Centos7 deploys Swarm

===============================================

 2018/5/1_1st modification ccb_warlock

 

===============================================

Since the k8s plan has been shelved, currently only using swarm to build a small-scale cluster can be considered. After a few days of using swarm, I have a clearer understanding of docker-compose, service, and stack related content. Comparing swarm and k8s is also different.

  


1. Preparations
1.1 Install wget and vim

yum install -y wget vim

 

1.2 Turn off the firewall

systemctl stop firewalld
systemctl disable firewalld

 

1.3 Modify the hostname
manager node to execute:

hostnamectl --static set-hostname  swarm-M01

 

The work node executes:

hostnamectl --static set-hostname  swarm-W01

 


2. Install docker

2.1 Install docker-ce

wget -P /etc/yum.repos.d/ https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce

 

2.2 Setting up
an image accelerator Because of the wall, accessing docker hub is not stable enough, so it is necessary to set up an image accelerator to solve this problem.
The image accelerator of Alibaba Cloud is used here.
After logging in to Alibaba Cloud, visit https://cr.console.aliyun.com/#/accelerator

2.3 Configure hosts information

# Modify docker daemon configuration

vim /etc/docker/daemon.json

 

# Add host information and save it in wq.

{
   "hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]
}

 

2.4 Restart, start docker

systemctl restart docker
systemctl enable docker

  


3. Install docker-compose
# Get the docker-compose file (1.21.0)

wget https://github.com/docker/compose/releases/download/1.21.0/docker-compose-Linux-x86_64

PS. You can find the latest version of docker-compose-Linux-x86_64 at https://github.com/docker/compose/releases. After downloading, upload it to the /usr/local/bin directory and change its name to docker-compose.

 

# Rename docker-compose-Linux-x86_64 to docker-compose and copy it to the /usr/local/bin/ directory

cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose

 

# Give the docker-compose file execute permission

chmod +x /usr/local/bin/docker-compose

 


3. Deploy swarm management nodes

# Create a cluster (12.11)

docker swarm init

 

# Create a cluster (when the host has multiple IPs, you need to specify the IP)

docker swarm init --advertise-addr 192.168.12.11

After creation, the node is the manager node (leader).

 

If you need to add other management nodes, you can use the following command to view the command to join the cluster as a management node.

docker swarm join-token manager

  


Fourth, deploy docker node

# View the command to join the cluster as a worker node

docker swarm join-token worker

 

# Register yourself to the cluster (12.11)

docker swarm join --token SWMTKN-1-1w1q09p1z37n4j24usz9lwb0i01t2ecuxn4ad5ctfdpks4270r-5p5mmiw6u77skwd49sxovztxc 192.168.12.11:2377

PS. The token information in the command is changed according to the actual situation.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325111494&siteId=291194637