1.下载地址
https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-2.3.4.tar.gz
2.解压
tar -zxvf haproxy-2.3.4.tar.gz
3.编译、安装
cd haproxy-2.3.4
make TARGET=linux3100 CPU=x86_64 PREFIX=/usr/local/haprpxy
make install PREFIX=/usr/local/haproxy
4.创建配置、日志文件
cd /usr/local/haproxy/
mkdir log
mkdir conf
touch /usr/local/haproxy/conf/haproxy.cfg
touch /usr/local/haproxy/log/haproxy.log
5.修改配置文件
vim /usr/local/haproxy/conf/haproxy.cfg
添加如下配置内容
global
log 127.0.0.1 local0 info
maxconn 4096
daemon
nbproc 1
pidfile /var/run/haproxy.pid
chroot /usr/local/haproxy
defaults
#mode tcp
log global
option redispatch
option abortonclose
retries 3
timeout http-request 30s
timeout queue 1m
timeout connect 10s
timeout client 20s
timeout server 30s
timeout check 5s
#######################HAproxy监控页面#########################
listen statsPage
mode http
bind 0.0.0.0:1080 #监听端口
stats refresh 30s #统计页面自动刷新时间
stats uri /haproxy?stats
stats realm Haproxy Manager #统计页面密码框上提示文本
stats auth admin:admin
#####################RabbitMQ的管理界面###############################
listen rabbitmq_admin
mode http
bind 192.168.88.204:15673
server node1 192.168.88.203:15672
server node2 192.168.88.204:15672
#####################RabbitMQ服务代理###########################################
listen rabbitmq_cluster
bind 192.168.88.204:5673
mode tcp
balance roundrobin
option tcpka
option tcplog
#timeout client 3h
#timeout server 3h
#timeout connect 3h
#check inter 2000 是检测心跳频率,rise 2是2次正确认为服务器可用,fall 3是3次失败认为服务器不可用
server node1 192.168.88.203:5672 check inter 5s rise 2 fall 3
server node2 192.168.88.204:5672 check inter 5s rise 2 fall 3
6.验证
http://192.168.88.204:1080/haproxy?stats
http://192.168.88.204:15673/
7.服务自启动(非必须)
1.将keepalived主程序加入到环境变量
ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin/haproxy2.设置启动脚本,方便service命令调用
cp /home/qxmz/packages/haproxy-2.3.4/examples/haproxy.init /etc/init.d/haproxy
chmod -R 755 /etc/init.d/haproxy3.创建默认配置文件
mkdir -p /etc/haproxy
ln -s /usr/local/haproxy/conf/haproxy.cfg /etc/haproxy/haproxy.cfg4.创建日志文件
ln -s /usr/local/haproxy/log/haproxy.log /var/log/haproxy.log5.拷贝错误页面
cp /home/qxmz/packages/haproxy-2.3.4/examples/errorfiles/ /usr/local/haproxy/ -r
ln -s /usr/local/haproxy/errorfiles /etc/haproxy/errorfiles6.添加为系统服务:
chkconfig --add haproxy7.设置开机启动:
chkconfig haproxy on8.常用命令:启动、关闭、重启
service haproxy start|stop|restart
8.修改日志路径 (非必须)
1.修改日志路径
vim /etc/rsyslog.conf
2.开启514 UDP监听(取消注释)
$ModLoad imudp
$UDPServerRun 514
3.指定日志存放点
在*.info;mail.none;authpriv.none;cron.none后面添加;local0.none
#最后一行添加
local0.* /usr/local/haproxy/log/haproxy.log
4.修改日志配置
vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-r -m 0 -c 2"
5.重启日志服务
systemctl restart rsyslog