docker swarm集群+Portainer图形化界面安装流程步骤
环境描述:(就是之前安装gitlab的环境,有兴趣的可以自行查阅)
centos7系统2台都安装好docker 版本为20.10.12
第一台:
hostname : master
ip地址:172.18.1.150
第二台:
hostname : work1
ip地址:172.18.1.151
安装swarm(初始化集群在150这台机上)
[[email protected] ~]# docker swarm init --advertise-addr 172.18.1.150
显示manager节点的TOKEN
[[email protected] ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-13uz401t6ukblcxdvtil8z6v3obo5pggysml2jw4cc2ak6ec92-8d7kg05wtavpv9i2vf340czh3 172.18.1.150:2377
master机器加入集群(复制上面的tk)
[[email protected] ~]# docker swarm join --token SWMTKN-1-13uz401t6ukblcxdvtil8z6v3obo5pggysml2jw4cc2ak6ec92-8d7kg05wtavpv9i2vf340czh3 172.18.1.150:2377
work1机器加入集群
[[email protected] ~]# docker swarm join --token SWMTKN-1-13uz401t6ukblcxdvtil8z6v3obo5pggysml2jw4cc2ak6ec92-8d7kg05wtavpv9i2vf340czh3 172.18.1.150:2377
查看一下刚刚加入集群的两台机器
[[email protected] ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
qaxikgjitmct371f6tci4ipbq * master Ready Active Reachable 20.10.12
2t84eyjo7mb7kljtnx8q6oznv work1 Ready Active Leader 20.10.12
在集群中安装Portainer服务
[[email protected] ~]# docker service create \
--name portainer \
--publish 9000:9000 \
--replicas=1 \
--constraint 'node.role == manager' \
--mount type=volume,src=portainer_data,dst=/data \
--mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \
portainer/portainer
查看一下
[[email protected] ~]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
9sjlthn68b39 portainer replicated 1/1 portainer/portainer:latest *:9000->9000/tcp
[root@master ~]# docker service ps portainer
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
iky6i9m04yly portainer.1 portainer/portainer:latest work1 Running Running 22 hours ago
59hzixdznzv1 \_ portainer.1 portainer/portainer:latest work1 Shutdown Failed 23 hours ago "task: non-zero exit (1)"
docker中监听一个tcp端口2375,后面Portainer添加主机是时候需要
在文件/usr/lib/systemd/system/docker.service文件中添加一下信息
[[email protected] ~]# sed -i 's/ExecStart=.*/ExecStart=\/usr\/bin\/dockerd -H unix\:\/\/\/var\/run\/docker.sock -D -H tcp\:\/\/0.0.0.0\:2375/g' /lib/systemd/system/docker.service
然后需要重启一下docker 执行以下命令
[[email protected] ~]# systemctl daemon-reload
[ro[email protected] ~]# systemctl restart docker
查看一下(2375端口是否显示出来)
[[email protected] ~]# ps -ef|grep docker
root 4384 26133 0 16:15 pts/0 00:00:00 grep --color=auto docker
root 31340 1 1 15:42 ? 00:00:23 /usr/bin/dockerd -H unix:///var/run/docker.sock -D -H tcp://0.0.0.0:2375
root 31480 31340 0 15:43 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 443 -container-ip 172.17.0.2 -container-port 443
root 31488 31340 0 15:43 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 443 -container-ip 172.17.0.2 -container-port 443
root 31503 31340 0 15:43 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.17.0.2 -container-port 80
root 31509 31340 0 15:43 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 80 -container-ip 172.17.0.2 -container-port 80
root 31525 31340 0 15:43 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 22 -container-ip 172.17.0.2 -container-port 22
root 31531 31340 0 15:43 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 22 -container-ip 172.17.0.2 -container-port 22
后面都是图形化,我就直接截图了
登录一下Portainer (第一次访问会要你设置admin密码,我这里已经设置好了)
这里选择remote,添加master主机 ip地址是172.18.1.150 端口:2375
添加好后是这个样子 (就截图了 其他就不描述了)
相关文章