docker-compose

Compose 是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose,您可以使用 YML 文件来配置应用程序需要的所有服务
[root@linux-node3 ~]# yum install pip*
[root@linux-node3 ~]# pip install docker-compose
vim haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096

defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000ms
timeout client 5000ms
timeout server 5000ms

listen stats
bind 0.0.0.0:1080
mode http
stats enable
stats hide-version
stats uri /stats
stats auth admin:admin

frontend balance
bind 0.0.0.0:80
default_backend web_backends

backend web_backends
mode http
option forwardfor
balance roundrobin
server web1 web1:80 check
server web2 web2:80 chec

vimdocker-compose.yml

web1:
image: nginx
volumes:
- /opt/index1.html:/usr/share/nginx/html/index.html
expose:
- 80

web2:
image: nginx
volumes:
- /opt/index2.html:/usr/share/nginx/html/index.html
expose:
- 80

haproxy:
image: haproxy
volumes:
- /opt/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
links:
- web1
- web2
ports:
- “7777:1080”

  • “80:80”

准备2个html文件
index1.html
index2.html

[root@linux-node3 opt]# docker-compose up 生产加-d 后台启动

负载成功

在这里插入图片描述
在这里插入图片描述
反复刷新,就可以看出负载成功。

登录haproxy里看看。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值