一、基础环境安装
如果你不想太麻烦,可以采用一台机器实现分布式,也是可以的按第1小节伪分布式环境小节进行实操,如果你有多台机器或虚拟机可以按第2小节进行实操。
1伪分布式环境
可以购买1折的云服务器也可以采用vmare在本地虚拟出一台centos7服务器。本人购买的新用户1折的云服务器。
a)安装docker(离线)
下载docker安装包docker-18.06.3-ce.tgz。然后上传到/opt文件夹下。
执行解压命令,并拷贝到/usr/bin/文件夹下
tar xzvf docker-18.06.3-ce.tgz
cp -ar docker/* /usr/bin/
编辑docker.service文件并复制配置内容进去。
vi /usr/lib/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 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
加载配置并启动docker
systemctl daemon-reload
systemctl start docker.service
验证docker是否已安好
docker ps
b) 创建docker swarm集群环境
输入ifconfig查看centos的网络情况,如果是云环境那么他有公网IP和私网IP,公网IP是私网IP的一个映射,我们只需要获取私网IP就可以的,我的华为云私网IP是192开头的,如下图
可以知道我的IP是192.168.0.163。
创建集群主节点:
docker swarm init --advertise-addr 192.168.0.163
验证集群节点
至此,单个节点的docker swarm 分布式节点已经完成,下节介绍多节点docker swarm部署



