安装 HAProxy 配置负载均衡
2011-10-10 08:48
381 查看
原文出处:http://blog.chenlb.com/2009/06/install-haproxy-and-configure-load-balance.html
据说 HAProxy 可以做负载均衡,同时还可对服务器健康检测,有 down 机的自动停止分发,当服务器正常后,又自动均衡到刚死过的服务器。之前用 nginx ,现试用下 haproxy 。
下载:haProxy 1.3.15 http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.15.7.tar.gz
安装:
cd /home/chenlb wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.15.7.tar.gz tar -zxvf haproxy-1.3.15.7.tar.gz cd haproxy-1.3.15.7 make TARGET=linux26 PREFIX=/home make install PREFIX=/home cd /home/haproxy vi haproxy.cfg
创建/修改配置haproxy.cfg:
global
log 127.0.0.1 local0
#log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
chroot /home/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /home/haproxy/logs/haproxy.pid
#debug
#quiet
defaults
log 127.0.0.1 local3
mode http
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
retries 2
maxconn 2000
balance roundrobin
stats uri /haproxy-stats
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen web_proxy 0.0.0.0:1080
option httpchk GET /ping.jsp
server s1 192.168.0.101:8080 weight 3 check
#server s2 192.168.0.102:8080 weight 3 check
server s3 192.168.0.103:8080 weight 3 check
启动 haproxy:
haproxy 192.168.0.100 分发到 192.168.0.101, 192.168.0.103 (故意down掉)。
可以打开 stats 看,http://192.168.0.100:1080/haproxy-stats,如:
haproxy balance stats, 点击放大
如果修改 haproxy.cfg 配置,想重启 haproxy 用 kill -HUP `cat logs/haproxy.pid` 是不行的。必须使用 -sf 或 -st 参数,如:
但配置后,死活不会输出日志,还没找到解决方法,网上有些,但行不通:
haproxy 还可以用 nginx 的配置,请看:http://www.igvita.com/2008/05/13/load-balancing-qos-with-haproxy/
参考资料:http://cn.haproxy.org/,http://cn.haproxy.org/download/1.3/doc/configuration-cn.txt,http://bbs.ctocio.com.cn/thread-7854276-1-1.html,http://www.2tutu.com/post/193.html
据说 HAProxy 可以做负载均衡,同时还可对服务器健康检测,有 down 机的自动停止分发,当服务器正常后,又自动均衡到刚死过的服务器。之前用 nginx ,现试用下 haproxy 。
下载:haProxy 1.3.15 http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.15.7.tar.gz
安装:
cd /home/chenlb wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.15.7.tar.gz tar -zxvf haproxy-1.3.15.7.tar.gz cd haproxy-1.3.15.7 make TARGET=linux26 PREFIX=/home make install PREFIX=/home cd /home/haproxy vi haproxy.cfg
cd /home/chenlb wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.15.7.tar.gz tar -zxvf haproxy-1.3.15.7.tar.gz cd haproxy-1.3.15.7 make TARGET=linux26 PREFIX=/home make install PREFIX=/home cd /home/haproxy vi haproxy.cfg
创建/修改配置haproxy.cfg:
global
log 127.0.0.1 local0
#log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
chroot /home/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /home/haproxy/logs/haproxy.pid
#debug
#quiet
defaults
log 127.0.0.1 local3
mode http
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
retries 2
maxconn 2000
balance roundrobin
stats uri /haproxy-stats
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen web_proxy 0.0.0.0:1080
option httpchk GET /ping.jsp
server s1 192.168.0.101:8080 weight 3 check
#server s2 192.168.0.102:8080 weight 3 check
server s3 192.168.0.103:8080 weight 3 check
global log 127.0.0.1 local0 #log 127.0.0.1 local1 notice #log loghost local0 info maxconn 4096 chroot /home/haproxy uid 99 gid 99 daemon nbproc 1 pidfile /home/haproxy/logs/haproxy.pid #debug #quiet defaults log 127.0.0.1 local3 mode http option httplog option httpclose option dontlognull option forwardfor option redispatch retries 2 maxconn 2000 balance roundrobin stats uri /haproxy-stats contimeout 5000 clitimeout 50000 srvtimeout 50000 listen web_proxy 0.0.0.0:1080 option httpchk GET /ping.jsp server s1 192.168.0.101:8080 weight 3 check #server s2 192.168.0.102:8080 weight 3 check server s3 192.168.0.103:8080 weight 3 check
启动 haproxy:
sbin/haproxy -f haproxy.cfg
haproxy 192.168.0.100 分发到 192.168.0.101, 192.168.0.103 (故意down掉)。
可以打开 stats 看,http://192.168.0.100:1080/haproxy-stats,如:
haproxy balance stats, 点击放大
如果修改 haproxy.cfg 配置,想重启 haproxy 用 kill -HUP `cat logs/haproxy.pid` 是不行的。必须使用 -sf 或 -st 参数,如:
sbin/haproxy -f haproxy.cfg -st `cat logs/haproxy.pid `
#./haproxy –help //haproxy相关命令参数介绍. haproxy -f <配置文件> [-n 最大并发连接总数] [-N 每个侦听的最大并发数] [-d] [-D] [-q] [-V] [-c] [-p] [-s] [-l] [-dk] [-ds] [-de] [-dp] [-db] [-m <内存限制M>] [{-sf|-st} pidlist...] -d 前台,debug模式 -D daemon模式启动 -q 安静模式,不输出信息 -V 详细模式 -c 对配置文件进行语法检查 -s 显示统计数据 -l 显示详细统计数据 -dk 不使用kqueue -ds 不使用speculative epoll -de 不使用epoll -dp 不使用poll -db 禁用后台模式,程序跑在前台 -sf 程序启动后向pidlist里的进程发送FINISH信号,这个参数放在命令行的最后 -st 程序启动后向pidlist里的进程发送TERMINATE信号,这个参数放在命令行的最后
但配置后,死活不会输出日志,还没找到解决方法,网上有些,但行不通:
syslog.conf里加一行 local3.* /var/log/haproxy.log # killall -HUP syslogd 重启 syslogd # touch /var/log/haproxy.log # chmod 777 /var/log/haproxy.log # tail –f /var/log/harpoxy.log 监控日志 # ./haproxy -f haproxy.cfg 启动服务.
haproxy 还可以用 nginx 的配置,请看:http://www.igvita.com/2008/05/13/load-balancing-qos-with-haproxy/
参考资料:http://cn.haproxy.org/,http://cn.haproxy.org/download/1.3/doc/configuration-cn.txt,http://bbs.ctocio.com.cn/thread-7854276-1-1.html,http://www.2tutu.com/post/193.html
相关文章推荐
- 负载均衡工具haproxy安装,配置,使用
- haproxy安装及负载均衡配置
- 负载均衡-haproxy 安装配置
- Keepalived+HAProxy配置高可用负载均衡,解决keepalived无法安装问题
- 负载均衡-haproxy安装配置
- HAProxy负载均衡安装配置
- 烂泥:高负载均衡学习haproxy之安装与配置
- Centos6.5 负载均衡 Haproxy 1.6.9安装配置
- 高负载均衡学习haproxy之安装与配置
- 负载均衡haproxy的安装配置
- 负载均衡工具haproxy安装,配置,使用
- 负载均衡工具haproxy安装,配置,使用
- 负载均衡(haproxy安装,配置,使用)
- 负载均衡(haproxy安装,配置,使用)
- [HAProxy] 负载均衡haproxy安装配置
- 安装 HAProxy 配置负载均衡
- 负载均衡工具haproxy安装,配置,使用
- 负载均衡-haproxy安装配置
- 负载均衡工具haproxy安装,配置,使用
- 烂泥:高负载均衡学习haproxy之安装与配置