上一篇文章,顺利完成了在CentOS7上安装部署kubernetes。接下来,考虑在CentOS7配置部署etcd的高可用集群。
从etcd clustering的官方站点上,看到有3中方式来引导etcd cluster。这里分别以静态引导和public etcd discovery这两种方式给出配置过程。假定:
- 你已经在CentOS7上安装好etcd,如果没有,可以参考在CentOS 7上安装部署kubernetes,或者利用yum单独安装etcd;
- 要配置etcd cluster的3台机器分别为:172.16.11.30,172.16.11.71,172.16.11.78;
- 及其在cluster中的命名依次为:infra0,infra1,infra2;
一 采用static方式开始执行配置:
1 第1台机器172.16.11.30上执行:
[root@localhost ~]# etcd --name infra0 --initial-advertise-peer-urls http://172.16.11.30:2380 --listen-peer-urls http://172.16.11.30:2380 --listen-client-urls http://172.16.11.30:2379,http://127.0.0.1:2379 --advertise-client-urls http://172.16.11.30:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster infra0=http://172.16.11.30:2380,infra1=http://172.16.11.71:2380,infra2=http://172.16.11.78:2380 --initial-cluster-state new
2 第2台机器172.16.11.71上执行:
[root@test-zyd-jy-2 ~]# etcd --name infra1 --initial-advertise-peer-urls http://172.16.11.71:2380 --listen-peer-urls http://172.16.11.71:2380 --listen-client-urls http://172.16.11.71:2379,http://127.0.0.1:2379 --advertise-client-urls http://172.16.11.71:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster infra0=http://172.16.11.30:2380,infra1=http://172.16.11.71:2380,infra2=http://172.16.11.78:2380 --initial-cluster-state new
3 第3台机器172.16.11.78上执行:
[root@localhost ~]# etcd --name infra2 --initial-advertise-peer-urls http://172.16.11.78:2380 --listen-peer-urls http://172.16.11.78:2380 --listen-client-urls http://172.16.11.78:2379,http://127.0.0.1:2379 --advertise-client-urls http://172.16.11.78:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster infra0=http://172.16.11.30:2380,infra1=http://172.16.11.71:2380,infra2=http://172.16.11.78:2380 --initial-cluster-state new
4 任意机器上,验证cluster健康信息:
[root@localhost ~]# etcdctl cluster-health member 2a21240027dcd247 is healthy: got healthy result from http://172.16.11.30:2379 member 784c02b20039dc5b is healthy: got healthy result from http://172.16.11.71:2379 member b1ca771041e5f776 is healthy: got healthy result from http://172.16.11.78:2379 cluster is healthy [root@localhost ~]#
5 任意机器上,执行etcdctl set key value:
[root@localhost ~]# etcdctl set k1 100 100 [root@localhost ~]# etcdctl get k1 100 [root@localhost ~]#
6 其它机器上,执行etcdctl get key来验证:
[root@test-zyd-jy-2 ~]# etcdctl get k1 100 [root@test-zyd-jy-2 ~]#
至此,通过静态方式,配置了一个3个节点的etcd cluster。关于上述命令中,几个参数的说明:
- name:指位于同一个cluster中的每个etcd 节点的名字,必须唯一;
- listen-client-urls:etcd接收客户端发起请求的监听地址;
- advertise-client-urls:etcd cluster中的成员用于给其它成员或者客户端,发送广播的地址信息;该地址既不能配置为localhost的形式,也绝对不能留空;
二 采用discovery方式来配置etcd cluster
discovery方式配置etcd cluster又分为etcd discovery service和DNS discovery方式,这里采用etcd discovery service方式来配置etcd cluster。
1 创建public discovery的token
curl https://discovery.etcd.io/new?size=3
这里,只需在其中任意节点执行上述命令,并获取命令的结果。这个结果集用于整个etcd cluster的配置。
[root@localhost ~]# curl https://discovery.etcd.io/new?size=3 https://discovery.etcd.io/920771e9b700844194c13ebeff79a543[root@localhost ~]#
2 第1台机器172.16.11.30上执行:
[root@localhost ~]# etcd --name centos-master --initial-advertise-peer-urls http://172.16.11.30:2380 --listen-peer-urls http://172.16.11.30:2380 --listen-client-urls http://127.0.0.1:4001,http://172.16.11.30:4001 --advertise-client-urls http://172.16.11.30:4001 --discovery https://discovery.etcd.io/920771e9b700844194c13ebeff79a543 2018-01-16 09:40:51.420704 I | etcdmain: etcd Version: 3.2.9 2018-01-16 09:40:51.421594 I | etcdmain: Git SHA: f1d7dd8 2018-01-16 09:40:51.421624 I | etcdmain: Go Version: go1.8.3 2018-01-16 09:40:51.421644 I | etcdmain: Go OS/Arch: linux/amd64 2018-01-16 09:40:51.421673 I | etcdmain: setting maximum number of CPUs to 4, total number of available CPUs is 4 2018-01-16 09:40:51.422265 W | etcdmain: no data-dir provided, using default data-dir ./centos-master.etcd 2018-01-16 09:40:51.422854 I | embed: listening for peers on http://172.16.11.30:2380 2018-01-16 09:40:51.423539 I | embed: listening for client requests on 127.0.0.1:4001 2018-01-16 09:40:51.423694 I | embed: listening for client requests on 172.16.11.30:4001 2018-01-16 09:40:53.344420 N | discovery: found self 425cf1a6e9b4c574 in the cluster 2018-01-16 09:40:53.344515 N | discovery: found 1 peer(s), waiting for 2 more ... ...
3 第1台机器172.16.11.71上执行:
[root@test-zyd-jy-2 ~]# etcd --name centos-master71 --initial-advertise-peer-urls http://172.16.11.71:2380 --listen-peer-urls http://172.16.11.71:2380 --listen-client-urls http://127.0.0.1:4001,http://172.16.11.71:4001 --advertise-client-urls http://172.16.11.71:4001 --discovery https://discovery.etcd.io/920771e9b700844194c13ebeff79a543 2018-01-16 09:42:18.030679 I | etcdmain: etcd Version: 3.2.9 2018-01-16 09:42:18.030858 I | etcdmain: Git SHA: f1d7dd8 2018-01-16 09:42:18.030872 I | etcdmain: Go Version: go1.8.3 2018-01-16 09:42:18.030884 I | etcdmain: Go OS/Arch: linux/amd64 2018-01-16 09:42:18.030897 I | etcdmain: setting maximum number of CPUs to 4, total number of available CPUs is 4 2018-01-16 09:42:18.030920 W | etcdmain: no data-dir provided, using default data-dir ./centos-master71.etcd 2018-01-16 09:42:18.031763 N | etcdmain: the server is already initialized as member before, starting as etcd member... 2018-01-16 09:42:18.032013 I | embed: listening for peers on http://172.16.11.71:2380 2018-01-16 09:42:18.032364 I | embed: listening for client requests on 127.0.0.1:4001 2018-01-16 09:42:18.032463 I | embed: listening for client requests on 172.16.11.71:4001 2018-01-16 09:42:20.062578 N | discovery: found peer 425cf1a6e9b4c574 in the cluster 2018-01-16 09:42:20.062701 N | discovery: found self d91473943b320695 in the cluster 2018-01-16 09:42:20.062718 N | discovery: found 2 peer(s), waiting for 1 more
4 第1台机器172.16.11.78上执行:
[root@localhost ~]# etcd --name centos-master78 --initial-advertise-peer-urls http://172.16.11.78:2380 --listen-peer-urls http://172.16.11.78:2380 --listen-client-urls http://127.0.0.1:4001,http://172.16.11.78:4001 --advertise-client-urls http://172.16.11.78:4001 --discovery https://discovery.etcd.io/920771e9b700844194c13ebeff79a543 2018-01-16 09:43:08.553406 I | etcdmain: etcd Version: 3.2.9 2018-01-16 09:43:08.553770 I | etcdmain: Git SHA: f1d7dd8 2018-01-16 09:43:08.553785 I | etcdmain: Go Version: go1.8.3 2018-01-16 09:43:08.553799 I | etcdmain: Go OS/Arch: linux/amd64 2018-01-16 09:43:08.553812 I | etcdmain: setting maximum number of CPUs to 8, total number of available CPUs is 8 2018-01-16 09:43:08.553840 W | etcdmain: no data-dir provided, using default data-dir ./centos-master78.etcd 2018-01-16 09:43:08.554396 N | etcdmain: the server is already initialized as member before, starting as etcd member... 2018-01-16 09:43:08.554762 I | embed: listening for peers on http://172.16.11.78:2380 2018-01-16 09:43:08.554951 I | embed: listening for client requests on 127.0.0.1:4001 2018-01-16 09:43:08.555013 I | embed: listening for client requests on 172.16.11.78:4001 2018-01-16 09:43:10.345677 N | discovery: found peer 425cf1a6e9b4c574 in the cluster 2018-01-16 09:43:10.345813 N | discovery: found peer d91473943b320695 in the cluster 2018-01-16 09:43:10.345831 N | discovery: found self 98d67d53103d0e5e in the cluster 2018-01-16 09:43:10.345845 N | discovery: found 3 needed peer(s) 2018-01-16 09:43:10.346126 I | etcdserver: name = centos-master78 2018-01-16 09:43:10.346145 I | etcdserver: data dir = centos-master78.etcd 2018-01-16 09:43:10.346161 I | etcdserver: member dir = centos-master78.etcd/member 2018-01-16 09:43:10.346210 I | etcdserver: heartbeat = 100ms 2018-01-16 09:43:10.346226 I | etcdserver: election = 1000ms 2018-01-16 09:43:10.346240 I | etcdserver: snapshot count = 100000 2018-01-16 09:43:10.346286 I | etcdserver: discovery URL= https://discovery.etcd.io/920771e9b700844194c13ebeff79a543 2018-01-16 09:43:10.346322 I | etcdserver: advertise client URLs = http://172.16.11.78:4001 2018-01-16 09:43:10.346368 I | etcdserver: initial advertise peer URLs = http://172.16.11.78:2380 2018-01-16 09:43:10.346429 I | etcdserver: initial cluster = centos-master78=http://172.16.11.78:2380 2018-01-16 09:43:10.353143 I | etcdserver: starting member 98d67d53103d0e5e in cluster 57d019a9b13bd63a 2018-01-16 09:43:10.353268 I | raft: 98d67d53103d0e5e became follower at term 0
5 任意机器上,验证cluster健康信息:
[root@localhost ~]# etcdctl cluster-health member 425cf1a6e9b4c574 is healthy: got healthy result from http://172.16.11.30:4001 member 98d67d53103d0e5e is healthy: got healthy result from http://172.16.11.78:4001 member d91473943b320695 is healthy: got healthy result from http://172.16.11.71:4001 cluster is healthy [root@localhost ~]#
至此,通过static和discovery service两种方式来配置了etcd cluster。