Created
August 15, 2017 01:25
-
-
Save shavit/976875a56368b329d806f3f8d7e2ac26 to your computer and use it in GitHub Desktop.
Create swarm of Docker servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Create a swarm manager and consul | |
# | |
# 1. Create 7 servers | |
# CONSUL_ADDRESS= | |
# SWARM_MANAGER_1_ADDRESS= | |
# SWARM_MANAGER_2_ADDRESS= | |
# LOAD_BALANCER_1_ADDRESS= | |
# LOAD_BALANCER_2_ADDRESS= | |
# WEB_APP_1_ADDRESS= | |
# WEB_APP_2_ADDRESS= | |
# | |
# 2. Consul | |
# | |
# Create consul service | |
ssh CONSUL_ADDRESS \ | |
docker run -d -p 8500:8500 --name consul progrium/consul -server -bootstrap | |
# | |
# 3. Swarm managers | |
# | |
# Create a swarm manager | |
ssh SWARM_MANAGER_1_ADDRESS \ | |
docker run -d -p 4000:4000 --name swarm-mananger swarm manage -H :4000 \ | |
--replication --advertise $SWARM_MANAGER_1_ADDRESS:4000 consul://$CONSUL_ADDRESS:8500 | |
# Create a second swarm manager | |
ssh SWARM_MANAGER_2_ADDRESS \ | |
docker run -d -p 4000:4000 --name swarm-mananger swarm manager -H :4000 \ | |
--replication --advertise $SWARM_MANAGER_2_ADDRESS:4000 consul://$CONSUL_ADDRESS:8500 | |
# | |
# 4. Connect to the swarm | |
# | |
# Run the swarm and expose the ip address on each of the nodes | |
ssh LOAD_BALANCER_1_ADDRESS \ | |
docker run -d --name swarm --restart always swarm join --advertise=$LOAD_BALANCER_1_ADDRESS:2375 consul://$CONSUL_ADDRESS:8500 | |
ssh LOAD_BALANCER_1_ADDRESS \ | |
cat default_docker.txt >> /etc/default/docker | |
ssh LOAD_BALANCER_1_ADDRESS \ | |
systemctl restart docker | |
ssh LOAD_BALANCER_2_ADDRESS \ | |
docker run -d --name swarm --restart always swarm join --advertise=$LOAD_BALANCER_2_ADDRESS:2375 consul://$CONSUL_ADDRESS:8500 | |
ssh LOAD_BALANCER_2_ADDRESS \ | |
cat default_docker.txt >> /etc/default/docker | |
ssh LOAD_BALANCER_2_ADDRESS \ | |
systemctl restart docker | |
ssh WEB_APP_1_ADDRESS \ | |
docker run -d --name swarm --restart always swarm join --advertise=$WEB_APP_1_ADDRESS:2375 consul://$CONSUL_ADDRESS:8500 | |
ssh WEB_APP_1_ADDRESS \ | |
cat default_docker.txt >> /etc/default/docker | |
ssh WEB_APP_1_ADDRESS \ | |
systemctl restart docker | |
ssh WEB_APP_2_ADDRESS \ | |
docker run -d --name swarm --restart always swarm join --advertise=$WEB_APP_2_ADDRESS:2375 consul://$CONSUL_ADDRESS:8500 | |
ssh WEB_APP_2_ADDRESS \ | |
cat default_docker.txt >> /etc/default/docker | |
ssh WEB_APP_2_ADDRESS \ | |
systemctl restart docker | |
# | |
# 5. Manage from the swarm manager | |
# | |
# Login to SWARM_MANAGER_1_ADDRESS | |
ssh SWARM_MANAGER_1_ADDRESS \ | |
docker -H :4000 info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make sure that port 2376 is close and the nodes are on the same private network. | |
DOCKER_OPTS="--cluster-advertise eth1:2376 --cluster-store consul://$CONSUL_ADDRESS:8500 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment