HAProxy可以实现 TCP 负载均衡
- 关闭防火墙
systemctl stop firewalld systemctl disable firewalld
- 修改 SELINUX
setenforce 0 sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
- 安装 haproxy
yum install -y haproxy
- 修改 haproxy 配置
cat <<EOF > /etc/haproxy/haproxy.cfg global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 65000 user haproxy group haproxy daemon stats socket /var/lib/haproxy/stats defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 65000 frontend tcp_master_frontend bind *:26443 mode tcp log global option tcplog timeout client 60s maxconn 65000 default_backend tcp_master_backend backend tcp_master_backend mode tcp option tcplog option log-health-checks balance roundrobin timeout queue 5s timeout connect 1s timeout server 60s server master01 192.168.1.108:6443 check server master02 192.168.1.110:6443 check server master03 192.168.1.109:6443 check EOF
- 注册 haproxy 为自动服务
systemctl daemon-reload systemctl enable haproxy systemctl restart haproxy
- 检查 haproxy 启动状态
systemctl staus haproxy ● haproxy.service - HAProxy Load Balancer Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2019-07-20 17:44:23 CST; 888ms ago