etcd集群安装和维护

yum install -y etcd

如果之前安装过etcd,停掉etcd服务并,清理持久化目录,默认目录在/var/lib/etcd/default.etcd

停止方法:systemctl stop etcd

数据清理方法: mv /var/lib/etcd/default.etcd /var/lib/etcd/default.etcd.bak

1、修改配置文件vi /etc/etcd/etcd.conf

配置文件如下,绿色部分IP需要修改,以172.28.73.54172.28.73.40172.28.16.153为例

172.28.73.54配置

ETCD_NAME="node1"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_PEER_URLS="http://172.28.73.54:2380"

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

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.28.73.54:2380"

ETCD_ADVERTISE_CLIENT_URLS="http://172.28.73.54:2379"

ETCD_INITIAL_CLUSTER="node1=http://172.28.73.54:2380,node2=http://172.28.73.40:2380,node3=http://172.28.16.153:2380"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_INITIAL_CLUSTER_STATE="new"

172.28.73.40配置

ETCD_NAME="node2"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_PEER_URLS="http://172.28.73.40:2380"

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

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.28.73.40:2380"

ETCD_ADVERTISE_CLIENT_URLS="http://172.28.73.40:2379"

ETCD_INITIAL_CLUSTER="node1=http://172.28.73.54:2380,node2=http://172.28.73.40:2380,node3=http://172.28.16.153:2380"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_INITIAL_CLUSTER_STATE="new"

172.28.16.53配置

ETCD_NAME="node3"

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_PEER_URLS="http://172.28.16.153:2380"

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

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.28.16.153:2380"

ETCD_ADVERTISE_CLIENT_URLS="http://172.28.16.153:2379"

ETCD_INITIAL_CLUSTER="node1=http://172.28.73.54:2380,node2=http://172.28.73.40:2380,node3=http://172.28.16.153:2380"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_INITIAL_CLUSTER_STATE="new"

2、每台服务器修改etcd系统启动文件

vi /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

3、启动

依次启动etcd服务

systemclt start etcdctl

4、验证

查看成员

etcdctl member list

每个节点上执行查看健康状态

etcdctl cluster-health

在任意一个节点etcdctl  set  /test  "hello etcd"

在另一个几点 etcdctl  get  /test 能看到数据则正常

相关推荐