stats auth haproxy:system --用户名和密码 stats hide-version
stats admin if TRUE --可以手动启动和停止服务
listen site_status --检查后端主机的健康
bind 0.0.0.0:80
mode http
log 127.0.0.1 local3 err
monitor-uri /site-stats --使用url地址检查
frontend main_status --定义acl规则
bind 0.0.0.0:80 --绑定到80端口
mode http
log global
option httplog
option forwardfor
acl web1 hdr_reg(host) -i ^(|ww1.itnihao.cn)$
--匹配和ww1.itnihao.cn两个域名就放到web1变量中
acl web2 url_sub -i killall= --请求中包含killall= 就放入到web2变量中
acl web3 path_beg -i /static /images /Javascript /stylesheets
use_backend server_web3 if web3 --满足web3变量的就丢到server_web3里面的虚拟主机
default_backend server_web4 --都不满足就丢到server_web4里面的虚拟主机
backend server_web3
mode http
balance roundrobin
option httpchk GET /test.html --定义首页 址
server ton1 192.168.1.248:80 check inter 1500 rise 3 fall 3 weight 1
--后端服务器,inter 1500是检查心跳频率,rise 3是3次正确可用,fall 3是3次失败不可用,weight 1是权重
server ton2 192.168.1.249:80 check inter 1500 rise 3 fall 3 weight 1
backend server_web4
mode http
balance roundrobin
option httpchk GET /index.html
server ton3 192.168.1.248:80 check inter 1500 rise 3 fall 3 weight 1
server ton4 192.168.1.249:80 check inter 1500 rise 3 fall 3 weight 1
[root@tong1 haproxy]# /etc/init.d/haproxy restart
Stopping haproxy: [ OK ]
Starting haproxy: [ OK ]
[root@tong1 haproxy]#
3.在后端主机安装apache服务
tong2节点:
[root@tong2 ~]# hostname
tong2
[root@tong2 ~]# yum install httpd -y
[root@tong2 ~]# vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
[root@tong2 ~]# echo 'node2' > /var/www/html/index.html
[root@tong2 ~]# echo 'static node2' > /var/www/html/test.html
[root@tong2 ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@tong2 ~]#
tong3节点:
[root@tong3 ~]# hostname
tong3
[root@tong3 ~]# yum install httpd -y
[root@tong3 ~]# vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
[root@tong3 ~]# echo 'node3' > /var/www/html/index.html
[root@tong3 ~]# echo 'static node3' > /var/www/html/test.html
[root@tong3 ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@tong3 ~]#
4.检查haproxy的状态和监控
后台管理和监控url页面
后端主机的监控页面
(1)后端主机状态正常
(2)后端主机不正常,出现宕机
���常访问节点