1.安装etcd (3节点)
1.1. 修改host
1 2 3 |
172.16.60.21 node1 172.16.60.22 node2 172.16.60.23 node3 |
1.2.修改内核参数,使之支持ip转发
1 2 3 |
echo 1 > /proc/sys/net/ipv4/ip_forward cat /etc/sysctl.conf sysctl -p |
1 2 |
yum install etcd -y cp /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak |
1.3.修改etcd配置
1 |
vim /etc/etcd/etcd.conf |
node1
1 2 3 4 5 6 7 8 9 10 11 |
#[Member] ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_NAME="node3" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.21:2380" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.21:2379" ETCD_INITIAL_CLUSTER="node1=http://192.168.0.21:2380,node2=http://192.168.0.22:2380,node3=http://192.168.0.23:2380" |
node2
1 2 3 4 5 6 7 8 9 10 11 |
#[Member] ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_NAME="node3" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.22:2380" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.22:2379" ETCD_INITIAL_CLUSTER="node1=http://192.168.0.21:2380,node2=http://192.168.0.22:2380,node3=http://192.168.0.23:2380" |
node3
1 2 3 4 5 6 7 8 9 10 11 |
#[Member] ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_NAME="node3" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.23:2380" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.23:2379" ETCD_INITIAL_CLUSTER="node1=http://192.168.0.21:2380,node2=http://192.168.0.22:2380,node3=http://192.168.0.23:2380" |
1.4.启动etcd
1 |
systemctl enable etcd && systemctl start etcd |
再次查看,发现多了一个etcd进程
1 |
ps -ef | grep etcd |
1 |
etcdctl member list |
1.5.etcd集群健康检查
1 |
etcdctl cluster-health |
1 2 3 4 5 6 7 8 9 10 11 12 |
=========================================================================================== 温馨提示: 如果/etc/etcd/etcd.conf配置错误,etcd服务启动了,然后再次修改后重启etcd,发现没有生效! 查看日志命令为"journalctl -xe",发现下面错误信息: the server is already initialized as member before, starting as etcd member... ...... simple token is not cryptographically signed 解决办法: 1) 删除各个节点的/var/lib/etcd/default.etcd/目录下的数据,即"rm -rf /var/lib/etcd/default.etcd/*" 2) 检查/etc/etcd/etcd.conf文件是否配置正确 3) 重新启动etcd服务,即"systemctl stop etcd && systemctl start etcd" , 这样新配置就会重新生效了! |
2.设置overlay网络
2.1 修改docker配置文件
1 |
vim /usr/lib/systemd/system/docker.service |
添加:
1 2 3 4 5 |
--cluster-store=etcd://192.168.0.21:2379 --cluster-advertise=eth0:2357 #参数解析: --cluster-store= 参数指向docker daemon所使用key value service的地址(本例中即etcd的服务地址) --cluster-advertise= 参数决定了所使用网卡以及docker daemon端口信息 |
1 |
systemctl daemon-reload && systemctl restart docker |
2.2创建overlay网络
1 2 3 4 |
docker network create -d overlay my_net #或者也可以指定网络段 docker network create -d overlay my_net --subnet 10.10.10.0/24 (指定子网),这里默认是10.0.0.0 |
overlay 是 global 网络,etcd 会将 my_net 同步到所有主机
2.3测试网络互通
1 2 3 4 |
node1: docker run --net my_net --name demo1 -tid busybox node2 docker run --net my_net --name demo2 -tid busybox |
ping 测试(通过ip和服务名ping都可以通)
(完成)
- 本文固定链接: https://www.yoyoask.com/?p=6497
- 转载请注明: shooter 于 SHOOTER 发表