負載均衡健康檢查


 

 

在Nginx官方模塊提供的模塊中,沒有對負載均衡后端節點的健康檢查模塊,但可以使用第三方模塊。
`nginx_upstream_check_module`來檢測后端服務的健康狀態

 

1.安裝依賴包

 

 

[root@lb02 ~]# yum install -y gcc glibc gcc-c++ pcre-devel openssl-devel patch

 

2.下載nginx源碼包以及nginx_upstream_check模塊第三方模塊

 

 

 

 

[root@lb02 ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
[root@lb02 ~]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip

 

3.解壓nginx源碼包以及第三方模塊

 

 

[root@lb02 ~]# tar xf nginx-1.14.2.tar.gz [root@lb02 ~]# unzip master.zip

 

4.進入nginx目錄,打補丁(nginx的版本是1.14補丁就選擇1.14的,p1代表在nginx目錄,p0是不在nginx目錄)

 

 

 

 

 

 

[root@lb02 ~]# cd nginx-1.14.2/ [root@lb02 nginx-1.14.2]# patch -p1 <../nginx_upstream_check_module-master/check_1.14.0+.patch [root@lb02 nginx-1.14.2]# ./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 --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --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 --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/root/nginx_upstream_check_module-master --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' [root@lb02 nginx-1.14.2]# make && make install

 

5.在已有的負載均衡上增加健康檢查的功能

 

 

 

 

 

 

 

 

 

 

[root@lb02 /etc/nginx]# vim /etc/nginx/nginx.conf http { include conf.d/*.conf; ... ... } [root@lb02 /etc/nginx]# mkdir /etc/nginx/conf.d [root@lb02 ~]# vim /etc/nginx/conf.d/proxy_web.conf upstream web { server 172.16.1.7:80 max_fails=2 fail_timeout=10s; server 172.16.1.8:80 max_fails=2 fail_timeout=10s; check interval=3000 rise=2 fall=3 timeout=1000 type=tcp; #interval 檢測間隔時間,單位為毫秒 #rise 表示請求2次正常,標記此后端的狀態為up #fall 表示請求3次失敗,標記此后端的狀態為down #type 類型為tcp #timeout 超時時間,單位為毫秒 } server { listen 80; server_name linux.web.com; location / { proxy_pass http://web; include proxy_params; } location /upstream_check { check_status; } } [root@lb02 ~]# vim /etc/nginx/proxy_params proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 60s; proxy_read_timeout 60s; proxy_send_timeout 60s; proxy_buffering on; proxy_buffer_size 32k; proxy_buffers 8 128k;

 

6.創建用戶和目錄

 

 

[root@lb02 ~]# groupadd nginx -g 666 [root@lb02 ~]# useradd nginx -u 666 -g 666 [root@lb02 ~]# mkdir -p  /var/cache/nginx/

 

7.啟動並配置本地hosts文件

[root@lb02 ~]# /usr/sbin/nginx

 

 

 

 

8.訪問

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM