首先建立了两个tomcat服务器
sudo docker run --name tomcat -p 8090:8080 -d tomcat
编辑index.html可以显示页面内容
docker cp index.html tomcat:/usr/local/tomcat/webapps/ROOT
173.16.80.107:8090
173.16.80.70:8090
下载haproxy
centos下sudo yum install haproxy
ubuntu下sudo apt-get install package 安装包
一般在/etc/haproxy
编辑配置文件 sudo vi haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user root
group root
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
defaults
log global
mode http
option http-keep-alive
option httplog
timeout connect 5000ms
timeout client 10000ms
timeout server 50000ms
timeout http-request 20000ms
balance roundrobin
listen stats
mode http
log 127.0.0.1 local0 err
bind 0.0.0.0:1088
stats enable
stats hide-version
stats uri /stats
stats refresh 30s
stats auth admin:admin
stats admin if TRUE
listen tomcat
bind 0.0.0.0:5222
mode http
maxconn 300
log 127.0.0.1 local0 debug
balance roundrobin
server static1 173.16.80.107:8090 check inter 2000 fall 3 weight 30
server static2 173.16.80.70:8090 check inter 2000 fall 3 weight 30
重新启动[chenwb@hadoop03 haproxy]$ sudo systemctl restart haproxy
运行 [chenwb@hadoop03 haproxy]$ sudo haproxy -f /etc/haproxy/haproxy.cfg
检查两个tomcat是否成功
浏览器地址栏输入配置的ip+端口 出现以下页面
然后在浏览器地址栏输入
http://173.16.80.70:1088/stats
得到一下的页面表示成功配置