系统相关
首页 > 系统相关> > Etcd在Linux CentOS7 集群配置 (多台电脑机实现)

Etcd在Linux CentOS7 集群配置 (多台电脑机实现)

作者:互联网

环境:

Node0节点IP:192.168.200.132

Node1节点IP:192.168.200.133

Node2节点IP:192.168.200.134

将Etcd服务端布置到上面3台机器上,集群和每个节点都会生成一个uuid。启动的时候会运行Raft,选举出Leader。

 

防火墙端口,开放 2379、2380、4001,显示success表示创建成功

[root@Cent0S7]# firewall-cmd --zone=public --add-port=2379/tcp --permanent     
success
[root@Cent0S7]# firewall-cmd --zone=public --add-port=2380/tcp --permanent     
success
[root@Cent0S7]# firewall-cmd --zone=public --add-port=4001/tcp --permanent
success

    

Node0节点,将下面配置内容加入之前创建的/etc/etcd.conf 配置文件中。

#节点名称
ETCD_NAME=etcd
#缓存数据存放位置
ETCD_DATA_DIR=/var/lib/etcd/
ETCD_LISTEN_PEER_URLS="http://192.168.200.132:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.200.132:2379"
#[cluster]
ETCD_HEARTBEAT_INTERVAL="200"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.200.132:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.200.132:2379,http://192.168.200.132:4001"
ETCD_INITIAL_CLUSTER="etcd=http://192.168.200.132:2380,etcd1=http://192.168.200.133:2380,etcd2=http://192.168.200.134:2380"

 

Node1节点将下面配置内容加入之前创建的/etc/etcd.conf 配置文件中。

#节点名称
ETCD_NAME=etcd1
#缓存数据存放位置
ETCD_DATA_DIR=/var/lib/etcd/
ETCD_LISTEN_PEER_URLS="http://192.168.200.133:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.200.133:2379"
#[cluster]
ETCD_HEARTBEAT_INTERVAL="200"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.200.133:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.200.133:2379,http://192.168.200.133:4001"
ETCD_INITIAL_CLUSTER="etcd=http://192.168.200.132:2380,etcd1=http://192.168.200.133:2380,etcd2=http://192.168.200.134:2380"

 

Node2节点将下面配置内容加入之前创建的/etc/etcd.conf 配置文件中。

#节点名称
ETCD_NAME=etcd2
#缓存数据存放位置
ETCD_DATA_DIR=/var/lib/etcd/
ETCD_LISTEN_PEER_URLS="http://192.168.200.134:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.200.134:2379"
#[cluster]
ETCD_HEARTBEAT_INTERVAL="200"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.200.134:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.200.134:2379,http://192.168.200.134:4001"
ETCD_INITIAL_CLUSTER="etcd=http://192.168.200.132:2380,etcd1=http://192.168.200.133:2380,etcd2=http://192.168.200.134:2380"

  

Node0、Node1、Node2节点守护进程  /etc/systemd/system/etcd.service配置

[Unit]
Description=Etcd Server
Documentation=https://github.com/coreos/etcd
After=network.target

[Service]
User=root
Type=notify
EnvironmentFile=/etc/etcd.conf
ExecStart=/usr/local/sbin/etcd
Restart=on-failure
RestartSec=10s
LimitNOFILE=40000

[Install]
WantedBy=multi-user.target

PS:修改配置后,要删除缓存,默认是用之前的缓存启动。

 

删除缓存文件夹

[root@Cent0S7 ~]# rm -rf /var/lib/etcd/
[root@Cent0S7 ~]# mkdir -p /var/lib/etcd/

 

刷新配置

[root@Cent0S7 ~]#  systemctl daemon-reload

 

Node0、Node1、Node2节点,分别执行下面命令启动

[root@Cent0S7 ~]# systemctl start etcd.service

PS:启动时光标一直闪,也没报错,因为其他节点还没启动,所以在查找,不用管,多开几个SecureCRT的Shell窗口启动每个service就可以了。

 

 验证:在任意一台node上执行都能看到所有member信息

[root@Cent0S7 ]# etcdctl -w="table" --endpoints=192.168.200.132:2379 member list 
+------------------+---------+-------+-----------------------------+---------------------------------------------------------+
|        ID        | STATUS  | NAME  |         PEER ADDRS          |                      CLIENT ADDRS                       |
+------------------+---------+-------+-----------------------------+---------------------------------------------------------+
| 724a7b614cfa065  | started | etcd1 | http://192.168.200.133:2380 | http://192.168.200.133:2379,http://192.168.200.133:4001 |
| 171955058e9a4708 | started | etcd2 | http://192.168.200.134:2380 | http://192.168.200.134:2379,http://192.168.200.134:4001 |
| 3942148265deeadf | started | etcd  | http://192.168.200.132:2380 | http://192.168.200.132:2379,http://192.168.200.132:4001 |
+------------------+---------+-------+-----------------------------+---------------------------------------------------------+

[root@Cent0S7 ]# etcdctl --write-out=table --endpoints=192.168.200.132:2379,192.168.200.133:2379,192.168.200.134:2379 endpoint status +----------------------+------------------+---------+---------+-----------+-----------+------------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX | +----------------------+------------------+---------+---------+-----------+-----------+------------+ | 192.168.200.132:2379 | 3942148265deeadf | 3.1.5 | 25 kB | false | 176 | 10 | | 192.168.200.133:2379 | 724a7b614cfa065 | 3.1.5 | 25 kB | true | 176 | 10 | | 192.168.200.134:2379 | 171955058e9a4708 | 3.1.5 | 25 kB | false | 176 | 10 | +----------------------+------------------+---------+---------+-----------+-----------+------------+

  

标签:http,Etcd,192.168,CentOS7,2380,etcd,2379,ETCD,Linux
来源: https://www.cnblogs.com/wutou/p/14065723.html