centos7 docker安裝 配置swarm集羣 配置portainer管理

一、安裝docker
系統信息

[root@localhost yum.repos.d]# cat /etc/centos-release
CentOS Linux release 7.8.2003 (Core)
[root@localhost yum.repos.d]# uname -a
Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost yum.repos.d]# 

1、安裝yum擴展工具
yum install -y yum-utils #(yum-utils的作用是管理repository及擴展包的工具,添加 repo 文件)

2、添加docker源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost yum.repos.d]# ls -l
總用量 40
-rw-r--r--. 1 root root 1664 4月   8 06:01 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 4月   8 06:01 CentOS-CR.repo
-rw-r--r--. 1 root root  649 4月   8 06:01 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 4月   8 06:01 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 4月   8 06:01 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 4月   8 06:01 CentOS-Sources.repo
-rw-r--r--. 1 root root 7577 4月   8 06:01 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 4月   8 06:01 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 2424 10月 19 2019 docker-ce.repo   #多了一個文件
[root@localhost yum.repos.d]# 

3、安裝docker-ce
yum install docker-ce docker-ce-cli containerd.io

yum list docker-ce --showduplicates | sort -r # 查看能安裝的版本
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.i #安裝指定版本

4、啓動docker
systemctl start docker #啓動docker

5、驗證docker
docker run hello-world 輸出一個

[root@localhost yum.repos.d]# ps -ef |grep docker
root     28579  2176  0 19:01 pts/0    00:00:00 grep --color=auto docker
[root@localhost yum.repos.d]# systemctl start docker
[root@localhost yum.repos.d]# ps -ef |grep docker
root     28589     1  2 19:01 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root     28713  2176  0 19:01 pts/0    00:00:00 grep --color=auto docker
[root@localhost yum.repos.d]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

6、輸出以上內容證明docker安裝成功

二、初始化docker的swarm集羣管理工具:(參考:https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/
192.168.1.6(主節點)

[root@docker03 ~]# docker swarm init --advertise-addr 192.168.1.6
Swarm initialized: current node (9rkx43tvikx2ap88pf9eulqvc) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-5vcgwju55lnbz91wyg58payafh60xyhj8xvw5nkgzxaxwtx97m-63fxrrxedmk2hrcgy9ka4eekn 192.168.1.6:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

192.168.1.7(集羣節點)加入該集羣:
docker swarm join --token SWMTKN-1-5vcgwju55lnbz91wyg58payafh60xyhj8xvw5nkgzxaxwtx97m-63fxrrxedmk2hrcgy9ka4eekn 192.168.1.6:2377
centos7 docker安裝  配置swarm集羣   配置portainer管理

三、安裝portainer(參考:https://portainer.readthedocs.io/en/latest/deployment.html
1、創建卷:
docker volume create portainer_data

2、初始化portainer
docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

3、添加portainer-agent用於管理swarm集羣

curl -L https://downloads.portainer.io/portainer-agent-stack.yml -o portainer-agent-stack.yml
docker stack deploy --compose-file=portainer-agent-stack.yml portaine

4、重啓docker
systemctl restart docker

5、成功效果

centos7 docker安裝  配置swarm集羣   配置portainer管理

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章