centos7部署etcd集群

Posted caidingyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7部署etcd集群相关的知识,希望对你有一定的参考价值。

实验环境:centos7.4纯净版

192.168.216.130 node1 master

192.168.216.132 node2 slave

192.168.216.134 node3 slave

yum安装etcd

yum install etcd 
yum list installed |grep -i etcd

技术图片

node1 etcd 配置

cp /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak
cd /etc/etcd/
[root@localhost etcd]# egrep ^[A-Z] ./etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/node1.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.216.130:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.216.130:2379,http://127.0.0.1:2379"
ETCD_NAME="node1"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.216.130:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.216.130:2379"
ETCD_INITIAL_CLUSTER="node1=http://192.168.216.130:2380,node2=http://192.168.216.132:2380,node3=http://192.168.216.134:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

node2 etcd 配置

cp /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak
cd /etc/etcd/
[root@localhost etcd]# egrep ^[A-Z] ./etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/node2.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.216.132:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.216.132:2379,http://127.0.0.1:2379"
ETCD_NAME="node2"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.216.132:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.216.132:2379"
ETCD_INITIAL_CLUSTER="node1=http://192.168.216.130:2380,node2=http://192.168.216.132:2380,node3=http://192.168.216.134:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

node3 etcd 配置

cp /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak
cd /etc/etcd/
[root@localhost etcd]# egrep ^[A-Z] ./etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/node3.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.216.134:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.216.134:2379,http://127.0.0.1:2379"
ETCD_NAME="node3"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.216.134:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.216.134:2379"
ETCD_INITIAL_CLUSTER="node1=http://192.168.216.130:2380,node2=http://192.168.216.132:2380,node3=http://192.168.216.134:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

  

修改 etcd.service

[root@localhost etcd]# cat /usr/lib/systemd/system/etcd.service
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=etcd
# set GOMAXPROCS to number of processors
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\\" --initial-advertise-peer-urls=\\"$ETCD_INITIAL_ADVERTISE_PEER_URLS\\" --advertise-client-urls=\\"$ETCD_ADVERTISE_CLIENT_URLS\\" --initial-cluster=\\"$ETCD_INITIAL_CLUSTER\\"  --initial-cluster-token=\\"$ETCD_INITIAL_CLUSTER_TOKEN\\" --initial-cluster-state=\\"$ETCD_INITIAL_CLUSTER_STATE\\""
Restart=on-failure
LimitNOFILE=65536

以上操作在 node1、node2、node3 节点上都需要操作,需要修改对应的ip

启动 etcd

依次启动 node1、node2、node3 节点的 etcd

systemctl start etcd.service
systemctl status etcd.service
systemctl enable etcd.service

验证 etcd

etcdctl cluster-health

技术图片

etcdctl member list

技术图片

各个节点配置crontab 定时同步时间,否则可能会出现node1 etcd[1657]: the clock difference against peer f63afbe816fb463d is too hig问题

yum install ntp
crontab -e
0 1 * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn >> /var/log/ntpdate.log 2>&1 &

  

 

以上是关于centos7部署etcd集群的主要内容,如果未能解决你的问题,请参考以下文章

centos7部署postgresql集群高可用 patroni + etcd 之patroni篇

2etcd单机部署和集群部署

金庸武功之“七伤拳”--etcd集群搭建

ETCD 集群部署

基于已有集群动态发现方式部署 Etcd 集群

kubernetes容器集群部署Etcd集群