当前位置:   article > 正文

haproxy

haproxy

一、haproxy

1.环境

haproxy        192.168.1.30            
web1        192.168.1.67
web2        192.168.1.68
web1,web2均上线了nginx服务

2.配置时间服务器

[root@haproxy01 ~]# yum -y install ntpdate
[root@haproxy01 ~]# ntpdate cn.ntp.org.cn
[root@haproxy01 ~]# yum -y install ntp
[root@haproxy01 ~]# systemctl start ntpd
[root@haproxy01 ~]# systemctl enable ntpd

3.安装配置haproxy

[root@haproxy01 ~]# yum -y install haproxy
[root@haproxy01 ~]# rpm -ql haproxy                    //查找配置文件
[root@haproxy01 ~]# vim /etc/haproxy/haproxy.cfg 

[root@haproxy01 ~]# systemctl start haproxy.service 
[root@haproxy01 ~]# systemctl enable haproxy.service
 
4.访问测试

[root@haproxy01 ~]# curl 192.168.1.30
i am web1
[root@haproxy01 ~]# curl 192.168.1.30
i am web2


5.添加统计页面

[root@haproxy01 ~]# vim /etc/haproxy/haproxy.cfg 
# 定义web管理界面
listen statistics
    bind     *:9090            #定义监听端口    
    mode     http             #默认使用协议    
    stats     enable             #启用stats
    stats     uri /hadmin?stats     #自定义统计页面的url
    stats     auth admin:admin     #统计页面的账号密码
    stats     hide-version         #隐藏在统计页面上的haproxy版本信息
    stats     refresh 30s         #统计页面自动刷新时间
    stats     admin if TRUE         #如果认证通过就做管理功能,可以管理后端服务器
    stats     realm hapadmin         #统计页面密码框上提示文件,默认为haproxy\statistics

[root@haproxy01 ~]# systemctl restart haproxy.service 

6.浏览器访问测试

http://192.168.1.30:9090/hadmin?stats
输入账号密码

7.权重

[root@haproxy01 ~]# vim /etc/haproxy/haproxy.cfg 

[root@haproxy01 ~]# systemctl restart haproxy.service 

测试:
[root@haproxy01 ~]# curl 192.168.1.30
i am web1
[root@haproxy01 ~]# curl 192.168.1.30
i am web1
[root@haproxy01 ~]# curl 192.168.1.30
i am web1
[root@haproxy01 ~]# curl 192.168.1.30
i am web1
[root@haproxy01 ~]# curl 192.168.1.30
i am web2

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/984265
推荐阅读
相关标签
  

闽ICP备14008679号