利用 Docker 在不同宿主机做 CentOS 系统容器( 三 )


#ETCD_GRPC_KEEPALIVE_MIN_TIME= "5s"
#ETCD_GRPC_KEEPALIVE_INTERVAL= "2h0m0s"
#ETCD_GRPC_KEEPALIVE_TIMEOUT= "20s"
#
#[Clustering]
#ETCD_INITIAL_ADVERTISE_PEER_URLS= "http://localhost:2380"
ETCD_ADVERTISE_CLIENT_URLS= "http://etcd:2379,http://etcd:4001"#通知客户端地址
#ETCD_DISCOVERY= ""
3、启动etcd服务
[root@master ~] # systemctl start etcd.service
[root@master ~] # systemctl enable etcd.service
4、查看etcd服务是否启动成功
[root@master ~] # netstat -tnlp | grep -E "4001|2380"
tcp 00127.0.0.1: 23800.0.0.0:* LISTEN 22733/etcd
tcp6 00::: 4001:::* LISTEN 22733/etcd
[root@master ~] # ps -ef | grep etcd
etcd 22733114月 17? 03: 33: 44/usr /bin/etcd --name=master --data-dir=/var/lib/etcd/default.etcd --listen-client-urls=http://0.0.0.0:2379,http:// 0.0.0.0: 4001
root 162335104月 22? 00: 04: 37/usr /bin/flanneld -etcd-endpoints=http://etcd: 2379-etcd-prefix=/atomic.io/network
root 333684333652019: 58pts/ 200: 00: 00vi /etc/etcd/etcd.conf
root 334263333652020: 00pts/ 200: 00: 00vi /etc/etcd/etcd.conf
root 338219333652020: 14pts/ 200: 00: 00grep --color=auto etcd
[root@master ~] # etcdctl -C http://etcd:4001 cluster-health
member 8e9e05c52164694d ishealthy: got healthy result fromhttp: //etcd: 2379
cluster ishealthy
[root@master ~] # etcdctl -C http://etcd:2379 cluster-health
member 8e9e05c52164694d ishealthy: got healthy result fromhttp: //etcd: 2379
cluster ishealthy
[root@master ~] #
5、在etcd中配置flannel需要用到的键值
[root@master ~] # etcdctl mk /atomic.io/network/config '{ "Network": "172.18.0.0/16"}'
{ "Network": "172.18.0.0/16"}
3.2.3、安装Flannel
flannel是所有宿主机需要安装的中间件,而且前文中提到的hosts文件一定要设置好 。
1、安装flannel服务
yuminstall flannel -y
2、修改flannel配置文件
[root@master ~] # vim /etc/sysconfig/flanneld
# Flanneld configuration options
# etcd url location. Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS= "http://etcd:2379"#etcd客户端端口
# etcd config key. This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX= "/atomic.io/network"#这个参数的值需要是etcd保存的key值,不然flannel启动不了
# Any additional options that you want to pass
#FLANNEL_OPTIONS=""
flanneld配置文件中的FLANNEL_ETCD_PREFIX参数与上文中保存在etcd中的一个键值是相对应的,但要注意FLANNEL_ETCD_PREFIX参数的值没有后边的/config 。
3、启动flanneld服务
[root@master ~] # systemctl start flanneld.service
[root@master ~] # systemctl enable flanneld.service
4、查看flanneld服务是否启动成功
[root@master ~] # ps -ef|grep flanneld
root 162335104月 22? 00: 04: 38/usr/bin/flanneld -etcd-endpoints=http: //etcd: 2379-etcd-prefix= /atomic.io/network
root 345092333652020: 37pts/ 200: 00: 00vim /etc/sysconfig/flanneld
root 345496333652020: 39pts/ 200: 00: 00vim /etc/sysconfig/flanneld
root 345545333652020: 39pts/ 200: 00: 00vim /etc/sysconfig/flanneld
root 347078333652020: 44pts/ 200: 00: 00vim /etc/sysconfig/flanneld
root 350147333652020: 54pts/ 200: 00: 00grep--color=auto flanneld
[root@master ~] # ifconfig flannel0
flannel 0: flags= 4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1472
inet 172.18. 92.0netmask 255.255. 0. 0destination 172.18. 92.0
inet6 fe8 0:: 244d:d95c:a79f:af2d prefixlen 64scopeid 0x20< link>
unspec 00- 00- 00- 00- 00- 00- 00- 00- 00- 00- 00- 00- 00- 00- 00- 00txqueuelen 500(UNSPEC)
RX packets 2691026bytes 142959067( 136.3MiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 2690704bytes 152477868( 145.4MiB)
TX errors 0dropped 0overruns 0carrier 0collisions 0
此时可看到flannel生成的flannel0网卡的IP是在etcd保存的网段内的,说明flannel网络配置完成 。


推荐阅读