docker swarm 集群部署及portainer安装。本文相关文件下载 Go!
tar -zxvf docker-19.03.6.tgz
cp docker/* /usr/bin/
/data/server/docker 为实际目录,操作前创建该目录,确保目录挂载到数据盘。 请不要使用系统盘的目录
mkdir -p /data/server/docker
vi /etc/docker/daemon.json
{
"data-root" : "/data/server/docker"
}
vi /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --bip=172.20.1.0/16
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
重新加载配置systemctl daemon-reload
启动Dockerservice docker start
查看docker启动状态systemctl status docker
查看启动容器docker ps
设置开机自启动systemctl enable docker.service
查看docker开机启动状态 enabled:开启, disabled:关闭systemctl is-enabled docker.service
vi /etc/selinux/config
将 SELINUX=enforcing 改为 SELINUX=disabled #永久关闭,需要重启系统后生效
setenforce 0 #临时生效
代码如下(示例):
例如:
192.168.33.11 master
192.168.33.12 node01
192.168.33.13 node02
hostnamectl set-hostname docker_master
hostnamectl set-hostname docker_node01
hostnamectl set-hostname docker_node02
date -s "2023-11-09 19:04:00"
docker swarm init --advertise-addr {ip}
docker swarm join --token SWMTKN-1-05nc145s79y1l2zx1q4qtcfb0xtfzltzjb3gz757vwgi5o9y14-cgzm7zpcti9u9y3a53s8haq55 {ip}:{port}
docker swarm join-token worker
进行获取node节点执行 docker swarm leave
manager节点执行 docker swarm leave --force
docker load --input portainer.tar
创建portainer的数据存储路径 如 /data/server/portainer
docker run -d -p 39000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /data/server/portainer:/data -d portainer/portainer
替换路径后执行以上命令,访问ip:39000即可访问portainer页面,初次进入只需要设置用户名密码即可,直接点击local标签然后connect即可,其余无需操作