centos7.6下部署ETCD3.4.7 集群 (最详细步骤)

↘锁芯ラ 提交于 2020-08-10 06:34:42

安装包地址:

https://github.com/etcd-io/etcd/releases

解压安装文件
tar -xvf etcd-v3.4.7-linux-amd64.tar.gz
cd etcd-v3.4.7-linux-amd64
cp etcd etcdctl /k8s/etcd/bin/
设置etcd的配置文件

cat /k8s/etcd/cfg/etcd #[Member] ETCD_NAME="etcd01" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.2.88:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.2.88:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.2.88:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.2.88:2379" ETCD_INITIAL_CLUSTER="etcd01=https://192.168.2.88:2380,etcd02=https://192.168.2.81:2380,etcd03=https://192.168.2.82:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

创建 etcd的 systemd unit 文件

cat /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=/k8s/etcd/cfg/etcd
ExecStart=/k8s/etcd/bin/etcd \
--initial-cluster-state=new \
--cert-file=/k8s/etcd/ssl/server.pem \
--key-file=/k8s/etcd/ssl/server-key.pem \
--peer-cert-file=/k8s/etcd/ssl/server.pem \
--peer-key-file=/k8s/etcd/ssl/server-key.pem \
--trusted-ca-file=/k8s/etcd/ssl/ca.pem \
--peer-trusted-ca-file=/k8s/etcd/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target
启动ETCD服务
systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
查看etcd状态
systemctl status etcd
● etcd.service - Etcd Server
   Loaded: loaded (/usr/lib/systemd/system/etcd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-07-09 15:55:58 CST; 1h 12min ago
 Main PID: 29830 (etcd)
    Tasks: 12
   Memory: 66.7M
   CGroup: /system.slice/etcd.service
           └─29830 /k8s/etcd/bin/etcd --name=etcd01 --data-dir=/var/lib/etcd/default.etcd --listen-peer-urls=https://192.168.1.10...
 
Jul 09 17:07:39 qas-k8s-master01 etcd[29830]: the clock difference against peer 2369b1ebd5f356e7 is too high [1.340843978s ...SAGE")
Jul 09 17:07:39 qas-k8s-master01 etcd[29830]: the clock difference against peer 2369b1ebd5f356e7 is too high [1.343013157s ...SHOT")
Jul 09 17:08:04 qas-k8s-master01 etcd[29830]: the clock difference against peer 67ad1178efd89256 is too high [1.287315582s ...SHOT")
Jul 09 17:08:04 qas-k8s-master01 etcd[29830]: the clock difference against peer 67ad1178efd89256 is too high [1.285244104s ...SAGE")
Jul 09 17:08:09 qas-k8s-master01 etcd[29830]: the clock difference against peer 2369b1ebd5f356e7 is too high [1.340602239s ...SAGE")
Jul 09 17:08:09 qas-k8s-master01 etcd[29830]: the clock difference against peer 2369b1ebd5f356e7 is too high [1.342891162s ...SHOT")
Jul 09 17:08:34 qas-k8s-master01 etcd[29830]: the clock difference against peer 67ad1178efd89256 is too high [1.285259365s ...SAGE")
Jul 09 17:08:34 qas-k8s-master01 etcd[29830]: the clock difference against peer 67ad1178efd89256 is too high [1.287337806s ...SHOT")
Jul 09 17:08:39 qas-k8s-master01 etcd[29830]: the clock difference against peer 2369b1ebd5f356e7 is too high [1.342999378s ...SHOT")
Jul 09 17:08:39 qas-k8s-master01 etcd[29830]: the clock difference against peer 2369b1ebd5f356e7 is too high [1.339802949s ...SAGE")
Hint: Some lines were ellipsized, use -l to show in full.

将启动文件、配置文件拷贝到 节点1、节点2
cd /k8s/ 
scp -r etcd 192.168.2.81:/k8s/
scp -r etcd 192.168.2.82:/k8s/
scp /usr/lib/systemd/system/etcd.service  192.168.2.81:/usr/lib/systemd/system/etcd.service
scp /usr/lib/systemd/system/etcd.service  192.168.2.82:/usr/lib/systemd/system/etcd.service 
node01节点修改

cat /k8s/etcd/cfg/etcd

#[Member]
ETCD_NAME="etcd02"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.2.81:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.2.81:2379"
 
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.2.81:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.2.81:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://192.168.2.88:2380,etcd02=https://192.168.2.81:2380,etcd03=https://192.168.2.82:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
node02节点修改

cat /k8s/etcd/cfg/etcd

#[Member]
ETCD_NAME="etcd03"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.2.82:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.2.82:2379"
 
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.2.82:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.2.82:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://192.168.2.88:2380,etcd02=https://192.168.2.81:2380,etcd03=https://192.168.2.82:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

验证集群是否正常运行
./etcdctl --cacert=/k8s/etcd/ssl/ca.pem --cert=/k8s/etcd/ssl/server.pem --key=/k8s/etcd/ssl/server-key.pem --endpoints="https://192.168.2.88:2379,https://192.168.2.81:2379,https://192.168.2.82:2379" endpoint health

注意: 启动ETCD集群同时启动二个节点,启动一个节点集群是无法正常启动的; 返回以下表示ok

https://192.168.2.82:2379 is healthy: successfully committed proposal: took = 15.675731ms
https://192.168.2.88:2379 is healthy: successfully committed proposal: took = 15.764248ms
https://192.168.2.81:2379 is healthy: successfully committed proposal: took = 14.121678ms

微信公众号:[Kubernetes中文社区] qrcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!