一、安装haproxy
//选择yum安装方式安装,目前官方已发布稳定版至2.0,base仓库中的版本为1.5,就做四层端口转发,无所谓
[root@centos-01 ~]# yum install haproxy
二、管理服务
[root@centos-01 ~]# cd /etc/haproxy/
[root@centos-01 haproxy]# cp haproxy.cfg haproxy.cfg.bak
[root@centos-01 haproxy]# vim haproxy.cfg
添加tcp代理
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode tcp
option dontlognull
option nolinger
retries 3
option redispatch
fullconn 4096
timeout connect 10s
timeout client 1m
timeout server 1m
listen FilesUpdate_55535 0.0.0.0:55535
server app1 192.168.0.146:3306
listen FilesUpdate_55536 0.0.0.0:55536
server app1 192.168.0.134:3306
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 3000
listen app-stats 0.0.0.0:80
stats refresh 15s
stats uri /stats
stats realm haproxy MaraDBServer
stats auth admin:admin
stats hide-version
备注:为了方便查看将app1 替换为ip+端口模式方式进行展示
三、启动haproxy
[root@centos-01 haproxy]# systemctl start haproxy.service
[root@centos-01 haproxy]# systemctl enable haproxy.service
四、添加防火墙规则
[root@centos-01 haproxy]# firewall-cmd --zone=public --add-port=55535-56535/tcp --permanent
[root@centos-01 haproxy]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@centos-01 haproxy]# firewall-cmd --reload
五、访问
登录http://192.168.5.250/stats admin/admin
留言