1、 安装Haproxy。
2、 服务监控开通9090端口,Kong分发和自启动开通80和443端口,TiDB分发开通4000端口,MongoDB分发开通22000端口。
步骤 1 以root用户登录已规划两台服务器。
步骤 2 参考章节4 ,创建super用户并设置登录密码。
步骤 3 以super用户登录已规划两台服务器。
步骤 4 安装Haproxy(两台服务器)。
sudo yum install haproxy -y
步骤 5 修改配置文件(两台服务器)。
sudo vi /etc/haproxy/haproxy.cfg
[root@ha80 ~]# cat /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local3 info
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 10000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
nbproc 24
defaults
log global
option tcplog
option dontlognull
option redispatch
retries 3
timeout connect 2s
timeout client 3600s
timeout server 3600s
maxconn 10000
frontend main
bind *:4000
mode tcp
default_backend app-tidb
backend app-tidb
mode tcp
balance leastconn
server app1 ...61:4000 check inter 2000 fall 3
server app2 ...63:4000 check inter 2000 fall 3
server app3 ..**.65:4000 check inter 2000 fall 3
listen kong_stats
stats enable
bind :9090
mode http
option httplog
log global
maxconn 10
stats refresh 30s
stats uri /admin
stats realm haproxy
stats auth admin:passwd***
stats hide-version
stats admin if TRUE
[root@ha81 ~]# cat /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local3 info
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 10000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
nbproc 24
defaults
log global
option tcplog
option dontlognull
option redispatch
retries 3
timeout connect 2s
timeout client 3600s
timeout server 3600s
maxconn 10000
frontend main
bind *:4000
mode tcp
default_backend app-tidb-backup
backend app-tidb-backup
mode tcp
balance leastconn
server app1 ...61:4000 check inter 2000 fall 3
server app2 ...63:4000 check inter 2000 fall 3
server app3 ..**.65:4000 check inter 2000 fall 3
listen kong_stats
stats enable
bind :9090
mode http
option httplog
log global
maxconn 10
stats refresh 30s
stats uri /admin
stats realm haproxy
stats auth admin:passwd***
stats hide-version
stats admin if TRUE
步骤 6 启动服务(两台服务器)。
sudo haproxy -f /etc/haproxy/haproxy.cfg
步骤 7 重新启动(两台服务器)。
sudo killall haproxy
sudo haproxy -f /etc/haproxy/haproxy.cfg
步骤 8 查看haproxy是否已启动(两台服务器)。
sudo ps -ef | grep haproxy
回显如下,表示服务启动成功。
步骤 9 打开浏览器,在地址栏输入http://10.32.37.11:9090/admin,访问前端页面。
登录用户名:admin,密码:passwd****
IP地址为已登录服务器IP。
步骤 10 开启服务器端口。
sudo firewall-cmd --zone=public --add-port=9090/tcp --permanent
sudo firewall-cmd --reload
查看防火墙端口:sudo firewall-cmd --zone=public --query-port=9090/tcp
删除防火墙端口:sudo firewall-cmd --zone=public --remove-port=9090/tcp –permanent
----结束