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管理

猜你喜欢

转载自blog.51cto.com/14285990/2495514