首页 > 其他 > 详细

haproxy 的安装

时间:2017-06-06 18:10:17      阅读:373      评论:0      收藏:0      [点我收藏+]

1.基础安装

yum install pcre pcre-devel openssl  openssl-devel
tar xf  haproxy-1.7.1.tar.gz
cd haproxy-1.7.1
make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1  PREFIX=/usr/local/haproxy
 make install PREFIX=/usr/local/haproxy
cd examples/
cp  haproxy.init   /etc/init.d/haproxy 
chmod +x  /etc/init.d/haproxy

2.本机IP:192.168.56.15

[root@bogon examples]# cat /etc/haproxy/haproxy.cfg 
global
maxconn 100000
chroot /usr/local/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid
log 127.0.0.1 local0 info

defaults
option http-keep-alive
maxconn 100000
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms

listen stats
 mode http
 bind 0.0.0.0:9999
 stats enable
 log global
 stats uri     /haproxy-status
 stats auth    haadmin:123456

listen  web_port  
 bind 0.0.0.0:80
 mode tcp
 log global
[root@bogon examples]# 
[root@bogon examples]# /etc/init.d/haproxy  restart 
Restarting haproxy (via systemctl):                        [  OK  ]
[root@bogon examples]#

http://192.168.56.15:9999/haproxy-status

技术分享

3.对后端代理

技术分享

技术分享

[root@bogon examples]# cat /etc/haproxy/haproxy.cfg 
global
maxconn 100000
chroot /usr/local/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid
log 127.0.0.1 local0 info

defaults
option http-keep-alive
maxconn 100000
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms

listen stats
 mode http
 bind 0.0.0.0:9999
 stats enable
 log global
 stats uri     /haproxy-status
 stats auth    haadmin:123456

listen  web_port  
 bind 0.0.0.0:80
 mode tcp  #tcp的方式
 log global
 server web1  192.168.56.12:80  check inter 2000 fall 15 rise 10
 server web2  192.168.56.16:80    check inter 2000 fall 15 rise 10
[root@bogon examples]# 
 /etc/init.d/haproxy  restart 
 #inter是监控检查时间间隔,即每间隔2秒进行一次检查,
 rise是连续检查10次失败后将服务器从负载删除,
 fall是连续15次监控检查成功后重新添加至负载,一般fall大于rise几次,

技术分享

[root@bogon html]# curl 192.168.56.15
192.168.56.12 web1
[root@bogon html]# curl 192.168.56.15
192.168.56.16 web2
[root@bogon html]# curl 192.168.56.15
192.168.56.12 web1
[root@bogon html]# curl 192.168.56.15
192.168.56.16 web2
[root@bogon html]# curl 192.168.56.15
192.168.56.12 web1
[root@bogon html]# curl 192.168.56.15
192.168.56.16 web2
[root@bogon html]# curl 192.168.56.15
192.168.56.12 web1
[root@bogon html]# curl 192.168.56.15
192.168.56.16 web2
[root@bogon html]# curl 192.168.56.15
192.168.56.12 web1
[root@bogon html]# curl 192.168.56.15
192.168.56.16 web2
[root@bogon html]#

查看负载状况

技术分享

本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1932814

haproxy 的安装

原文:http://wsxxsl.blog.51cto.com/9085838/1932814

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!