k8s部署etcd数据库集群
⒈下载
https://github.com/etcd-io/etcd/releases
⒉解压
1 tar -zxvf etcd-v3.3.12-linux-amd64.tar.gz
⒊移动可执行文件及证书文件到指定目录
1 mkdir -p /opt/kubernetes/{bin,cfg,ssl}
1 mv etcd-v3.3.12-linux-amd64/etcd /opt/kubernetes/bin/ 2 mv etcd-v3.3.12-linux-amd64/etcdctl /opt/kubernetes/bin/
cp /home/fanqi/*.pem /opt/kubernetes/ssl/
⒋新建一个配置文件
1 cd /opt/kubernetes/cfg/ 2 vi etcd
#[Member] ETCD_NAME="etcd02" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.0.212:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.0.212:2379" #[clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.212:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.212:2379" ETCD_INITIAL_CLUSTER="etcd01=https://192.168.0.211:2380,etcd02=https://192.168.0.212:2380,etcd03=https://192.168.0.213:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
⒌编写服务配置文件及启动服务
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_TOKEN} \ --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
systemctl start etcd
⒍设置开机启动
systemctl enable etcd
⒎查看集群状态
/opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.0.211:2379,https://192.168.0.212:2379,https://192.168.0.213:2379" cluster-health