CentOS7 下安裝
yum install haproxy
cat >> /etc/sysctl.conf <<-END
net.ipv4.ip_forward=1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 8
END
sysctl -p
sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
reboot
全局配置
global
log 127.0.0.1 local3 info
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 102400
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
默認配置
defaults
log global
option dontlognull
option redispatch
option abortonclose
timeout check 8s
tcp 連接多個 ceph-radosgw
frontend ceph-radosgw *:7480
timeout client 8s
default_backend ceph-radosgw
backend ceph-radosgw
mode tcp
balance roundrobin
timeout connect 8s
timeout server 8s
retries 2
server cpeh240 10.9.10.234:7480 check
server ceph241 10.9.10.235:7480 check
server ceph243 10.9.10.236:7480 check
tcp 連接 mysql galera cluster
frontend mysql *:3306
timeout client 1800s
default_backend mysql
backend mysql
balance source
option tcpka
timeout connect 8s
timeout server 1800s
retries 2
server mysql231 10.9.10.231:3306 check inter 4s
server mysql232 10.9.10.232:3306 check inter 4s
server mysql233 10.9.10.233:3306 check inter 4s
tcp 連接 redis 主庫
frontend redis *:6379
timeout client 1800s
default_backend redis
backend redis
balance roundrobin
timeout connect 8s
timeout server 1800s
retries 2
option tcp-check
tcp-check connect
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send QUIT\r\n
tcp-check expect string +OK
server redis87 10.1.14.87:6379 check inter 4s
server redis88 10.1.14.88:6379 check inter 4s
server redis89 10.1.14.89:6379 check inter 4s
狀態頁面
listen admin_stats
bind 0.0.0.0:10080
mode http
maxconn 100
timeout client 1m
timeout connect 4s
timeout server 4s
stats refresh 30s
stats uri /
stats auth username:password
stats realm haproxy for private user, enter username/password
stats hide-version
生成日誌文件 haproxy.log
touch /var/log/haproxy.log
chown haproxy.haproxy /var/log/haproxy.log
sed -i -e '/ModLoad imudp/s/^#//' \
-e '/UDPServerRun 514/s/^#//' /etc/rsyslog.conf
echo 'local3.* /var/log/haproxy.log' >> /etc/rsyslog.conf
systemctl restart rsyslog
systemctl restart haproxy
參考