以靜態(tài)方式部署etcd集群
何為靜態(tài)方式部署呢运提?
預(yù)先已知etcd集群中有哪些節(jié)點(diǎn)鳍寂,在啟動(dòng)時(shí)通過(guò)--initial-cluster參數(shù)直接指定好etcd的各個(gè)節(jié)點(diǎn)地址
一改含、測(cè)試環(huán)境
主機(jī)名 | 系統(tǒng)版本 | IP | 服務(wù) |
---|---|---|---|
master | centos7.5 | 172.16.91.195 | etcd |
slave01 | centos7.5 | 172.16.91.196 | etcd |
slave02 | centos7.5 | 172.16.91.197 | etcd |
二、部署方式說(shuō)明
目前大概有以下幾種部署方式吧:
- yum
- docker
- rpm
- k8s
本文采用yum方式安裝部署
其他方式迄汛,docker捍壤,rpm方式可以參考其他博文,或者官網(wǎng)
https://github.com/etcd-io/etcd/releases
2.1 通過(guò)yum方式安裝的etcd服務(wù)鞍爱,配置文件位置如下:
名稱 | 位置 |
---|---|
etcd | /usr/bin/etcd |
etcdctl | /usr/bin/etcdctl |
etcd.service | /lib/systemd/system/etcd.service |
etcd.conf | /etc/etcd/etcd.conf |
三鹃觉、部署etcd服務(wù)(不帶認(rèn)證)
3.1 通過(guò)yum方式部署安裝etcd
在三臺(tái)節(jié)點(diǎn)上,分別使用下面的命令睹逃,來(lái)安裝etcd
yum install -y etcd
注意:
- 通過(guò)yum方式安裝的etcd服務(wù)盗扇,是交給linux的系統(tǒng)服務(wù)來(lái)維護(hù)生命周期的
- 此時(shí)etcd服務(wù)并沒(méi)有起來(lái)祷肯,需要手動(dòng)啟動(dòng)etcd服務(wù)
由于默認(rèn)的配置只能自己本節(jié)點(diǎn)使用,因此這里先不啟動(dòng)etcd服務(wù)
3.2 更新配置文件
3.2.1 更新etcd.service
-
master節(jié)點(diǎn)疗隶,配置文件如下所示:
[root@master lib]# more /lib/systemd/system/etcd.service [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=/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-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \ --initial-cluster-state=${ETCD_INITIAL_CLUSTER_STATE} \ --initial-cluster=${ETCD_INITIAL_CLUSTER} Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target
-
slave1節(jié)點(diǎn)佑笋,配置文件如下所示:
[root@slave1 lib]# more /lib/systemd/system/etcd.service [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=/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-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \ --initial-cluster-state=${ETCD_INITIAL_CLUSTER_STATE} \ --initial-cluster=${ETCD_INITIAL_CLUSTER} Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target
-
slave2節(jié)點(diǎn),配置文件如下所示:
[root@slave2 ~]# more /lib/systemd/system/etcd.service [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=/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-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \ --initial-cluster-state=${ETCD_INITIAL_CLUSTER_STATE} \ --initial-cluster=${ETCD_INITIAL_CLUSTER} Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target
3.2.2 更新etcd.conf
-
master節(jié)點(diǎn)斑鼻,配置文件如下所示:
[root@master lib]# more /etc/etcd/etcd.conf #[Member] ETCD_DATA_DIR="/var/lib/etcd-jingtai/data" ETCD_LISTEN_PEER_URLS="http://172.16.91.195:2380" ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379,http://172.16.91.195:2379" ETCD_NAME="master" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.91.195:2380" ETCD_ADVERTISE_CLIENT_URLS="http://127.0.0.1:2379,http://172.16.91.195:2379" ETCD_INITIAL_CLUSTER="master=http://172.16.91.195:2380,slave1=http://172.16.91.196:2380,slave2=http://172.16.91.197:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster001" ETCD_INITIAL_CLUSTER_STATE="new"
-
slave1節(jié)點(diǎn)蒋纬,配置文件如下所示:
[root@slave1 etcd-jingtai]# more /etc/etcd/etcd.conf #[Member] ETCD_DATA_DIR="/var/lib/etcd-jingtai/data" ETCD_LISTEN_PEER_URLS="http://172.16.91.196:2380" ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379,http://172.16.91.196:2379" ETCD_NAME="slave1" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.91.196:2380" ETCD_ADVERTISE_CLIENT_URLS="http://127.0.0.1:2379,http://172.16.91.196:2379" ETCD_INITIAL_CLUSTER="master=http://172.16.91.195:2380,slave1=http://172.16.91.196:2380,slave2=http://172.16.91.197:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster001" ETCD_INITIAL_CLUSTER_STATE="new"
-
slave2節(jié)點(diǎn),配置文件如下所示:
[root@slave2 ~]# more /etc/etcd/etcd.conf #[Member] ETCD_DATA_DIR="/var/lib/etcd-jingtai/data" ETCD_LISTEN_PEER_URLS="http://172.16.91.197:2380" ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379,http://172.16.91.197:2379" ETCD_NAME="slave2" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://172.16.91.197:2380" ETCD_ADVERTISE_CLIENT_URLS="http://127.0.0.1:2379,http://172.16.91.197:2379" ETCD_INITIAL_CLUSTER="master=http://172.16.91.195:2380,slave1=http://172.16.91.196:2380,slave2=http://172.16.91.197:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster001" ETCD_INITIAL_CLUSTER_STATE="new"
3.3 重啟etcd服務(wù)
- 創(chuàng)建data目錄
mkdir -p /var/lib/etcd-jingtai/data
- 啟動(dòng)服務(wù)
systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
systemctl status etcd
四坚弱、測(cè)試etcd服務(wù)
查看服務(wù)狀態(tài)
五蜀备、問(wèn)題列表
-
request sent was ignored (cluster ID mismatch: peer[3fc33c18ca0433f2]=3b1291d31874b132, local=9818358e4a92d2d9) request cluster ID mismatch (got 9818358e4a92d2d9 want 3b29dfa314757683)
現(xiàn)象是: 一個(gè)etcd集群里,有兩個(gè)leader荒叶, 或者說(shuō)碾阁,這兩個(gè)etcd實(shí)例有各自的集群ID,
第3個(gè)etcd實(shí)例停撞,分別向這兩個(gè)發(fā)送請(qǐng)求
原因:
在搭建集群前,先進(jìn)行了單實(shí)例的etcd部署測(cè)試悼瓮, 即master, slave1節(jié)點(diǎn)分別進(jìn)行了單實(shí)例部署測(cè)試戈毒,
也就是歷史數(shù)據(jù)的影響。
刪除歷史數(shù)據(jù)即可横堡。
rm -rf /var/lib/etcd/*
六埋市、說(shuō)明:
在部署過(guò)程中,遇到的主要問(wèn)題有:
配置文件名稱寫錯(cuò)了
etcd.service里命贴,啟動(dòng)服務(wù)ExecStart里不能有空白行道宅,注釋
-
權(quán)限問(wèn)題,User=etcd,改成root
recognized environment variable ETCD_DATA_DIR, but unused: shadowed by corresponding flag
默認(rèn)是etcd胸蛛,導(dǎo)致污茵,啟動(dòng)失敗。當(dāng)然葬项,也可以修改ETCD_DATA_DIR的權(quán)限泞当,或者所有者 歷史數(shù)據(jù)的影響