HAProxy Web服務器狀態監測

三種狀態監測方式: •基於四層的傳輸端口做狀態監測

server 172.18.200.103 172.18.200.103:80 check port 9000 addr 172.18.200.104 inter 3s fall 3 rise 5 weight 1

•基於指定URI 做狀態監測
•基於指定URI的request請求頭部內容做狀態監測
option httpchk

•option httpchk <uri>
•option httpchk <method> <uri>
•option httpchk <method> <uri> <version>

示例:

listen web_prot_http_nodes
	bind 192.168.7.102:80
	mode http
	log global
	option httpchk GET /wp-includes/js/jquery/jquery.js?ver=1.12.4 HTTP/1.0 #基於指定URL
	#option httpchk HEAD /wp-includes/js/jquery/jquery.js?ver=1.12.4 HTTP/1.0\r\nHost:\192.168.7.102 #通過request獲取的頭部信息進行匹配進行健康檢測,節省很多不必要的網絡開銷,降低磁盤IO。
	server 192.168.7.102 blogs.studylinux.net:80 check inter 3000 fall 3 rise 5
	server 192.168.7.101 192.168.7.101:8080 cookie web1 check inter 3000 fall 3 rise 5

實戰演示:

在後端服務器(192.168.37.37)新建一個monitor_page目錄,並在目錄下創建一個index.html文件。

[root@centos37html]#mkdir /var/www/html/monitor_page
[root@centos37html]#echo OK >  monitor_page/index.html
vim  /etc/haproxy/haproxy.cfg

#官網業務訪問入口=====================================

listen WEB_PORT_80
        bind 192.168.37.17:80
        mode tcp   改爲tcp類型,也會從http服務進行訪問。
        rspidel Server:.*
        #option httpchk GET /monitor_page/index.html  HTTP/1.0
        option httpchk HEAD  /monitor_page/index.html  HTTP/1.0\r\nHost:\192.168.37.17 生產用,用HEAD模式,可以節省很多不必要的網絡開銷,降低磁盤IO,聲明是從17的IP地址發起的請求。
        server web1 192.168.37.27:80 check inter 3000 fall 3 rise 5
        server web2 192.168.37.37:80 check inter 3000 fall 3 rise 5

改爲HEAD模式(只獲取頭部信息,並設置爲每五秒監控一次),就不會在後端服務器日誌中不會再顯示文件大小,節省不必要的網絡開銷,降低磁盤IO。

在網頁上進行狀態頁檢查,此時可以看到後端服務器(192.168.37.27)沒有monitor_page此目錄,就會顯示down機現象。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章