Etcd Cluster配置
- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
環境:
host1(docker1):172.16.199.17/24
主機2(docker2):172.16.199.27/24
host3上(docker2):172.16.199.37/24
目的:
配置ETCD集群服務,為後續絨布網絡及kubernetes(K8S)集群提供基礎服務
配置步驟:
主機1安裝配置:
下載ETCD服務(當前版本V3.2.1)
1
|
wget https://github.com/coreos/etcd/releases/download/v3.2.1/etcd-v3.2.1-linux-amd64.tar.gz
|
下載完畢後,解壓,將ETCD及etcdctl文件拷貝到PATH可以搜索到的目錄,例如在/ usr / bin中
進入systmed的服務目錄,創建etcd服務使得以後可以通過systemd託管服務啟動
1
|
[root@docker1 etcd-v3.2.1-linux-amd64]# cd /usr/lib/systemd/system/
|
創建名為etcd.service文件,內容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
User=root
# 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}\" "
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
|
創建/ var / lib / etcd目錄
創建/etc/etcd/etcd.conf目錄及文件,文件內容如下:
1
2
3
4
5
6
7
8
9
|
ETCD_NAME="etcd01"
ETCD_DATA_DIR="/var/lib/etcd/etcd01"
ETCD_LISTEN_PEER_URLS="http://172.16.199.17:2380"
ETCD_LISTEN_CLIENT_URLS="http://172.16.199.17:2379,http://127.0.0.1:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.199.17:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://172.16.199.17:2379"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster1"
ETCD_INITIAL_CLUSTER="etcd01=http://172.16.199.17:2380,etcd02=http://172.16.199.27:2380"
|
主機2安裝配置:
方法同主機1,在etcd.conf配置文件中將ETCD_NAME,DIR以及相關IP修改為etcd02和172.16.199.27,TOKEN保持不變
啟動ETCD服務:
在兩台主機上分別執行
systemctl守護進程重新加載
systemctl啟動etcd.service
檢查在/ var / log / messages中,以及systemctl命令本身無錯誤輸出
systemctl啟用etcd.service
檢驗集群服務:
1
2
3
4
5
6
7
8
|
[root@docker1 system]# etcdctl cluster-health
member 63e5296d334e3fa is healthy: got healthy result from http://172.16.199.17:2379
member 9558b2437a9b849a is healthy: got healthy result from http://172.16.199.27:2379
[root@docker1 system]# etcdctl member list
63e5296d334e3fa: name=etcd01 peerURLs=http://172.16.199.17:2380 clientURLs=http://172.16.199.17:2379 isLeader=true
9558b2437a9b849a: name=etcd02 peerURLs=http://172.16.199.27:2380 clientURLs=http://172.16.199.27:2379 isLeader=false
[root@docker1 system]# etcdctl cluster heath
|
1
2
3
4
5
6
7
|
[root@docker2 etcd-v3.2.1-linux-amd64]# etcdctl cluster-health
member 63e5296d334e3fa is healthy: got healthy result from http://172.16.199.17:2379
member 9558b2437a9b849a is healthy: got healthy result from http://172.16.199.27:2379
cluster is healthy
[root@docker2 etcd-v3.2.1-linux-amd64]# etcdctl member list
63e5296d334e3fa: name=etcd01 peerURLs=http://172.16.199.17:2380 clientURLs=http://172.16.199.17:2379 isLeader=true
9558b2437a9b849a: name=etcd02 peerURLs=http://172.16.199.27:2380 clientURLs=http://172.16.199.27:2379 isLeader=false
|
測試ETCD:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@docker1 system]# etcdctl mkdir /testdir
[root@docker1 system]# etcdctl ls
/testdir
[root@docker1 system]# etcdctl set /testdir/key1 value1
value1
[root@docker1 system]# etcdctl get /testdir/key1
value1
[root@docker1 system]# etcdctl -o extended get /testdir/key1
Key: /testdir/key1
Created-Index: 7
Modified-Index: 7
TTL: 0
Index: 7
value1
[root@docker1 system]# etcdctl ls --recursive
/testdir
/testdir/key1
|
1
2
3
4
5
6
7
8
|
[root@docker2 member]# etcdctl ls
/testdir
[root@docker2 member]# etcdctl ls --recursive
/testdir
/testdir/key1
[root@docker2 member]# etcdctl get /testdir/key1
value1
|
集群冗餘測試:
停止host1 etcd服務,host2無法選舉成為領導,這是因為etcd集群實際上至少需要三個節點:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
[root@docker2 member]# tail -f /var/log/messages
Jun 27 21:44:45 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 430
Jun 27 21:44:46 docker2 etcd: 9558b2437a9b849a is starting a new election at term 430
Jun 27 21:44:46 docker2 etcd: 9558b2437a9b849a became candidate at term 431
Jun 27 21:44:46 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 431
Jun 27 21:44:46 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 431
Jun 27 21:44:47 docker2 etcd: health check for peer 63e5296d334e3fa could not connect: dial tcp 172.16.199.17:2380: getsockopt: connection refused
Jun 27 21:44:48 docker2 etcd: 9558b2437a9b849a is starting a new election at term 431
Jun 27 21:44:48 docker2 etcd: 9558b2437a9b849a became candidate at term 432
Jun 27 21:44:48 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 432
Jun 27 21:44:48 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 432
Jun 27 21:44:49 docker2 etcd: 9558b2437a9b849a is starting a new election at term 432
Jun 27 21:44:49 docker2 etcd: 9558b2437a9b849a became candidate at term 433
Jun 27 21:44:49 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 433
Jun 27 21:44:49 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 433
Jun 27 21:44:51 docker2 etcd: 9558b2437a9b849a is starting a new election at term 433
Jun 27 21:44:51 docker2 etcd: 9558b2437a9b849a became candidate at term 434
Jun 27 21:44:51 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 434
Jun 27 21:44:51 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 434
Jun 27 21:44:52 docker2 etcd: health check for peer 63e5296d334e3fa could not connect: dial tcp 172.16.199.17:2380: getsockopt: connection refused
Jun 27 21:44:52 docker2 etcd: 9558b2437a9b849a is starting a new election at term 434
Jun 27 21:44:52 docker2 etcd: 9558b2437a9b849a became candidate at term 435
Jun 27 21:44:52 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 435
Jun 27 21:44:52 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 435
Jun 27 21:44:54 docker2 etcd: 9558b2437a9b849a is starting a new election at term 435
Jun 27 21:44:54 docker2 etcd: 9558b2437a9b849a became candidate at term 436
Jun 27 21:44:54 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 436
Jun 27 21:44:54 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 436
Jun 27 21:44:55 docker2 etcd: 9558b2437a9b849a is starting a new election at term 436
Jun 27 21:44:55 docker2 etcd: 9558b2437a9b849a became candidate at term 437
Jun 27 21:44:55 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 437
Jun 27 21:44:55 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 437
Jun 27 21:44:56 docker2 etcd: 9558b2437a9b849a is starting a new election at term 437
Jun 27 21:44:56 docker2 etcd: 9558b2437a9b849a became candidate at term 438
Jun 27 21:44:56 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 438
Jun 27 21:44:56 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 438
Jun 27 21:44:57 docker2 etcd: health check for peer 63e5296d334e3fa could not connect: dial tcp 172.16.199.17:2380: getsockopt: connection refused
Jun 27 21:44:57 docker2 etcd: 9558b2437a9b849a is starting a new election at term 438
Jun 27 21:44:57 docker2 etcd: 9558b2437a9b849a became candidate at term 439
Jun 27 21:44:57 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 439
Jun 27 21:44:57 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 439
Jun 27 21:44:58 docker2 etcd: 9558b2437a9b849a is starting a new election at term 439
Jun 27 21:44:58 docker2 etcd: 9558b2437a9b849a became candidate at term 440
Jun 27 21:44:58 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 440
Jun 27 21:44:58 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 440
Jun 27 21:44:59 docker2 etcd: 9558b2437a9b849a is starting a new election at term 440
Jun 27 21:44:59 docker2 etcd: 9558b2437a9b849a became candidate at term 441
Jun 27 21:44:59 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 441
Jun 27 21:44:59 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 441
Jun 27 21:45:01 docker2 etcd: 9558b2437a9b849a is starting a new election at term 441
Jun 27 21:45:01 docker2 etcd: 9558b2437a9b849a became candidate at term 442
Jun 27 21:45:01 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 442
Jun 27 21:45:01 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 442
Jun 27 21:45:02 docker2 etcd: health check for peer 63e5296d334e3fa could not connect: dial tcp 172.16.199.17:2380: getsockopt: connection refused
|
恢復主機1 etcd服務:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Jun 27 21:45:02 docker2 etcd: peer 63e5296d334e3fa became active
Jun 27 21:45:02 docker2 etcd: established a TCP streaming connection with peer 63e5296d334e3fa (stream MsgApp v2 writer)
Jun 27 21:45:02 docker2 etcd: established a TCP streaming connection with peer 63e5296d334e3fa (stream Message writer)
Jun 27 21:45:02 docker2 etcd: established a TCP streaming connection with peer 63e5296d334e3fa (stream MsgApp v2 reader)
Jun 27 21:45:02 docker2 etcd: established a TCP streaming connection with peer 63e5296d334e3fa (stream Message reader)
Jun 27 21:45:02 docker2 etcd: 9558b2437a9b849a is starting a new election at term 442
Jun 27 21:45:02 docker2 etcd: 9558b2437a9b849a became candidate at term 443
Jun 27 21:45:02 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 9558b2437a9b849a at term 443
Jun 27 21:45:02 docker2 etcd: 9558b2437a9b849a [logterm: 61, index: 17] sent MsgVote request to 63e5296d334e3fa at term 443
Jun 27 21:45:02 docker2 etcd: 9558b2437a9b849a received MsgVoteResp from 63e5296d334e3fa at term 443
Jun 27 21:45:02 docker2 etcd: 9558b2437a9b849a [quorum:2] has received 2 MsgVoteResp votes and 0 vote rejections
Jun 27 21:45:02 docker2 etcd: 9558b2437a9b849a became leader at term 443
Jun 27 21:45:02 docker2 etcd: raft.node: 9558b2437a9b849a elected leader 9558b2437a9b849a at term 443
|
增加第三節點:
- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
留言
張貼留言