kubernetes 部署--创建 etcd 集群(非TLS)⑤
安装 etcd
yum install etcd
接下来,修改 systemd 将会使用的环境文件(master1、master2、master3分别配置):
export PEER_NAME=$(hostname) export PRIVATE_IP=$(ip addr show ens160 | grep -Po 'inet \K[\d.]+') cat > /etc/etcd/etcd.conf <<EOL #[Member] ETCD_NAME="${PEER_NAME}" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="http://${PRIVATE_IP}:2380" ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379,http://${PRIVATE_IP}:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://${PRIVATE_IP}:2380" ETCD_ADVERTISE_CLIENT_URLS="http://${PRIVATE_IP}:2379" ETCD_INITIAL_CLUSTER="master1=http://192.168.22.101:2380,master2=http://192.168.22.102:2380,master3=http://192.168.22.103:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" EOL
请确保用恰当的 ETCD_INITIAL_CLUSTER 地址: hostname0=<etcd0-ip-address>、 hostname1=<etcd1-ip-address> 和 hostname2=<etcd2-ip-address>。
现在复制 systemd unit 文件,如下所示:
vim /lib/systemd/system/etcd.service [Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target [Service] Type=notify WorkingDirectory=/var/lib/etcd/ EnvironmentFile=-/etc/etcd/etcd.conf User=etcd # set GOMAXPROCS to number of processors ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/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-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\" \ --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" \ --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\"" Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target
同步etcd.service到master2和master3
scp /lib/systemd/system/etcd.service master2:/lib/systemd/system/etcd.service scp /lib/systemd/system/etcd.service master3:/lib/systemd/system/etcd.service
最后,像这样启动 etcd:
systemctl daemon-reload systemctl enable etcd systemctl start etcd
检查它是否成功启动:
systemctl status etcd
服务检查
etcdctl cluster-health member 97404dcac5bcbe95 is healthy: got healthy result from http://192.168.22.101:2379 member f1e382a69d83f82b is healthy: got healthy result from http://192.168.22.102:2379 member f460473152666b51 is healthy: got healthy result from http://192.168.22.103:2379 cluster is healthy
目录 返回
首页