Docker 从入门到精通之Docker搭建Nginx集群
nginx集群
准备3台服务,创建3个nginx服务,搭建基于swarm的nginx服务集群
$ docker service create \
--name my-web \
-p 8080:80 \
--replicas 3 \
nginx:latest
pym6z9yfx25n49fkh6z0mw4xu
overall progress: 3 out of 3 tasks
1/3: running
2/3: running
3/3: running
verify: Service converged
查看服务
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
pym6z9yfx25n my-web replicated 3/3 nginx:latest *:8080->80/tcp
scale service
$ docker service scale my-web=2
配置负载均衡,此处用haproxy,也可以用consule做服务发现

在101这台服务器安装haproxy
$ mkdir /haproxy/haproxy.cfg
$ docker run -d -p 80:80 -v /haproxy:/usr/local/etc/haproxy --name haproxy haproxy
修改haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
# Configure HAProxy to listen on port 80
frontend http_front
bind *:80
stats uri /haproxy?stats
default_backend http_back
# Configure HAProxy to route requests to swarm nodes on port 8080
backend http_back
balance roundrobin
server node1 192.168.56.101:8080 check
server node2 192.168.56.106:8080 check
server node3 192.168.56.107:8080 check
访问http://192.168.56.101会轮询访问三个nginx服务
相关推荐
-
unix或centos离线安装jdk和nginx操作说明2023-10-23 15:41:26
-
Nginx自定义数据结构之字符串(String)数组(Array)链表(List)
Nginx自定义数据结构之字符串(String)数组(Array)链表(List)2023-10-23 15:41:09 -
Nginx的配置详解2023-10-23 15:40:54
-
Centos7 Nginx搭建局域网yum仓库详细步骤2023-10-23 15:38:59
-
nginx维护页面处置-全部URL指向同一个页面2023-10-23 15:35:52