README.md 2.0 KB

wordpress

  1. 启动1个 wordpress 容器

使用docker-compose.yml文件,执行如下命令启动:

docker-compose up -d

访问:http://http://192.168.99.100:8080

  1. 启动2个 wordpress 容器:

同时启动两个 wordpress 容器,实现负载均衡,不暴露端口,使用docker-compose1.yml文件:

docker-compose scale wordpress=2 

然后在主机中安装 haproxy 实现负载均衡:

yum install haproxy -y

修改配置文件:

cp /etc/haproxy/haproxy.cfg{,.bak}
vim /etc/haproxy/haproxy.cfg

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 level admin  #支持命令行控制
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 stats
    mode http
    bind 0.0.0.0:8888
    stats enable
    stats uri     /haproxy-status 
    stats auth    admin:123456
frontend frontend_www_example_com
    bind 10.0.0.100:8000
    mode http
    option httplog
    log global
    default_backend backend_www_example_com
backend backend_www_example_com
    option forwardfor header X-REAL-IP
    option httpchk HEAD / HTTP/1.0
    balance roundrobin
    server web-node1  10.0.0.100:32768 check inter 2000 rise 30 fall 15
    server web-node2  10.0.0.100:32769 check inter 2000 rise 30 fall 15

启动haproxy:

systemctl start haproxy
systemctl enable haproxy

浏览器访问: http://192.168.99.100:8888/haproxy-status