Tengine 反向代理状态检测
生活随笔
收集整理的這篇文章主要介紹了
Tengine 反向代理状态检测
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Tengine 反向代理狀態(tài)檢測(cè) 安裝Tengine: 編譯安裝 ./configure --prefix=/usr/loca/nginx
make && make install
?
配置upstream server: #user nobody; user nginx nginx; worker_processes 1;?
#pid logs/nginx.pid; events {worker_connections 1024; }# load modules compiled as Dynamic Shared Object (DSO) # #dso { # load ngx_http_fastcgi_module.so; # load ngx_http_rewrite_module.so; #} http {include mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log logs/access.log main;#access_log "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G" main; sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;# server {# listen 80;# server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;# location / {# root html;# index index.html index.htm;# }#error_page 404 /404.html;# redirect server error pages to the static page /50x.html# #error_page 500 502 503 504 /50x.html;#location = /50x.html {# root html;#}# proxy the PHP scripts to Apache listening on 127.0.0.1:80# #location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000# #location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one# #location ~ /\.ht {# deny all;#}#}# another virtual host using mix of IP-, name-, and port-based configuration# #server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server# #server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#} upstream tomcat { ip_hash; server 192.168.137.201:8080; server 192.168.137.202:8080; check interval=3000 rise=2 fall=5 timeout=1000 type=http;check_http_send "HEAD / HTTP/1.0\r\n\r\n";check_http_expect_alive http_2xx http_3xx;} upstream tomcat-1 {ip_hash;server 192.168.137.201:8081;server 192.168.137.202:8081;check interval=3000 rise=2 fall=5 timeout=1000 type=http; #狀態(tài)檢測(cè)check_http_send "HEAD / HTTP/1.0\r\n\r\n";check_http_expect_alive http_2xx http_3xx;}server { listen 80; server_name 127.0.0.1; index index.jsp index.html; location / {proxy_pass http://tomcat; #以這種格式來使用后端的web服務(wù)器 proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;client_max_body_size 10m;client_body_buffer_size 128k;proxy_connect_timeout 90;proxy_send_timeout 90;proxy_read_timeout 90;proxy_buffer_size 4k;proxy_buffers 4 32k;proxy_busy_buffers_size 64k;proxy_temp_file_write_size 64k;} #location /status { #check_status; #access_log off; #} #location /nginx_status { #stub_status on; #access_log off; #} } server {listen 8000;server_name 127.0.0.1;index index.jsp index.html;location / {proxy_pass http://tomcat-1; #以這種格式來使用后端的web服務(wù)器 proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;client_max_body_size 10m;client_body_buffer_size 128k;proxy_connect_timeout 90;proxy_send_timeout 90;proxy_read_timeout 90;proxy_buffer_size 4k;proxy_buffers 4 32k;proxy_busy_buffers_size 64k;proxy_temp_file_write_size 64k;} } include /usr/local/nginx/conf/vhosts/*.conf;}?
狀態(tài)檢測(cè)模塊可以為Tengine提供主動(dòng)式后端服務(wù)器健康檢查的功能。 該模塊在Tengine-1.4.0版本以前沒有默認(rèn)開啟,它可以在配置編譯選項(xiàng)的時(shí)候開啟:./configure --with-http_upstream_check_module 編輯/etc/nginx/nginx.conf http {upstream cluster1 {# simple round-robinserver 192.168.30.116:80;#server 192.168.0.2:80;check interval=3000 rise=2 fall=5 timeout=1000 type=http;check_http_send "HEAD / HTTP/1.0\r\n\r\n";check_http_expect_alive http_2xx http_3xx;}upstream cluster2 {# simple round-robinserver 192.168.30.113:80;server 192.168.30.114:80;check interval=3000 rise=2 fall=5 timeout=1000 type=http;check_keepalive_requests 100;check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";check_http_expect_alive http_2xx http_3xx;}server {listen 80;location /1 {proxy_pass http://cluster1;}location /2 {proxy_pass http://cluster2;}location /status {check_status;access_log off;allow SOME.IP.ADD.RESS;deny all;}} }?
?
指令后面的參數(shù)意義是: interval:向后端發(fā)送的健康檢查包的間隔。 fall(fall_count): 如果連續(xù)失敗次數(shù)達(dá)到fall_count,服務(wù)器就被認(rèn)為是down。 rise(rise_count): 如果連續(xù)成功次數(shù)達(dá)到rise_count,服務(wù)器就被認(rèn)為是up。 timeout: 后端健康請(qǐng)求的超時(shí)時(shí)間。 default_down: 設(shè)定初始時(shí)服務(wù)器的狀態(tài),如果是true,就說明默認(rèn)是down的,如果是false,就是up的。默認(rèn)值是true,也就是一開始服務(wù)器認(rèn)為是不可用,要等健康檢查包達(dá)到一定成功次數(shù)以后才會(huì)被認(rèn)為是健康的。 type:健康檢查包的類型,現(xiàn)在支持以下多種類型 tcp:簡(jiǎn)單的tcp連接,如果連接成功,就說明后端正常。 ssl_hello:發(fā)送一個(gè)初始的SSL hello包并接受服務(wù)器的SSL hello包。 http:發(fā)送HTTP請(qǐng)求,通過后端的回復(fù)包的狀態(tài)來判斷后端是否存活。 mysql: 向mysql服務(wù)器連接,通過接收服務(wù)器的greeting包來判斷后端是否存活。 ajp:向后端發(fā)送AJP協(xié)議的Cping包,通過接收Cpong包來判斷后端是否存活。 port: 指定后端服務(wù)器的檢查端口。你可以指定不同于真實(shí)服務(wù)的后端服務(wù)器的端口,比如后端提供的是443端口的應(yīng)用,你可以去檢查80端口的狀態(tài)來判斷后端健康狀況。默認(rèn)是0,表示跟后端server提供真實(shí)服務(wù)的端口一樣。該選項(xiàng)出現(xiàn)于Tengine-1.4.0。 check_http_send http_packet: 該指令可以配置http健康檢查包發(fā)送的請(qǐng)求內(nèi)容。為了減少傳輸數(shù)據(jù)量,推薦采用"HEAD"方法。 當(dāng)采用長(zhǎng)連接進(jìn)行健康檢查時(shí),需在該指令中添加keep-alive請(qǐng)求頭,如:"HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n"。 同時(shí),在采用"GET"方法的情況下,請(qǐng)求uri的size不宜過大,確保可以在1個(gè)interval內(nèi)傳輸完成,否則會(huì)被健康檢查模塊視為后端服務(wù)器或網(wǎng)絡(luò)異常。 check_http_expect_alive: 該指令指定HTTP回復(fù)的成功狀態(tài),默認(rèn)認(rèn)為2XX和3XX的狀態(tài)是健康的。 check_status: 顯示服務(wù)器的健康狀態(tài)頁面。該指令需要在http塊中配置。 在Tengine-1.4.0以后,你可以配置顯示頁面的格式。支持的格式有: html、csv、 json。默認(rèn)類型是html。轉(zhuǎn)載于:https://www.cnblogs.com/ligao/p/8926712.html
總結(jié)
以上是生活随笔為你收集整理的Tengine 反向代理状态检测的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python自学第12天 模块
- 下一篇: Unity3d 控制物体移动、旋转、缩放