A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

文章将会引导你:

Centos搭建docker环境(节点环境准备)
swarm单集群
Centos搭建docker环境(节点环境准备)

系统要求:
目前,CentOS 仅发行版本中的内核支持 Docker。
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。

安装必要工具

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
1
添加阿里云下载源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1
安装docker-ce
sudo yum makecache fast(可选操作)

sudo yum -y install docker-ce
1
2
3
一些无关的优化设置
systemctl stop firewalld(关闭防火墙)

systemctl disable firewalld(开启不开启防火墙)

systemctl start docker(启动docker)

systemctl enable docker(开机启动docker)
1
2
3
4
5
6
7
swarm单集群

环境说明
hostname        idaddress        role
swarm01        192.168.198.131        manager
swarm02        192.168.198.132        manager
swarm03        192.168.198.133        worker
操作目的解释
在swarm01进行节点初始化,默认是manager节点; swarm02作为manager节点加入集群中;swarm02作为worker节点加入集群中。最终的效果展示的大概是这样的:

[root@swarm01 ~]# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
pxginxl7p0ck7sc6lc3r7yfvg *   swarm01             Ready               Active              Leader              18.09.4
wwjbu34lqg9diney4e4xpes3l     swarm02             Ready               Active              Reachable           18.09.4
0pv07jzs0cf4581q283r1nqp5     swarm03             Ready               Active                                  18.09.4
1
2
3
4
5
环境准备(这里只配置swarm01,其余两个同理)
准备三个docker环境的虚拟机,要求之间具有联通关系

swarm01主机相关操作

hostname swarm01(主机名称命名)

还有可能需要配置静态ip
vim /etc/sysconfig/network-scripts/ifcfg-en33(编辑网络配置文件,名称可能不是这个,具体系统具体对待)

需要修改部分
BOOTPROTO="static"
BROADCAST=192.168.198.255
IPADDR=192.168.198.131
NETMASK=255.255.255.0
GATEWAY=192.168.198.2

如何获取上面的信息
ifconfig

netstat -rn

如果没有ifconfig命令,可以进行下面的操作
[root@swarm01 network-scripts]# yum search ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ap.stykers.moe
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
============================================================================================================================= Matched: ifconfig ==============================================================================================================================
net-tools.x86_64 : Basic networking tools
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
集群初始化
操作位置:swarm01
[root@swarm01 network-scripts]# docker swarm init --advertise-addr 192.168.198.131 \--listen-addr 192.168.198.131:2377
Swarm initialized: current node (2g6592p43eonilcjvivw3ww1f) is now a manager.

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

    docker swarm join --token SWMTKN-1-2gyvi3dxuyuw9h5red8hty6hu9rvgwsxfmo296e1ajtfln0rsl-exsbzi1308n0kstnrizfwqyv5 192.168.198.131:2377

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

[root@swarm01 network-scripts]#

查看集群初始化效果
[root@swarm01 network-scripts]# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
[root@swarm01 network-scripts]#

获取控制节点的token
[root@swarm01 network-scripts]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2gyvi3dxuyuw9h5red8hty6hu9rvgwsxfmo296e1ajtfln0rsl-3ujqri9fd63dns6v37z9cxd84 192.168.198.131:2377

[root@swarm01 network-scripts]#

拷贝这句话在swarm02上执行
[root@swarm02 ~]# docker swarm join --token SWMTKN-1-2gyvi3dxuyuw9h5red8hty6hu9rvgwsxfmo296e1ajtfln0rsl-3ujqri9fd63dns6v37z9cxd84 192.168.198.131:2377
This node joined a swarm as a manager.
[root@swarm02 ~]#


获取工作节点的token
[root@swarm01 network-scripts]# docker swarm join-token worker
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2gyvi3dxuyuw9h5red8hty6hu9rvgwsxfmo296e1ajtfln0rsl-exsbzi1308n0kstnrizfwqyv5 192.168.198.131:2377

[root@swarm01 network-scripts]#


拷贝这句话在swarm03执行
[root@swarm03 ~]#  docker swarm join --token SWMTKN-1-2gyvi3dxuyuw9h5red8hty6hu9rvgwsxfmo296e1ajtfln0rsl-exsbzi1308n0kstnrizfwqyv5 192.168.198.131:2377
This node joined a swarm as a worker.
[root@swarm03 ~]#

集群节点最终查看效果
[root@swarm01 network-scripts]# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active              Reachable           18.09.4
hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
[root@swarm01 network-scripts]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
swarm集群搭建总结
总的来说操作相对于k8s简直简单的不是一点
这篇文章没有大量的截图不符合我的尿性,失败。
更多集群的操作命令这篇文章就不在介绍了,后续我会新开一篇文章进行介绍,还行大家多多关注。
---------------------
【转载,仅作分享,侵删】
作者:dream_on_sakura_rain
原文:https://blog.csdn.net/qq_32112175/article/details/89048747
版权声明:本文为博主原创文章,转载请附上博文链接!

1 个回复

正序浏览
奈斯,感谢分享!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马