HAProxy配置
2014-07-29 19:17
155 查看
前言
Haproxy是一个负载均衡服务器,能够提供4层,7层代理,并能支持上万级别的连接,你可以直接在WEB服务器前端加上它,而不影响应用的访问,完全透明。
安装
$ wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.8.tar.gz $ tar -zxvf haproxy-1.4.8.tar.gz $ cd haproxy-1.4.8 $ ./configure --prefix=/path/to/haproxy $ make && make install
配置
首先要添加haproxy:haproxy用户:$ groupadd haproxy $ useradd -g haproxy haproxy
查看uid和gid
$ sudo cat /etc/passwd |grep haproxy
编辑haproxy.cfg,添加如下内容:
global log 127.0.0.1 local3 maxconn 4096 #最大连接数 chroot /path/to/haproxy #安装目录 uid 535 #用户haproxy gid 520 #组haproxy daemon #守护进程运行 nbproc 1 #进程数量 pidfile logs/haproxy.pid defaults log 127.0.0.1 local3 mode http #layer 7代理 option httplog option httpclose option dontlognull option forwardfor retries 2 maxconn 2000 balance roundrobin stats uri /haproxy-stats contimeout 5000 clitimeout 50000 srvtimeout 50000 frontend http-in bind *:80 #监听地址 default_backend pool1 backend pool1 option httpchk GET /test.php #用来做健康检查 stats refresh 2 server server1 192.168.1.1:82 weight 3 maxconn 32 check #check表示对这个server进行健康检查 server server2 192.168.1.2:82 weight 3 maxconn 32 check
查看后端server状态: http://example.com/haproxy-stats
启动
$ sudo ./sbin/haproxy -f haproxy.cfg
重启
$ sudo ./sbin/haproxy -f haproxy.cfg -st `cat logs/haproxy.pid`
日志问题
有童鞋说日志怎么也写不进去,我也遇到了这个问题,在这里分享下。 编辑/etc/syslog.conf文件,添加:
local3.* /var/log/haproxy.log
编辑
/etc/sysconfig/syslog文件,把
SYSLOGD_OPTIONS="-m 0"
改成
SYSLOGD_OPTIONS="-r -m 0" #enables logging from remote machines
重启syslogd:
/etc/init.d/syslog restart
通过
tail应该可以看到日志输出了:
tail -f -n 30 /var/log/haproxy.log
相关文章推荐
- ubuntu10.04下haproxy+heartbeat配置高可用负载均衡(修改版|亲测绝对可行)
- haproxy配置说明
- 安装 HAProxy 配置负载均衡
- haproxy的安装与配置
- HAProxy的基本安装配置
- haproxy安装与配置
- 负载均衡工具haproxy安装,配置,使用
- 负载均衡工具haproxy安装,配置,使用
- haproxy + keepalived “一键安装包” 配置与测试HOWTO
- HAProxy配置使用说明 一
- Keepalived&Haproxy的简单安装配置
- 负载均衡工具haproxy安装,配置,使用
- haproxy配置实现动静分离
- HAProxy 配置负载均衡 可以测量服务器监控状况,动态分配
- haproxy配置说明 二
- HAProxy配置使用说明
- Keepalived&Haproxy的简单安装配置
- Haproxy安装及配置
- Haproxy 配置项\配置实例
- Keepalived+HAProxy配置高可用负载均衡,解决keepalived无法安装问题