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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NGINX负载均衡+监控

發布時間:2024/3/24 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NGINX负载均衡+监控 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、配置NGINX運行環境

????????更新yum源

? ? ? ? ????????yum update

????????安裝gcc

????????????????yum install -y gcc-c++

????????安裝PCRE pcre-devel

????????????????yum install -y pcre pcre-devel

????????安裝zlib

????????????????yum install -y zlib zlib-devel

????????安裝Open SSL

????????????????yum install -y openssl openssl-devel

二、下載安裝nginx

? ? ? ? 1、下載nginx至/usr/local/ 目錄

????????????????wget -c https://nginx.org/download/nginx-1.20.1.tar.gz

? ? ? ? 2、解壓nginx

? ? ? ? ? ? ? ? tar -xzvf?nginx-1.20.1.tar.gz

? ? ? ? 3、下載nginx第三方模塊nginx_upstream_check_module至/usr/local/目錄

????????????????wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master ????????????????unzip master

? ? ? ? 4、進入nginx-1.20.1文件,進行打nginx_upstream_check_module模塊的補丁

cd nginx-1.20.1/ patch -p1 < ../nginx_upstream_check_module-master/check_1.20.1+.patch patching file src/http/modules/ngx_http_upstream_hash_module.c patching file src/http/modules/ngx_http_upstream_ip_hash_module.c patching file src/http/modules/ngx_http_upstream_least_conn_module.c patching file src/http/ngx_http_upstream_round_robin.c patching file src/http/ngx_http_upstream_round_robin.h

? ? ? ? 5、添加nginx_upstream_check_module模塊的參數

./configure --prefix=../nginx --user=www-web --group=www-web --with-http_ssl_module --with-http_v2_module --with-threads --with-file-aio --with-http_stub_status_module --add-module=../nginx_upstream_check_module-master/

? ? ? ? 6、編譯安裝nginx

?????????????????這里和redis的編譯安裝比較類似,首先在當前目錄(/usr/local/nginx-1.20.1)進行編譯。輸入make即可

????????????????make
????????????????然后回車,如果編譯出錯,請檢查是否前面的4個安裝都沒有問題。
????????編譯成功之后,就可以安裝了,輸入以下指令:

????????????????make install
????????????????ok,安裝成功。
????????????????這時候返回上一級目錄,就會發現多了nginx目錄。

三、配置nginx和nginx監控

? ? ? ? 進入/usr/local/nginx/conf/nginx.conf

? ? ? ? vim?/usr/local/nginx/conf/nginx.conf

? ? ? ? 1、配置nginx

upstream cluster { server 192.168.6.99:8080; #配置應用入Tomcat或者apache server 192.168.6.99:8082; #server localhost:端口號; check interval=5000 rise=1 fall=3 timeout=1000; #nginx監控配置 }#interval: 檢測間隔5秒#fall: 連續檢測失敗次數3次時,認定relaserver is down#rise: 連續檢測成功1次時,認定relaserver is up#timeout: 超時1秒 #default_down: 初始狀態為down,只有檢測通過后才為up#type: 檢測類型方式 tcp#1. tcp :tcp 套接字,不建議使用,后端業務未100%啟動完成,前端已經放開訪問的情況#2. ssl_hello: 發送hello報文并接收relaserver 返回的hello報文#3. http: 自定義發送一個請求,判斷上游relaserver 接收并處理#4. mysql: 連接到mysql服務器,判斷上游relaserver是否還存在#5. ajp: 發送AJP Cping數據包,接收并解析AJP Cpong響應以診斷上游relaserver是否還存活(AJPtomcat內置的一種協議)#6. fastcgi: php程序是否存活

? ? ? ? 2、調用nginx監控

server { listen 80; #nginx端口號80 server_name localhost; location / { #從內部調用執行監控模塊 proxy_pass http://cluster; } location /nstatus { #從外部調用監控的模塊 http://localhost:80/nstatus check_status; access_log off; } }

四、啟動nginx

? ? ? ? 1、開啟添加80端口號

????????防火墻添加80可用端口

????????????????Firewall-cmd --permanent --zone=public --add-port=80/tcp

????????重啟防火墻可用端口

????????????????Firewall-cmd --reload

????????查看防火墻可用端口是否有80

????????????????Firewall-cmd --zone=public --query-port=80/tcp

? ? ? ? 2、啟動nginx 并 設置開啟自啟動

????????啟動nginx

? ? ? ? ? ? ? ? ./usr/local/nginx/sbin/nginx????????

????????查看nginx進程

????????????????ps aux | grep nginx

????????設置開機自啟動只需要在rc.local增加啟動代碼即可

? ? ? ????????? vim /ect/rc.local

????????在rc.local文件底部加上下面的代碼

????????????????/usr/local/nginx/sbin/nginx

????????關閉nginx

????????????????./nginx -s quit 或者 ./nginx -s stop

????????重啟nginx

????????????????./nginx -s reload

總結

以上是生活随笔為你收集整理的NGINX负载均衡+监控的全部內容,希望文章能夠幫你解決所遇到的問題。

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