美文网首页
在CentOS7上部署ETCD集群

在CentOS7上部署ETCD集群

作者: amoyzhu | 来源:发表于2017-03-03 16:34 被阅读0次

[root@all softs]# yum install etcd -y

[root@all softs]# mv /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak

[root@k8smaster softs]# vi /etc/etcd/etcd.conf

ETCD_NAME=etcdmaster

ETCD_DATA_DIR="/var/lib/etcd/etcd-master.etcd"

ETCD_LISTEN_PEER_URLS="http://172.16.160.205:2380"

ETCD_LISTEN_CLIENT_URLS="http://172.16.160.205:2379,http://127.0.0.1:2379"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.160.205:2380"

ETCD_INITIAL_CLUSTER="etcdmaster=http://172.16.160.205:2380,etcdnode1=http://172.16.160.206:2380,etcdnode2=http://172.16.160.207:2380"

ETCD_INITIAL_CLUSTER_STATE="new"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-00"

ETCD_ADVERTISE_CLIENT_URLS="http://172.16.160.205:2379"

[root@k8snode1 softs]# vi /etc/etcd/etcd.conf

ETCD_NAME=etcdnode1

ETCD_DATA_DIR="/var/lib/etcd/etcd-master.etcd"

ETCD_LISTEN_PEER_URLS="http://172.16.160.206:2380"

ETCD_LISTEN_CLIENT_URLS="http://172.16.160.206:2379,http://127.0.0.1:2379"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.160.206:2380"

ETCD_INITIAL_CLUSTER="etcdmaster=http://172.16.160.205:2380,etcdnode1=http://172.16.160.206:2380,etcdnode2=http://172.16.160.207:2380"

ETCD_INITIAL_CLUSTER_STATE="new"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-00"

ETCD_ADVERTISE_CLIENT_URLS="http://172.16.160.206:2379"

[root@k8snode2 softs]# vi /etc/etcd/etcd.conf

ETCD_NAME=etcdnode2

ETCD_DATA_DIR="/var/lib/etcd/etcd-master.etcd"

ETCD_LISTEN_PEER_URLS="http://172.16.160.207:2380"

ETCD_LISTEN_CLIENT_URLS="http://172.16.160.207:2379,http://127.0.0.1:2379"

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.160.207:2380"

ETCD_INITIAL_CLUSTER="etcdmaster=http://172.16.160.205:2380,etcdnode1=http://172.16.160.206:2380,etcdnode2=http://172.16.160.207:2380"

ETCD_INITIAL_CLUSTER_STATE="new"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-00"

ETCD_ADVERTISE_CLIENT_URLS="http://172.16.160.207:2379"

启动服务文件/usr/lib/systemd/system/etcd.service一般不修改也行,注意ExecStart后的参数

[root@all softs]# mv /usr/lib/systemd/system/etcd.service  /usr/lib/systemd/system/etcd.service.bak

[root@all softs]# vi /usr/lib/systemd/system/etcd.service

[Unit]

Description=Etcd Server

After=network.target

After=network-online.target

Wants=network-online.target

[Service]

Type=notify

WorkingDirectory=/var/lib/etcd/

EnvironmentFile=-/etc/etcd/etcd.conf

User=etcd

ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" \

--data-dir=\"${ETCD_DATA_DIR}\" \

--listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" \

--listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" \

--advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\" \

--initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\" \

--initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" \

--initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\""

Restart=on-failure

LimitNOFILE=65536

[Install]

WantedBy=multi-user.target

三台服务器全部运行并测试:

[root@all softs]# systemctl enable etcd && systemctl restart etcd && systemctl status etcd

[root@k8snode2 softs]#

查看etcd成员列表,可以看出172.16.160.205现在是leader,可以试着关闭第一台的etcd服务,领导角色会变成另外一台。

[root@all softs]# etcdctl member list

48e928c68a0c1cd6: name=etcdmaster peerURLs=http://172.16.160.205:2380 clientURLs=http://172.16.160.205:2379 isLeader=true

7eccc73b94e5aaea: name=etcdnode2 peerURLs=http://172.16.160.207:2380 clientURLs=http://172.16.160.207:2379 isLeader=false

d7378dd58f633a96: name=etcdnode1 peerURLs=http://172.16.160.206:2380 clientURLs=http://172.16.160.206:2379 isLeader=false

[root@k8smaster softs]#

查看etcd的健康情况,是否存活。

[root@all softs]# etcdctl cluster-health

member 48e928c68a0c1cd6 is healthy: got healthy result from http://172.16.160.205:2379

member 7eccc73b94e5aaea is healthy: got healthy result from http://172.16.160.207:2379

member d7378dd58f633a96 is healthy: got healthy result from http://172.16.160.206:2379

cluster is healthy

[root@k8smaster softs]#

[root@all softs]# curl -L http://172.16.160.205:2379/version

{"etcdserver":"3.0.15","etcdcluster":"3.0.0"}

[root@all softs]# curl -L http://172.16.160.206:2379/version

{"etcdserver":"3.0.15","etcdcluster":"3.0.0"}

[root@all softs]# curl -L http://172.16.160.207:2379/version

{"etcdserver":"3.0.15","etcdcluster":"3.0.0"}

旧的文档一般是使用4012端口,新版本使用2379端口作为监听端口

删除节点命令:etcdctl member remove XXXXXXXX

添加节点命令:etcdctl member add k8snode2 http://172.16.160.208:2380

ETCD_DATA_DIR="/var/lib/etcd/etcd-master.etcd" ETCD数据存放目录,卸载ETCD时,也要删除。

查看etcd版本信息:

[root@k8snode2 etcd-master.etcd]# etcdctl --version

etcdctl version: 3.0.15

API version: 2

[root@k8snode2 etcd-master.etcd]#

相关文章

网友评论

      本文标题:在CentOS7上部署ETCD集群

      本文链接:https://www.haomeiwen.com/subject/jdrrgttx.html