etcd集群的部署
admin
2023-03-16 13:41:09
0
node1  192.168.56.173
node2 192.168.56.174
node3 192.168.56.200
node* 为主机名称
[root@node1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@node1 ~]#


https://github.com/coreos/etcd/releases/download/v3.0.15/etcd-v3.0.15-linux-amd64.tar.gz 
tar xf  etcd-v3.0.15-linux-amd64.tar.gz 
cd etcd-v3.0.15-linux-amd64 
cp etcd  /usr/bin/
cp etcdctl /usr/bin/

192.168.56.173(node1)

cat  /etc/systemd/system/etcd2.service

[Unit]
Description=etcd2.service
[Service]
Type=notify
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/mkdir -p /data/etcd2
ExecStart=/usr/bin/etcd \
  --data-dir /data/etcd2 \
  --name etcd0 \
  --advertise-client-urls http://192.168.56.173:2379,http://192.168.56.173:4001 \
  --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
  --initial-advertise-peer-urls http://192.168.56.173:2380 \
  --listen-peer-urls http://0.0.0.0:2380 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster etcd0=http://192.168.56.173:2380,etcd1=http://192.168.56.174:2380,etcd2=http://192.168.56.200:2380
[Install]
WantedBy=multi-user.target
# 设置服务自启动
systemctl enable /etc/systemd/system/etcd2.service
# 启动etcd1  (先不要做 三个节点都部署完毕 在分别启动 否则启动会hang)
systemctl restart etcd2.service

192.168.56.174(node2)

[root@node2 ~]# cat  /etc/systemd/system/etcd2.service 

[Unit]
Description=etcd2.service
[Service]
Type=notify
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/mkdir -p /data/etcd2
ExecStart=/usr/bin/etcd \
  --data-dir /data/etcd2 \
  --name etcd1 \
  --advertise-client-urls http://192.168.56.174:2379,http://192.168.56.174:4001 \
  --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
  --initial-advertise-peer-urls http://192.168.56.174:2380 \
  --listen-peer-urls http://0.0.0.0:2380 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster etcd0=http://192.168.56.173:2380,etcd1=http://192.168.56.174:2380,etcd2=http://192.168.56.200:2380
[Install]
WantedBy=multi-user.target
# 设置服务自启动
systemctl enable /etc/systemd/system/etcd2.service
# 启动etcd2  (先不要做 三个节点都部署完毕 在分别启动 否则启动会hang)
systemctl restart etcd2.service

192.168.56.200(node2)

[root@node3~]# cat  /etc/systemd/system/etcd2.service 

[root@node3 ~]# cat  /etc/systemd/system/etcd2.service 
[Unit]
Description=etcd2.service
[Service]
Type=notify
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/mkdir -p /data/etcd2
ExecStart=/usr/bin/etcd \
  --data-dir /data/etcd2 \
  --name etcd2 \
  --advertise-client-urls http://192.168.56.200:2379,http://192.168.56.200:4001 \
  --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
  --initial-advertise-peer-urls http://192.168.56.200:2380 \
  --listen-peer-urls http://0.0.0.0:2380 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster etcd0=http://192.168.56.173:2380,etcd1=http://192.168.56.174:2380,etcd2=http://192.168.56.200:2380
[Install]
WantedBy=multi-user.target
# 设置服务自启动
systemctl enable /etc/systemd/system/etcd2.service
# 启动etcd3  (先不要做 三个节点都部署完毕 在分别启动 否则启动会hang)
systemctl restart etcd2.service

备注:启动的方式一个一个启动 否则systemctl  restart   etcd2.service 会hang住


查看状态 

