查看主机名

hostnamectl 

修改主机名

hostnamectl set-hostname xxx

关闭selinux

sed -i 's/SELINUX=enforcing/#SELINUX=enforcing/'  /etc/selinux/config
sed -i "/#SELINUX=enforcing/a\SELINUX=disabled"   /etc/selinux/config

关闭防火墙或者开放端口

systemctl stop firewalld

修改hosts

vi /etc/hosts

安装docker

yum -y install docker

主节点初始化集群

docker swarm init --advertise-addr 192.168.6.130:2377

创建集群网络

docker network create --driver overlay 网络名

其他机器加入集群

测试

docker service create -p 80:80 --name webserver --replicas 5 httpd

注意:非必选项,修改ExecStart
(待核实,因为搭建集群后访问其他 节点并未生效,改了这个配置重启才生效。但感觉并非此问题。)

vi /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          --init-path=/usr/libexec/docker/docker-init-current \
          --seccomp-profile=/etc/docker/seccomp.json \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $REGISTRIES

参考链接:
https://blog.csdn.net/zmx729618/article/details/81709639
http://www.bubuko.com/infodetail-2433187.html
https://www.cnblogs.com/wlbl/p/10207749.html