我们使用haproxy没有直接监控php的功能,但是我们可以通过80来进行监控php是否正常,当不正常时,自动踢掉当服务器。

server1 haproxy 192.168.0.5
server2 nginx+php 192.168.0.6
server3 nginx+php 192.168.0.7
分别在server2和3上安装好nginx和php
在server1上装好haproxy
在server1上编辑haproxy配置文件在最后一行加入才以下代码,注意192.168.0.5是你的主机头

listen appservers
        mode http
        bind 0.0.0.0:80
        maxconn 2000
        balance roundrobin
        option httpchk HEAD /health_check.php HTTP/1.1rnHost: 192.168.0.5
        server web1 192.168.0.6:80 weight 1 check inter 1s rise 2 fall 2
        server web2 192.168.0.7:80 weight 1 check inter 1s rise 2 fall 2

分别在server2和3上网站中添加一个监控php文件health_check.php内容如下
打开浏览器测试server2和3的health_check.php,出现Hello World!
重启haproxy,分别把server2和3停掉,都能访问php,现在全部停掉php后就会显示
503 Service Unavailable
No server is available to handle this request.

分类: linux负载均衡 标签: 暂无标签

评论

暂无评论数据

暂无评论数据

目录