[root@node3 ~]# systemctl  status etcd2.service 
● etcd2.service
   Loaded: loaded (/etc/systemd/system/etcd2.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-09-02 23:43:59 CST; 10min ago
  Process: 2673 ExecStartPre=/usr/bin/mkdir -p /data/etcd2 (code=exited, status=0/SUCCESS)
 Main PID: 2675 (etcd)
   CGroup: /system.slice/etcd2.service
           └─2675 /usr/bin/etcd --data-dir /data/etcd2 --name etcd2 --advertise-client-urls http://192.168.56.200:2379,http://192.168.56.200:4001 --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001...

Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer e37f661be0f0e44a (stream Message reader)
Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer 161efc88633d5fd4 (stream MsgApp v2 reader)
Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer 161efc88633d5fd4 (stream Message reader)
Sep 02 23:44:45 node3 etcd[2675]: closed an existing TCP streaming connection with peer 161efc88633d5fd4 (stream Message writer)
Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer 161efc88633d5fd4 (stream Message writer)
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea [term: 25] received a MsgVote message with higher term from e37f661be0f0e44a [term: 26]
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea became follower at term 26
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea [logterm: 20, index: 623, vote: 0] voted for e37f661be0f0e44a [logterm: 20, index: 623] at term 26
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea [term: 26] ignored a MsgVote message with lower term from 161efc88633d5fd4 [term: 24]
Sep 02 23:44:46 node3 etcd[2675]: raft.node: 52aafe548d51c9ea elected leader e37f661be0f0e44a at term 26
[root@node3 ~]#
[root@node3 ~]# netstat  -lntup 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      869/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1132/master         
tcp6       0      0 :::2379                 :::*                    LISTEN      2675/etcd           
tcp6       0      0 :::2380                 :::*                    LISTEN      2675/etcd           
tcp6       0      0 :::22                   :::*                    LISTEN      869/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1132/master         
tcp6       0      0 :::4001                 :::*                    LISTEN      2675/etcd           
[root@node3 ~]#

查看相关主体的状态

[root@node1 etcd-v3.0.15-linux-amd64]# etcdctl member list
161efc88633d5fd4: name=etcd0 peerURLs=http://192.168.56.173:2380 clientURLs=http://192.168.56.173:2379,http://192.168.56.173:4001 isLeader=false
52aafe548d51c9ea: name=etcd2 peerURLs=http://192.168.56.200:2380 clientURLs=http://192.168.56.200:2379,http://192.168.56.200:4001 isLeader=false
e37f661be0f0e44a: name=etcd1 peerURLs=http://192.168.56.174:2380 clientURLs=http://192.168.56.174:2379,http://192.168.56.174:4001 isLeader=true
[root@node1 etcd-v3.0.15-linux-amd64]#

集群的状态监控(可以结合zabbix做监控)

[root@node1 etcd-v3.0.15-linux-amd64]# etcdctl cluster-health
member 161efc88633d5fd4 is healthy: got healthy result from http://192.168.56.173:2379
member 52aafe548d51c9ea is healthy: got healthy result from http://192.168.56.200:2379
member e37f661be0f0e44a is healthy: got healthy result from http://192.168.56.174:2379
cluster is healthy
[root@node1 etcd-v3.0.15-linux-amd64]#

etcd基本操作

[root@node1 ~]# etcdctl set testkey "hello world"
hello world
[root@node1 ~]# etcdctl   get  testkey 
hello world
[root@node1 ~]# curl -L http://localhost:2379/v2/keys/testkey
{"action":"get","node":{"key":"/testkey","value":"hello world","modifiedIndex":11,"createdIndex":11}}
[root@node1 ~]# curl -L http://192.168.56.173:2379/v2/keys/testkey
{"action":"get","node":{"key":"/testkey","value":"hello world","modifiedIndex":11,"createdIndex":11}}
[root@node1 ~]#


相关内容

热门资讯

ICC逮捕令致内塔尼亚胡出行受... 【环球网报道】据以色列《新消息报》网站26日报道,由于国际刑事法院(ICC)2024年就以色列在巴勒...
“罗永浩怒斥电视机厂商”戳中了... 7月25日晚,罗永浩发文怒斥当下电视机的产品设计。据都市快报报道,罗永浩表示,他为家中老人换了两次电...
各地各部门坚持人民至上筑牢防汛... 新华社北京7月25日电 题:风雨同舟映初心——各地各部门坚持人民至上筑牢防汛抗洪坚实堤坝新华社记者当...
法院回应LV起诉地产开发商 7月26日,厦门市湖里区人民法院发布情况通报,网传案情“路易威登公司起诉地产开发商,因楼盘外立面四叶...
携程的问题不仅在于垄断,更在于... 国内平台科技企业一般都是通过向B端收费、抽佣获利,尽量给消费者创造一个比较清爽的使用环境。携程算是最...
海信电视用遥控器关闭后打不开 原因可能是遥控器的电池没有装好或者是没电了,需要重新安装一下电池或者更换新的电池试一试;原因可能是电...
电视机突然没电源打不开了 有可能是电视开关的电源线断了;可能是电视在使用时短路;可能是电源插头插座松动;可能是电视内部零件接触...
电热水器下面那个小龙头漏水是怎... 电热水器下面那个小龙头漏水是怎么回事?1、因为安全阀发生了故障或者是已经被损坏了,就会有漏水的现象;...
回答下电脑桌面一片空白怎么恢复 电脑桌面上如果是一片空白,那说明您的电脑图标被隐藏了,想要恢复就要按照如下的三个步骤去操作才行。 第...
澳总理要找特朗普“理论”关税:... 当地时间7月26日,澳大利亚总理阿尔巴尼斯表示,他将直接向美国总统特朗普提出抗议,反对美国新近宣布的...