【发布时间】:2017-02-23 00:44:05
【问题描述】:
刚刚开始在 AWS 上使用 swarm。我可以使用 docker-machine、init swarm 创建集群并启动服务。但我努力让负载平衡正常工作。
我只能在部署它的主机上卷曲应用程序,其他主机不转发请求,不进行循环。
我正在使用以下脚本来测试我的集群。任何线索都会很棒,在这里有点卡住了。
!/bin/bash
aws_region=eu-west-1
instances=6
n=1
while [ $n -le $instances ]
do
machine_name=$aws_region-$n
docker-machine create \
--driver amazonec2 \
--amazonec2-region $aws_region \
--amazonec2-security-group 'swarm-cluster' \
$machine_name &
n=$(( n + 1 ))
done
!/bin/bash
Init managers
hostname="eu-west-1-1"
echo $hostname
manager_ip="$(docker-machine inspect $hostname | jq -r '.Driver.PrivateIPAddress'):2377"
docker $(docker-machine config $hostname) swarm init --advertise-addr $manager_ip --listen-addr $manager_ip
manager_token="$(docker $(docker-machine config $hostname) swarm join-token manager -q)"
worker_token="$(docker $(docker-machine config $hostname) swarm join-token worker -q)"
hostname="eu-west-1-2"
echo $hostname
ip="$(docker-machine inspect $hostname | jq -r '.Driver.PrivateIPAddress'):2377"
docker $(docker-machine config $hostname) swarm join \
--token $manager_token \
$manager_ip \
--advertise-addr $ip --listen-addr $ip
hostname="eu-west-1-3"
echo $hostname
ip="$(docker-machine inspect $hostname | jq -r '.Driver.PrivateIPAddress'):2377"
docker $(docker-machine config $hostname) swarm join \
--token $manager_token \
$manager_ip \
--advertise-addr $ip --listen-addr $ip
Init workers
hostname="eu-west-1-4"
echo $hostname
ip="$(docker-machine inspect $hostname | jq -r '.Driver.PrivateIPAddress'):2377"
docker $(docker-machine config $hostname) swarm join \
--token $worker_token \
$manager_ip \
--advertise-addr $ip --listen-addr $ip
hostname="eu-west-1-5"
echo $hostname
ip="$(docker-machine inspect $hostname | jq -r '.Driver.PrivateIPAddress'):2377"
docker $(docker-machine config $hostname) swarm join \
--token $worker_token \
$manager_ip \
--advertise-addr $ip --listen-addr $ip
hostname="eu-west-1-6"
echo $hostname
ip="$(docker-machine inspect $hostname | jq -r '.Driver.PrivateIPAddress'):2377"
docker $(docker-machine config $hostname) swarm join \
--token $worker_token \
$manager_ip \
--advertise-addr $ip --listen-addr $ip
eval $(docker-machine env eu-west-1-1)
docker service create --name web --replicas 3 --mount type=bind,src=/etc/hostname,dst=/usr/share/nginx/html/index.html,readonly --publish 80:80 nginx
【问题讨论】:
-
当您
curl其他机器之一时会发生什么?nginx图像具有较高的保活设置,因此如果您只是测试负载平衡,请尝试使用图像 from this answer
标签: docker amazon-ec2 docker-swarm