部署etcd集羣

部署etcd集羣

第一步:先拉取etcd二進制壓縮包node

wget https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz
//解壓壓縮包
tar zxvf etcd-v3.3.2-linux-amd64.tar.gz

第二步:創建一個文件,分別存放bin文件,cfg配置文件,ssl驗證文件linux

mkdir /opt/kubernetes/{bin,cfg,ssl}
//而後將etcd,etcdctl移動到bin目錄下
mv etcd-v3.3.2-linux-amd64/etcd /opt/kubernetes/bin/
mv etcd-v3.3.2-linux-amd64/etcdctl /opt/kubernetes/bin/

第三步:建立etcd.service配置文件git

vi /usr/lib/systemd/system/etcd.service
 //內容爲
 [Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=-/opt/kubernetes/cfg/etcd
ExecStart=/opt/kubernetes/bin/etcd \
--name=${ETCD_NAME} \
--data-dir=${ETCD_DATA_DIR} \
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} \
--initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
--initial-cluster=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-token=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-state=new \
--cert-file=/opt/kubernetes/ssl/server.pem \
--key-file=/opt/kubernetes/ssl/server-key.pem \
--peer-cert-file=/opt/kubernetes/ssl/server.pem \
--peer-key-file=/opt/kubernetes/ssl/server-key.pem \
--trusted-ca-file=/opt/kubernetes/ssl/ca.pem \
--peer-trusted-ca-file=/opt/kubernetes/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

第四步:建立etcd配置文件github

#[Member]
ETCD_NAME="etcd01" //節點名字
ETCD_DATA_DIR="/var/lib/etcd/default.etcd" //數據目錄
ETCD_LISTEN_PEER_URLS="https://172.16.163.131:2380" 當前節點的ip地址
ETCD_LISTEN_CLIENT_URLS="https://172.16.163.131:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://172.16.163.131:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://172.16.163.131:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://172.16.163.131:2380,etcd02=https://172.16.163.130:2380,etcd03=https://172.16.163.129:2380" //集羣全部的節點的ip地址
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

第五步:將TLS證書生成的pem文件,複製到/opt/kubernetes/ssl/目錄下shell

cp ssl/server*pem ssl/ca*.pem /opt/kubernetes/ssl/

第六步:啓動etcdssh

systemctl daemon-reload
systemctl start etcd
systemctl enable etcd

第七步:查看etcd是否啓動url

ps -ef |grep etcd

第八步:設置互信免密登陸3d

//生成祕鑰和私鑰
ssh-keygen
//將祕鑰和私鑰複製到其餘節點,這樣就能夠相互免密登陸了
ssh-copy-id root@172.16.163.130

第九步:將全部在master節點上的配置文件都拷貝到node節點上,都使用一樣的配置文件,不一樣的地方在於有些配置文件的內容不一樣。這些操做只須要在master作就能夠。code

scp -r /opt/kubernetes/bin/ root@172.16.163.130:/opt/kubernetes/
//將etcd配置文件拷貝到node節點
scp -r /opt/kubernetes/cfg/ root@172.16.163.130:/opt/kubernetes/
scp -r /opt/kubernetes/ssl/ root@172.16.163.130:/opt/kubernetes/
//將etcd.service配置文件也要拷貝到node節點
scp /usr/lib/systemd/system/etcd.service root@172.16.163.130:/usr/lib/systemd/system

第十步:由於etcd,etcdctl命令會常使用,因此將他們加入到PATH路徑中server

將etcd命令加入PATH
vi /etc/profile
在最後一行加入:PATH=$PATH:/opt/kubernetes/bin
讓配置生效
source /etc/profile

第十一步:檢查集羣搭建成功與否

//執行這個命令須要進入到/opt/kubernetes/ssl目錄,由於須要使用TLS證書
etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://172.16.163.130:2379,https://172.16.163.129:2379,https://172.16.163.131:2379" cluster-health
或者   
etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem cluster-health
//輸出這個表示成功
member 204f1af770aff3d9 is healthy: got healthy result from https://172.16.163.129:2379
member 81e41daa4ea73cbc is healthy: got healthy result from https://172.16.163.130:2379
member d2349ea355902626 is healthy: got healthy result from https://172.16.163.131:2379
cluster is healthy

報錯:

這個報錯是由數據目錄引發的,只須要刪除這個數據目錄就能夠了。

rm -rf /var/lib/etcd/default.etcd/

到這裏錯誤處理完畢,etcd集羣搭建完成。

相關文章
相關標籤/搜索