【问题标题】:Docker swarm load balancing on AWS not workingAWS 上的 Docker 群负载平衡不起作用
【发布时间】: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


【解决方案1】:

我在 sa-east-1 地区遇到了同样的问题。这个完全相同的集群配置在 VirtualBox 上的本地虚拟机中运行良好:

Client:
 Version:      1.13.0
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Tue Jan 17 09:58:26 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.0
 API version:  1.25 (minimum version 1.12)
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Tue Jan 17 09:58:26 2017
 OS/Arch:      linux/amd64
 Experimental: false

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2015-08-07
    • 2012-12-19
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多