日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux nginx 安装stream,Centos7-64bit-编译安装配置Nginx stream四层负载均衡 动态加载

發布時間:2024/7/23 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux nginx 安装stream,Centos7-64bit-编译安装配置Nginx stream四层负载均衡 动态加载 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Centos7-64bit-編譯安裝配置Nginx stream四層負載均衡 動態加載

2018-08-10 17:12

分享人:老牛

yum install screen -y && screen -S nginx

sudo yum -y groupinstall "Development Tools" && yum -y epel-release wget gc autoconf automake pcre-devel zlib-devel openssl-devel

----------------------yum安裝nginx(默認未編譯stream模塊,如果需要用按下面方法編譯)------------------------------

安裝nginx

sudo yum install nginx -y

設置nginx開機啟動

sudo systemctl enable nginx

-----------------------通過編譯安裝nginx(開啟stream模塊 動態加載方式)-----------------------------

編譯安裝nginx

sudo yum check-update || sudo yum update -y

yum groupinstall -y 'Development Tools'

yum install -y epel-release

yum install -y wget perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel

wget https://nginx.org/download/nginx-1.13.2.tar.gz && tar zxvf nginx-1.13.2.tar.gz

wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && tar xzvf pcre-8.40.tar.gz

wget https://www.zlib.net/zlib-1.2.11.tar.gz && tar xzvf zlib-1.2.11.tar.gz

wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz && tar xzvf openssl-1.1.0f.tar.gz

rm -rf *.tar.gz

cd ~/nginx-1.13.2

cp ~/nginx-1.13.2/man/nginx.8 /usr/share/man/man8

gzip /usr/share/man/man8/nginx.8

man nginx

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --build=CentOS --builddir=nginx-1.13.2 --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-compat --with-pcre=../pcre-8.40 --with-pcre-jit --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.0f --with-openssl-opt=no-nextprotoneg --with-debug

make

make install

ln -s /usr/lib64/nginx/modules /etc/nginx/modules

nginx -V

useradd --system --home /var/cache/nginx --shell /sbin/nologin --comment "nginx user" --user-group nginx

nginx -t

mkdir -p /var/cache/nginx && sudo nginx -t

vi /usr/lib/systemd/system/nginx.service

寫入以下內容

[Unit]

Description=nginx - high performance web server

Documentation=https://nginx.org/en/docs/

After=network-online.target remote-fs.target nss-lookup.target

Wants=network-online.target

[Service]

Type=forking

PIDFile=/var/run/nginx.pid

ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf

ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s TERM $MAINPID

[Install]

WantedBy=multi-user.target

啟動nginx 設置開機啟動nginx

systemctl start nginx.service && sudo systemctl enable nginx.service

檢查nginx是否開機啟動

systemctl is-enabled nginx.service

檢查nginx是否正常運行

sudo systemctl status nginx.service

ps aux | grep nginx

curl -I 127.0.0.1

shutdown -r now

rm /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf

mkdir ~/.vim/

cp -r ~/nginx-1.13.2/contrib/vim/* ~/.vim/

rm /etc/nginx/*.default

-------------------------------nginx編譯安裝完畢------------------------------------------

-----------------------防火墻管理(未設置nginx 80端口可能無法訪問)-----------------------------

啟動防火墻

systemctl start firewalld.service

添加防火墻規則(添加80 443端口)--剛編譯的 若未添加 可能無法訪問

sudo firewall-cmd --permanent --zone=public --add-service=http

sudo firewall-cmd --permanent --zone=public --add-service=https

sudo firewall-cmd --reload

如需要可關閉防火墻

systemctl stop firewalld.service

關閉防火墻開機啟動

systemctl disable firewalld.service

設置防火墻開機啟動

systemctl enable firewalld.service

Centos7 防火墻 相關控制命令

systemctl is-enabled nginx.service #查詢nginx是否開機啟動

systemctl enable nginx.service #開機運行nginx

systemctl disable nginx.service #取消開機運行nginx

systemctl start nginx.service #啟動nginx

systemctl stop nginx.service #停止nginx

systemctl restart nginx.service #重啟nginx

systemctl reload nginx.service #重新加載nginx配置文件

systemctl status nginx.service #查詢nginx運行狀態

systemctl --failed #顯示啟動失敗的服務

#查看端口監聽情況

ss -tlnp|grep :80

nginx服務器默認root路徑

/usr/share/nginx/html

nginx服務器默認配置文件

/etc/nginx/nginx.conf

追加配置文件路徑(會自動加載.conf結尾的文件)

/etc/nginx/conf.d

---------------------------負載均衡配置------------------------------

清空nginx配置

cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbackup

cat /dev/null > /etc/nginx/nginx.conf

vi /etc/nginx/nginx.conf

根據實際情況添加負載均衡配置

worker_processes 1;

load_module ?"modules/ngx_stream_module.so";

events {

worker_connections ?1024;

}

stream {

upstream backend {

hash $remote_addr consistent;

server 176.58.111.12:80 weight=5 max_fails=3 fail_timeout=30s;

server 178.79.163.35:80 weight=5 ?max_fails=3 fail_timeout=30s;

}

server {

listen 80;

proxy_connect_timeout 1s;

proxy_timeout 3s;

proxy_pass backend;

}

}

總結

以上是生活随笔為你收集整理的linux nginx 安装stream,Centos7-64bit-编译安装配置Nginx stream四层负载均衡 动态加载的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。