Centos7搭建swarm集群

1. 准备

两台虚拟机,IP分别为:
192.168.1.104
192.168.1.105
保证能互相 ping

2. 修改虚拟机的 host,分别任 c1、c2

192.168.1.105 中,设置其 hostc1

    hostnamectl --static set-hostname c1

查看:

    hostnamectl status

192.168.1.104 中,设置其 hostc2

    hostnamectl --static set-hostname c2

查看:

    hostnamectl status

3. 修改网络配置:

192.168.1.105 中:
运行:vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
修改以下几项:

静态IP:BOOTPROTO=static
自启动网络:ONBOOT=yes
设置IP:IPADDR0=192.168.1.105
设置子网掩码:PREFIXO0=255.255.255.0
设置网关:192.168.1.1
设置DNS:192.168.1.1

192.168.1.104 中,同样设置;

重启网络配置:service network restart

4. 将 hostname 加入 /etc/hosts

192.168.1.104

vi /etc/hosts

加入 192.168.1.105 c1

192.168.1.105

vi /etc/hosts

加入 192.168.1.104 c2

此时:
192.168.1.104 中:ping c1ping
192.168.1.105 中:ping c2ping

5. ssh 免密码登录:

c1 中:
运行:ssh-keygen
修改配置文件:vi /etc/ssh/sshd_config
去掉下面两行的注释:

    RSAAuthentication yes
    PubkeyAuthentication yes
将生成的密钥,复制到另一台:
    ssh-copy-id c1
    ssh-copy-id c2

c2 中类似;

验证:在 c1、c2 中:
运行:for n in $(seq 1 2); do ssh c$n hostname; done;
输出:

    c1
    c2

6. 使用 swarm (将 c1 作为管理节点)

c1 中:
运行:docker swarm init --advertise-addr 192.168.1.105
输出:

Swarm initialized: current node (8e4unyeyr41lm9ydpd6m5h2ik) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-0mff0pmz2wj90pis58ism59518pifb7kytcgiaavi8gpbem4im-174dot24tr60ntiafv1rso40n \
    192.168.1.105:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

c2 中,运行 c1 中输出的部分:

docker swarm join \
    --token SWMTKN-1-0mff0pmz2wj90pis58ism59518pifb7kytcgiaavi8gpbem4im-174dot24tr60ntiafv1rso40n \
    192.168.1.105:2377

输出:This node joined a swarm as a worker.
表示已经成为了一个工作节点。

c1 中:
运行:docker node ls
输出:

ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
        0zmhvma2s5km2pjn2mudutzru    c2        Ready   Active        
        8e4unyeyr41lm9ydpd6m5h2ik *  c1        Ready   Active        Leader

Leader 表示该节点为管理节点

集群建立成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值