配置各个节点/etc/hosts
[root@host-10-10-18-42 etcd]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 etcd1 10.10.18.42 etcd2 10.10.18.43 etcd3 10.10.18.44
etcd1 |
10.10.18.42 |
|
|
10.10.18.43 |
|
|
10.10.18.44 |
配置目录
mkdir /data/k8s/etcd/{data,wal} -p
chown -R etcd.etcd /data/k8s/etcd
etcd1
[root@host-10-10-18-42 etcd]# cat etcd.conf ETCD_DATA_DIR="/data/k8s/etcd/data" ETCD_WAL_DIR="/data/k8s/etcd/wal" ETCD_LISTEN_PEER_URLS="http://10.10.18.42:2380" ETCD_LISTEN_CLIENT_URLS="http://10.10.18.42:2379" ETCD_MAX_SNAPSHOTS="5" ETCD_MAX_WALS="5" ETCD_NAME="etcd1" ETCD_SNAPSHOT_COUNT="100000" ETCD_HEARTBEAT_INTERVAL="100" ETCD_ELECTION_TIMEOUT="1000" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.10.18.42:2380" ETCD_ADVERTISE_CLIENT_URLS="http://10.10.18.42:2379" ETCD_INITIAL_CLUSTER="etcd1=http://10.10.18.42:2380,etcd2=http://10.10.18.43:2380,etcd3=http://10.10.18.44:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
etcd2
[root@host-10-10-18-43 etcd]# cat etcd.conf ETCD_DATA_DIR="/data/k8s/etcd/data" ETCD_WAL_DIR="/data/k8s/etcd/wal" ETCD_LISTEN_PEER_URLS="http://10.10.18.43:2380" ETCD_LISTEN_CLIENT_URLS="http://10.10.18.43:2379" ETCD_MAX_SNAPSHOTS="5" ETCD_MAX_WALS="5" ETCD_NAME="etcd2" ETCD_SNAPSHOT_COUNT="100000" ETCD_HEARTBEAT_INTERVAL="100" ETCD_ELECTION_TIMEOUT="1000" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.10.18.43:2380" ETCD_ADVERTISE_CLIENT_URLS="http://10.10.18.43:2379" ETCD_INITIAL_CLUSTER="etcd1=http://10.10.18.42:2380,etcd2=http://10.10.18.43:2380,etcd3=http://10.10.18.44:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
etcd3
[root@host-10-10-18-44 etcd]# cat etcd.conf ETCD_DATA_DIR="/data/k8s/etcd/data" ETCD_WAL_DIR="/data/k8s/etcd/wal" ETCD_LISTEN_PEER_URLS="http://10.10.18.44:2380" ETCD_LISTEN_CLIENT_URLS="http://10.10.18.44:2379" ETCD_MAX_SNAPSHOTS="5" ETCD_MAX_WALS="5" ETCD_NAME="etcd3" ETCD_SNAPSHOT_COUNT="100000" ETCD_HEARTBEAT_INTERVAL="100" ETCD_ELECTION_TIMEOUT="1000" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.10.18.44:2380" ETCD_ADVERTISE_CLIENT_URLS="http://10.10.18.44:2379" ETCD_INITIAL_CLUSTER="etcd1=http://10.10.18.42:2380,etcd2=http://10.10.18.43:2380,etcd3=http://10.10.18.44:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
Jun 29 11:28:03 host-10-10-18-43 etcd[4059]: health check for peer 1829ea2c82ecd13e could not connect: dial tcp 10.10.18.42:2380: i/o timeout (prober "ROUND_TRIPPER_RAFT_MESSAGE") Jun 29 11:28:03 host-10-10-18-43 etcd[4059]: health check for peer 1829ea2c82ecd13e could not connect: dial tcp 10.10.18.42:2380: i/o timeout (prober "ROUND_TRIPPER_SNAPSHOT") Jun 29 11:28:03 host-10-10-18-43 etcd[4059]: health check for peer fe3b541533812c5d could not connect: dial tcp 10.10.18.44:2380: i/o timeout (prober "ROUND_TRIPPER_RAFT_MESSAGE") Jun 29 11:28:03 host-10-10-18-43 etcd[4059]: health check for peer fe3b541533812c5d could not connect: dial tcp 10.10.18.44:2380: i/o timeout (prober "ROUND_TRIPPER_SNAPSHOT")
root@ubuntu:~/bibili# telnet 10.10.18.44 2380 Trying 10.10.18.44... telnet: Unable to connect to remote host: No route to host root@ubuntu:~/bibili#
关闭CentOS7防火墙
# 查看防火墙状态 firewall-cmd --state # 停止firewall systemctl stop firewalld.service # 禁止firewall开机启动 systemctl disable firewalld.service
关闭SELINUX
# 编辑SELINUX文件 vim /etc/selinux/config # 将SELINUX=enforcing改为SELINUX=disabled
root@ubuntu:~/bibili# telnet 10.10.18.44 2380 Trying 10.10.18.44... Connected to 10.10.18.44. Escape character is ‘^]‘. ^C^C^CConnection closed by foreign host.
root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 etcdctl --endpoints=http://10.10.18.42:2379,http://10.10.18.43:2379,http://10.10.18.44:2379 endpoint health http://10.10.18.43:2379 is healthy: successfully committed proposal: took = 2.311413ms http://10.10.18.42:2379 is healthy: successfully committed proposal: took = 4.239303ms http://10.10.18.44:2379 is healthy: successfully committed proposal: took = 4.742326ms root@ubuntu:~/etcd-v3.5.0-linux-arm64#
root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl --endpoints=http://10.10.18.42:2379,http://10.10.18.43:2379,http://10.10.18.44:2379 member list 1829ea2c82ecd13e, started, etcd1, http://10.10.18.42:2380, http://10.10.18.42:2379, false 19ddebfcb3e299fd, started, etcd2, http://10.10.18.43:2380, http://10.10.18.43:2379, false fe3b541533812c5d, started, etcd3, http://10.10.18.44:2380, http://10.10.18.44:2379, false
root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl -w table --endpoints=http://10.10.18.42:2379,http://10.10.18.43:2379,http://10.10.18.44:2379 endpoint status +-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | http://10.10.18.42:2379 | 1829ea2c82ecd13e | 3.3.11 | 328 kB | true | false | 339 | 17 | 0 | | | http://10.10.18.43:2379 | 19ddebfcb3e299fd | 3.3.11 | 328 kB | false | false | 339 | 17 | 0 | | | http://10.10.18.44:2379 | fe3b541533812c5d | 3.3.11 | 328 kB | false | false | 339 | 17 | 0 | | +-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ root@ubuntu:~/etcd-v3.5.0-linux-arm64#
root@ubuntu:~/etcd-v3.5.0-linux-arm64# ENDPOINTS=http://10.10.18.42:2379,http://10.10.18.43:2379,http://10.10.18.44:2379 root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl -w table --endpoints=$ENDPOINTS endpoint status +-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | http://10.10.18.42:2379 | 1829ea2c82ecd13e | 3.3.11 | 328 kB | true | false | 339 | 17 | 0 | | | http://10.10.18.43:2379 | 19ddebfcb3e299fd | 3.3.11 | 328 kB | false | false | 339 | 17 | 0 | | | http://10.10.18.44:2379 | fe3b541533812c5d | 3.3.11 | 328 kB | false | false | 339 | 17 | 0 | | +-------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ root@ubuntu:~/etcd-v3.5.0-linux-arm64#
root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl --endpoints=$ENDPOINTS put test "helloworld" OK root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl --endpoints=$ENDPOINTS get test test helloworld root@ubuntu:~/etcd-v3.5.0-linux-arm64#
[root@host-10-10-18-42 etcd]# tree /data/k8s/etcd/ /data/k8s/etcd/ |-- data | `-- member | `-- snap | `-- db `-- wal |-- 0000000000000000-0000000000000000.wal `-- 0.tmp 4 directories, 3 files
root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl --endpoints=$ENDPOINTS snapshot save mysnapshot.db Error: snapshot must be requested to one selected node, not multiple [http://10.10.18.42:2379 http://10.10.18.43:2379 http://10.10.18.44:2379] root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl --endpoints=$ENDPOINTS snapshot status mysnapshot.db -w json Deprecated: Use `etcdutl snapshot status` instead. Error: stat mysnapshot.db: no such file or directory root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl --endpoints=http://10.10.18.43:2379 snapshot status mysnapshot.db -w json Deprecated: Use `etcdutl snapshot status` instead. Error: stat mysnapshot.db: no such file or directory root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl --endpoints=http://10.10.18.43:2379 snapshot save mysnapshot.db {"level":"info","ts":1624938894.0369105,"caller":"snapshot/v3_snapshot.go:68","msg":"created temporary db file","path":"mysnapshot.db.part"} {"level":"info","ts":1624938894.0386374,"logger":"client","caller":"v3/maintenance.go:211","msg":"opened snapshot stream; downloading"} {"level":"info","ts":1624938894.0386932,"caller":"snapshot/v3_snapshot.go:76","msg":"fetching snapshot","endpoint":"http://10.10.18.43:2379"} {"level":"info","ts":1624938894.0599878,"logger":"client","caller":"v3/maintenance.go:219","msg":"completed snapshot read; closing"} {"level":"info","ts":1624938894.0606616,"caller":"snapshot/v3_snapshot.go:91","msg":"fetched snapshot","endpoint":"http://10.10.18.43:2379","size":"328 kB","took":"now"} {"level":"info","ts":1624938894.0607412,"caller":"snapshot/v3_snapshot.go:100","msg":"saved","path":"mysnapshot.db"} Snapshot saved at mysnapshot.db root@ubuntu:~/etcd-v3.5.0-linux-arm64# ETCDCTL_API=3 ./etcdctl snapshot status mysnapshot.db -w json Deprecated: Use `etcdutl snapshot status` instead. {"hash":3787458990,"revision":2,"totalKey":7,"totalSize":327680} root@ubuntu:~/etcd-v3.5.0-linux-arm64#