1、下载安装
二进制下载:
https://github.com/coreos/etcd/releases/download/v3.3.13/etcd-v3.3.13-linux-amd64.tar.gz
1 [root@k8s-master01 ~]# tar xf etcd-v3.3.13-linux-amd64.tar.gz 2 [root@k8s-master01 ~]# cd etcd-v3.3.13-linux-amd64 3 [root@k8s-master01 etcd-v3.3.13-linux-amd64]# ll 4 总用量 29776 5 drwxr-xr-x 10 1000 1000 4096 5月 3 2019 Documentation 6 -rwxr-xr-x 1 1000 1000 16927136 5月 3 2019 etcd 7 -rwxr-xr-x 1 1000 1000 13498880 5月 3 2019 etcdctl 8 -rw-r--r-- 1 1000 1000 38864 5月 3 2019 README-etcdctl.md 9 -rw-r--r-- 1 1000 1000 7262 5月 3 2019 README.md 10 -rw-r--r-- 1 1000 1000 7855 5月 3 2019 READMEv2-etcdctl.md
只有etcd,etcdctl两个文件有用
2、安装etcd
1 #创建etcd所需要的目录 2 [root@k8s-master01 opt]# mkdir -p etcd/{bin,cfg,ssl} 3 #拷贝下载下来的可执行命令 4 [root@k8s-master01 ~]# cp etcd-v3.3.13-linux-amd64/{etcd,etcdctl} /opt/etcd/bin/ 5 #拷贝我们生成的自签证书 6 [root@k8s-master01 ~]# cp k8s/tls/etcd/{server,server-key,ca}.pem /opt/etcd/ssl/ 7 [root@k8s-master01 ~]# tree /opt/etcd 8 /opt/etcd 9 ├── bin 10 │ ├── etcd 11 │ └── etcdctl 12 ├── cfg 13 └── ssl 14 ├── ca.pem 15 ├── server-key.pem 16 └── server.pem
3、生成启动和配置文件
#配置文件
1 [root@k8s-master01 ~]# cat /opt/etcd/cfg/etcd.conf 2 3 #[Member] 4 ETCD_NAME="etcd-1" 5 ETCD_DATA_DIR="/var/lib/etcd/default.etcd" 6 ETCD_LISTEN_PEER_URLS="https://etcd01:2380" 7 ETCD_LISTEN_CLIENT_URLS="https://etcd01:2379" 8 9 #[Clustering] 10 ETCD_INITIAL_ADVERTISE_PEER_URLS="https://etcd01:2380" 11 ETCD_ADVERTISE_CLIENT_URLS="https://etcd01:2379" 12 ETCD_INITIAL_CLUSTER="etcd-1=https://etcd01:2380,etcd-2=https://etcd02:2380,etcd-3=https://etcd03:2380" 13 ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" 14 ETCD_INITIAL_CLUSTER_STATE="new"
#启动文件
1 [root@k8s-master01 etcd]# cat /opt/etcd/etcd.service 2 [Unit] 3 Description=Etcd Server 4 After=network.target 5 After=network-online.target 6 Wants=network-online.target 7 8 [Service] 9 Type=notify 10 EnvironmentFile=/opt/etcd/cfg/etcd.conf 11 ExecStart=/opt/etcd/bin/etcd 12 --name=${ETCD_NAME} 13 --data-dir=${ETCD_DATA_DIR} 14 --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} 15 --listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 16 --advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} 17 --initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} 18 --initial-cluster=${ETCD_INITIAL_CLUSTER} 19 --initial-cluster-token=${ETCD_INITIAL_CLUSTER_TOKEN} 20 --initial-cluster-state=new 21 --cert-file=/opt/etcd/ssl/server.pem 22 --key-file=/opt/etcd/ssl/server-key.pem 23 --peer-cert-file=/opt/etcd/ssl/server.pem 24 --peer-key-file=/opt/etcd/ssl/server-key.pem 25 --trusted-ca-file=/opt/etcd/ssl/ca.pem 26 --peer-trusted-ca-file=/opt/etcd/ssl/ca.pem 27 Restart=on-failure 28 LimitNOFILE=65536 29 30 [Install] 31 WantedBy=multi-user.target
4、拷贝etcd目录到etcd01,etcd02,etcd03机器上
1 [root@k8s-master01 ~]# scp -r /opt/etcd/ etcd01:/opt/ 2 [root@k8s-master01 ~]# scp -r /opt/etcd/ etcd02:/opt/ 3 [root@k8s-master01 ~]# scp -r /opt/etcd/ etcd03:/opt/
5、分别修改3台etcd的cfg/etcd.conf文件,IP为自己的IP
#etcd01
[root@etcd01 ~]# cat /opt/etcd/cfg/etcd.conf #[Member] ETCD_NAME="etcd-1" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://10.16.8.161:2380" ETCD_LISTEN_CLIENT_URLS="https://10.16.8.161:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.16.8.161:2380" ETCD_ADVERTISE_CLIENT_URLS="https://10.16.8.161:2379" ETCD_INITIAL_CLUSTER="etcd-1=https://10.16.8.161:2380,etcd-2=https://10.16.8.162:2380,etcd-3=https://10.16.8.163:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
#etcd02
#[Member] ETCD_NAME="etcd-2" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://10.16.8.162:2380" ETCD_LISTEN_CLIENT_URLS="https://10.16.8.162:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.16.8.162:2380" ETCD_ADVERTISE_CLIENT_URLS="https://10.16.8.162:2379" ETCD_INITIAL_CLUSTER="etcd-1=https://10.16.8.161:2380,etcd-2=https://10.16.8.162:2380,etcd-3=https://10.16.8.163:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
#etcd03
[root@etcd03 ~]# cat /opt/etcd/cfg/etcd.conf #[Member] ETCD_NAME="etcd-3" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://10.16.8.163:2380" ETCD_LISTEN_CLIENT_URLS="https://10.16.8.163:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://10.16.8.163:2380" ETCD_ADVERTISE_CLIENT_URLS="https://10.16.8.163:2379" ETCD_INITIAL_CLUSTER="etcd-1=https://10.16.8.161:2380,etcd-2=https://10.16.8.162:2380,etcd-3=https://10.16.8.163:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
6、3台etcd机器上分别拷贝etcd.service到/usr/lib/systemd/system
[root@etcd01 ~]# mv /opt/etcd/etcd.service /usr/lib/systemd/system [root@etcd02 ~]# mv /opt/etcd/etcd.service /usr/lib/systemd/system [root@etcd03 ~]# mv /opt/etcd/etcd.service /usr/lib/systemd/system
7、启动和开机启动etcd
[root@etcd01 ~]# systemctl daemon-reload [root@etcd01 ~]# systemctl start etcd [root@etcd01 ~]# systemctl enable etcd
8、查看集群状态
[root@etcd01 ~]# /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://10.16.8.161:2379,https://10.16.8.162:2379,https://10.16.8.163:2379" cluster-health member 592bed4fa345de89 is healthy: got healthy result from https://10.16.8.163:2379 member 7fc93466fcfffccf is healthy: got healthy result from https://10.16.8.162:2379 member d83d38380a38f404 is healthy: got healthy result from https://10.16.8.161:2379 cluster is healthy