etcd3.5.0版本集群部署及備份


1,環境配置

https://github.com/etcd-io/etcd/releases/tag/v3.5.0

etcd版本:etcd-v3.5.0
集群ip:
etcd-1:192.168.44.218
etcd-2:192.168.6.166
etcd-3:192.168.44.210

2,ETCD下載

$ wget https://github.com/etcd-io/etcd/releases/download/v3.5.0/etcd-v3.5.0-linux-amd64.tar.gz
$ tar -zxvf  etcd-v3.5.0-linux-amd64.tar.gz -C /beta/etcd
$ cd /beta/etcd
$ mv etcd-v3.5.0-linux-amd64  etcd-v3.5.0
$ mkdir /etc/etcd           # 創建etcd配置文件目錄
$ chown root.root etcd-v3.5.0 -R
開啟防火牆端口
firewall-cmd --add-port=2379/tcp --permanent --zone=public
firewall-cmd --add-port=2380/tcp --permanent --zone=public
firewall-cmd --reload

3,創建etcd配置文件:

$ vi /etc/etcd/conf.yml

節點1,添加如下內容:
cat >/etc/etcd/conf.yml<<EOF
name: etcd-1
data-dir: /beta/etcd/data
listen-client-urls: http://192.168.44.218:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.44.218:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.44.218:2380
initial-advertise-peer-urls: http://192.168.44.218:2380
initial-cluster: etcd-1=http://192.168.44.218:2380,etcd-2=http://192.168.6.166:2380,etcd-3=http://192.168.44.210:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
EOF

節點2,添加如下內容:
cat >/etc/etcd/conf.yml<<EOF
name: etcd-2
data-dir: /beta/etcd/data
listen-client-urls: http://192.168.6.166:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.6.166:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.6.166:2380
initial-advertise-peer-urls: http://192.168.6.166:2380
initial-cluster: etcd-1=http://192.168.44.218:2380,etcd-2=http://192.168.6.166:2380,etcd-3=http://192.168.44.210:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
EOF

節點3,添加如下內容:
cat >/etc/etcd/conf.yml<<EOF
name: etcd-3
data-dir: /beta/etcd/data
listen-client-urls: http://192.168.44.210:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.44.210:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.44.210:2380
initial-advertise-peer-urls: http://192.168.44.210:2380
initial-cluster: etcd-1=http://192.168.44.218:2380,etcd-2=http://192.168.6.166:2380,etcd-3=http://192.168.44.210:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
EOF

啟動命令:
$ ./etcd --config-file=/etc/etcd/conf.yml

4,配置ETCD為啟動服務


編輯/usr/lib/systemd/system/etcd.service,添加下面內容:
cat >/usr/lib/systemd/system/etcd.service<<EOF
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/beta/etcd/etcd-v3.5.0
# User=etcd
ExecStart=/beta/etcd/etcd-v3.5.0/etcd --config-file=/etc/etcd/conf.yml
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

5,更新啟動:

systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
systemctl restart etcd

systemctl status etcd.service -l

6,API 3 備份與恢復方法

在命令行設置:
# export ETCDCTL_API=3

備份數據:
# etcdctl --endpoints localhost:2379 snapshot save snapshot.db

恢復:
# etcdctl snapshot restore snapshot.db --name m3 --data-dir=/home/etcd_data
恢復后的文件需要修改權限為 etcd:etcd
--name:重新指定一個數據目錄,可以不指定,默認為 default.etcd
--data-dir:指定數據目錄
建議使用時不指定 name 但指定 data-dir,並將 data-dir 對應於 etcd 服務中配置的 data-dir
更新etcd系統默認配置:
當前使用的是etcd v3版本,系統默認的是v2,通過下面命令修改配置。

$ vi /etc/profile
在末尾追加
export ETCDCTL_API=3
$ source /etc/profile

ETCD命令
$ cd /beta/etcd/etcd-v3.5.0

查看當前etcd版本:
$ ./etcdctl version
etcdctl version: 3.5.0
API version: 3.5

常用命令
export ETCDCTL_API=3
ETCD_VER=v3.5.0
./etcdctl --endpoints=192.168.44.218:2379,192.168.6.166:2379,192.168.44.210:2379   endpoint status
./etcdctl --endpoints=192.168.44.218:2379,192.168.6.166:2379,192.168.44.210:2379   endpoint health
./etcdctl --endpoints=192.168.44.218:2379,192.168.6.166:2379,192.168.44.210:2379  endpoint hashkv
./etcdctl --endpoints=192.168.44.218:2379,192.168.6.166:2379,192.168.44.210:2379  check perf
./etcdctl --endpoints=192.168.44.218:2379,192.168.6.166:2379,192.168.44.210:2379  check datascale
./etcdctl --endpoints=192.168.44.218:2379,192.168.6.166:2379,192.168.44.210:2379  member list


查看集群成員信息:
export ETCDCTL_API=3
查看選舉狀態:
 ./etcdctl --endpoints=192.168.44.218:2379,192.168.6.166:2379,192.168.44.210:2379   endpoint status
192.168.44.218:2379, d0b6669beaefa1b1, 3.5.0, 63 MB, true, false, 5, 29022, 29022, 
192.168.6.166:2379, 4a53660b08484e27, 3.5.0, 63 MB, false, false, 5, 29022, 29022, 
192.168.44.210:2379, 61639fbcc5571efc, 3.5.0, 63 MB, false, false, 5, 29022, 29022, 


ECTD讀寫操作
基於HTTP協議的API使用起來比較簡單,這里主要通過etcdctl和curl兩種方式來做簡單介紹。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM