安裝配置ETCD

zchbaby2000發表於2020-05-05

Master: 192.168.56.101
Worker node1: 192.168.56.102
Worker node2: 192.168.56.103

在安裝k8s之前,手動安裝配置etcd


下載etcd


傳到3節點,解壓壓縮包
mkdir /opt/etcd/{bin,cfg,ssl} -p
tar -zxvf etcd-v3.2.30-linux-amd64.tar.gz -C ./
mv etcd-v3.2.30-linux-amd64/{etcd,etcdctl} /opt/etcd/bin/


master節點配置檔案 /opt/etcd/cfg/etcd
#[Member]
ETCD_NAME="etcd-1"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.56.101:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.56.101:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.56.101:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.56.101:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.56.101:2380,etcd-2=https://192.168.56.102:2380,etcd-3=https://192.168.56.103:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"


Worker node1節點配置檔案 /opt/etcd/cfg/etcd
#[Member]
ETCD_NAME="etcd-2"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.56.102:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.56.102:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.56.102:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.56.102:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.56.101:2380,etcd-2=https://192.168.56.102:2380,etcd-3=https://192.168.56.103:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"


Worker node2節點配置檔案 /opt/etcd/cfg/etcd
#[Member]
ETCD_NAME="etcd-3"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.56.103:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.56.103:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.56.103:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.56.103:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.56.101:2380,etcd-2=https://192.168.56.102:2380,etcd-3=https://192.168.56.103:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"


master節點,Worker node1, Worker node2 配置檔案 /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/etcd/cfg/etcd
ExecStart=/opt/etcd/bin/etcd \
--name=${ETCD_NAME} \
--data-dir=${ETCD_DATA_DIR} \
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS}, \
--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_TOKEN} \
--initial-cluster-state=new \
--cert-file=/opt/etcd/ssl/server.pem \
--key-file=/opt/etcd/ssl/server-key.pem \
--peer-cert-file=/opt/etcd/ssl/server.pem \
--peer-key-file=/opt/etcd/ssl/server-key.pem \
--trusted-ca-file=/opt/etcd/ssl/ca.pem \
--peer-trusted-ca-file=/opt/etcd/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target


將之前生成的證書複製到/opt/etcd/ssl
cp ca*pem server*pem /opt/etcd/ssl


啟動並設定開機啟動
systemctl start etcd
systemctl enable etcd

檢查一下叢集的狀態
/opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.56.101:2379,https://192.168.56.102:2379,https://192.168.56.103:2379" cluster-health
member 181ffe2d394f445b is healthy: got healthy result from https://192.168.56.101:2379
member 737ab8edec59b6e6 is healthy: got healthy result from https://192.168.56.102:2379
member 87a3a196a794e8f0 is healthy: got healthy result from https://192.168.56.103:2379
cluster is healthy

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/725820/viewspace-2689897/,如需轉載,請註明出處,否則將追究法律責任。

相關文章