ETCD集群环境搭建

软件安装环境
软件版本及安装路径
编号 软件 版本信息 安装路径 备注
1 etcd etcd.x86_64.0.3.2.22-1.el7 Yum 缺省路径

ETCD安装及配置
a) 首先下载国内的YUM源 (三台机均进行下载)
[root@localhost~]#curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 –:–:– 62 2523 62 1565 0 0 4609 0 –:–:– 100 2523 100 2523 0 0 7396 0 –:–:– –:–:– –:–:– 7398

b) 安装ETCD (三台机均进行安装)
[root@localhost ~]# yum install etcd -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
正在解决依赖关系
–> 正在检查事务
—> 软件包 etcd.x86_64.0.3.2.22-1.el7 将被 安装
–> 解决依赖关系完成

c) 配置ETCD服务器
ETCD1:配置文件的修改
Vim /etc/etcd/etcd.conf
ETCD_NAME=etcd1 #实例名称
ETCD_DATA_DIR=”/var/lib/etcd/etcd1″ #数据保存目录
ETCD_ADVERTISE_CLIENT_URLS=”http://192.168.21.223:2379,http://lcoalhost:2379″ #广播给外部客户端使用的url
ETCD_LISTEN_CLIENT_URLS=”http://192.168.21.223:2379,http://localhost:2379″ #供外部客户端使用的url
ETCD_LISTEN_PEER_URLS=”http://192.168.21.223:2380″ #集群内部通信使用的URL
ETCD_INITIAL_ADVERTISE_PEER_URLS=”http://192.168.21.223:2380″ #广播给集群内其他成员访问的URL
ETCD_INITIAL_CLUSTER=”etcd1=http://192.168.21.223:2380,etcd2=http://192.168.21.208:2380,etcd3=http://192.168.21.219:2380″ #初始集群成员列表
ETCD_INITIAL_CLUSTER_STATE=”new” #初始集群状态,new为新建集群,exist为加入集群
ETCD_INITIAL_CLUSTER_TOKEN=”etcd-cluster” #集群的名称

ETCD2配置文件的修改
ETCD_NAME=etcd2
ETCD_DATA_DIR=”/var/lib/etcd/etcd2″
ETCD_ADVERTISE_CLIENT_URLS=”http://192.168.21.208:2379,http://lcoalhost:2379″
ETCD_LISTEN_CLIENT_URLS=”http://192.168.21.208:2379,http://localhost:2379″
ETCD_LISTEN_PEER_URLS=”http://192.168.21.208:2380″
ETCD_INITIAL_ADVERTISE_PEER_URLS=”http://192.168.21.208:2380″
ETCD_INITIAL_CLUSTER=”etcd1=http://192.168.21.223:2380,etcd2=http://192.168.21.208:2380,etcd3=http://192.168.21.219:2380″
ETCD_INITIAL_CLUSTER_STATE=”new”
ETCD_INITIAL_CLUSTER_TOKEN=”etcd-cluster”

ETCD3配置文件的修改
ETCD_NAME=etcd3
ETCD_DATA_DIR=”/var/lib/etcd/etcd3″
ETCD_ADVERTISE_CLIENT_URLS=”http://192.168.21.219:2379,http://lcoalhost:2379″
ETCD_LISTEN_CLIENT_URLS=”http://192.168.21.219:2379,http://localhost:2379″
ETCD_LISTEN_PEER_URLS=”http://192.168.21.219:2380″
ETCD_INITIAL_ADVERTISE_PEER_URLS=”http://192.168.21.219:2380″
ETCD_INITIAL_CLUSTER=”etcd1=http://192.168.21.223:2380,etcd2=http://192.168.21.208:2380,etcd3=http://192.168.21.219:2380″
ETCD_INITIAL_CLUSTER_STATE=”new”
ETCD_INITIAL_CLUSTER_TOKEN=”etcd-cluster”

d) 启动服务文件的修改 (三台修改均如下红色部分)
vim /usr/lib/systemd/system/etcd.service
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c “GOMAXPROCS=$(nproc) /usr/bin/etcd –name=\”${ETCD_NAME}\” –data-dir=\”${ETCD_DATA_DIR}\” –listen-client-urls=\”${ETCD_LISTEN_CLIENT_URLS}\” –listen-peer-urls=\”${ETCD_LISTEN_PEER_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}\””

ETCD的启动
当三台机相关配置完成后,进行服务的启动(在三台机器上均执行如下命令进行启动,注意单台机器配置好后启动会超时失败,因为无法发现集群中其它服务器)
systemctl daemon-reload ##重新加载服务的配置
systemctl start etcd ##启动etcd
systemctl enable etcd ##开机自启

ETCD状态检测
#检测集群机器列
[root@localhost ~]# etcdctl member list
399599b1d3660a81: name=etcd2 peerURLs=http://192.168.21.208:2380 clientURLs=http://192.168.21.208:2379,http://lcoalhost:2379 isLeader=false
9c88ced26ca4494c: name=etcd3 peerURLs=http://192.168.21.219:2380 clientURLs=http://192.168.21.219:2379,http://lcoalhost:2379 isLeader=false
d3f70fadd825c216: name=etcd1 peerURLs=http://192.168.21.223:2380 clientURLs=http://192.168.21.223:2379,http://lcoalhost:2379 isLeader=true
#检测集群机器健康状态
[root@localhost ~]# etcdctl cluster-health
member 399599b1d3660a81 is healthy: got healthy result from http://192.168.21.208:2379
member 9c88ced26ca4494c is healthy: got healthy result from http://192.168.21.219:2379
member d3f70fadd825c216 is healthy: got healthy result from http://192.168.21.223:2379
cluster is healthy

常见问题
如遇到ETCD启动超时,如下:
Redirecting to /bin/systemctl restart etcd.service
Job for etcd.service failed because a timeout was exceeded. See “systemctl status etcd.service” and “journalctl -xe” for details.
是由于集群中其它机器没有启动导致。所以最好多台机器配置完成后,一起启动。以避免超时。

如遇无法启动报错的情况,如下:
[root@localhost system]# service etcd restart
Redirecting to /bin/systemctl restart etcd.service
Warning: etcd.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
Job for etcd.service failed because the control process exited with error code. See “systemctl status etcd.service” and “journalctl -xe” for details.
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# service etcd restart
Redirecting to /bin/systemctl restart etcd.service
Job for etcd.service failed because the control process exited with error code. See “systemctl status etcd.service” and “journalctl -xe” for details.
[root@localhost system]# journalctl -xe
12月 05 22:06:47 localhost.localdomain etcd[27684]: listening for client requests on localhost:2379
12月 05 22:06:47 localhost.localdomain etcd[27684]: couldn’t find local name “etcd1 #实例名称” in the initial cluster configuration
12月 05 22:06:47 localhost.localdomain systemd[1]: etcd.service: main process exited, code=exited, status=1/FAILURE
12月 05 22:06:47 localhost.localdomain systemd[1]: Failed to start Etcd Server.
— Subject: Unit etcd.service has failed
— Defined-By: systemd
— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

是由于/etc/etcd/etcd.conf中配置有误导致

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>