首页 > 代码库 > haproxy基础
haproxy基础
说明:用haproxy实现的基本负载均衡
192.168.56.20 haproxy
192.168.56.21 apache01
192.168.56.22 apache02
[root@apache01 html]# cat /etc/hosts 192.168.56.20 haproxy 192.168.56.21 apache01 192.168.56.22 apache02 [root@apache01 html]#
1.三台服务器
yum install -y gcc glibc gcc-c++ make screen tree lrzsz
2.192.168.56.22 和 192.168.56.21
yum -y install httpd
3.192.168.56.21
echo "web01 192.168.56.21" > /var/www/html/index.html systemctl start httpd systemctl enable httpd 默认监听的是80端口 /etc/httpd/conf/httpd.conf
4.192.168.56.22
echo "web02 192.168.56.22" > /var/www/html/index.html systemctl start httpd systemctl enable httpd 默认监听的是80端口 /etc/httpd/conf/httpd.conf
5.192.168.56.20
yum -y install haproxy vi /etc/harproxy/haproxy.cfg global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 frontend main *:80 acl url_static path_beg -i /static /images /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static default_backend app backend static balance roundrobin server static 127.0.0.1:4331 check backend app balance roundrobin server app1 192.168.56.21:80 check inter 2000 rise 3 fall 3 weight 1 server app2 192.168.56.22:80 check inter 2000 rise 3 fall 3 weight 1 备注: 每个2s 重启3次 3次失败 不可用 权重都是1 systemctl start haproxy systemctl enable haproxy
6.浏览器查看
刷新查看
本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1890910
haproxy基础
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。