使用 etcdadm 快速、彈性部署 etcd 集群( 二 )

2、添加節點 192.168.31.39
etcdadm join https://192.168.31.38:2379 \--version "3.5.5" \--init-system "systemd" \--install-dir "/opt/bin/"\--certs-dir"/etc/etcd/pki" \--data-dir "/var/lib/etcd"\--release-url "https://github.com/etcd-io/etcd/releases/download"Etcd Server1、用于 Etcd Server 的環境變量配置 /etc/etcd/etcd.env
ETCD_NAME=c7# Initial cluster configurationETCD_INITIAL_CLUSTER=c7=https://192.168.31.37:2380ETCD_INITIAL_CLUSTER_TOKEN=dee8095fETCD_INITIAL_CLUSTER_STATE=new# Peer configurationETCD_INITIAL_ADVERTISE_PEER_URLS=https://192.168.31.37:2380ETCD_LISTEN_PEER_URLS=https://192.168.31.37:2380ETCD_CLIENT_CERT_AUTH=trueETCD_PEER_CERT_FILE=/etc/etcd/pki/peer.crtETCD_PEER_KEY_FILE=/etc/etcd/pki/peer.keyETCD_PEER_TRUSTED_CA_FILE=/etc/etcd/pki/ca.crt# Client/server configurationETCD_ADVERTISE_CLIENT_URLS=https://192.168.31.37:2379ETCD_LISTEN_CLIENT_URLS=https://192.168.31.37:2379,https://127.0.0.1:2379ETCD_PEER_CLIENT_CERT_AUTH=trueETCD_CERT_FILE=/etc/etcd/pki/server.crtETCD_KEY_FILE=/etc/etcd/pki/server.keyETCD_TRUSTED_CA_FILE=/etc/etcd/pki/ca.crt# OtherETCD_DATA_DIR=/var/lib/etcdETCD_STRICT_RECONFIG_CHECK=trueGOMAXPROCS=8# Logging configuration# Profiling/metrics2、Etcd Server 啟動腳本
# cat /etc/systemd/system/etcd.service[Unit]Description=etcdDocumentation=https://github.com/coreos/etcdConflicts=etcd-member.serviceConflicts=etcd2.service[Service]EnvironmentFile=/etc/etcd/etcd.envExecStart=/opt/bin/etcdType=notifyTimeoutStartSec=0Restart=on-failureRestartSec=5sLimitNOFILE=65536Nice=-10IOSchedulingClass=best-effortIOSchedulingPriority=2MemoryLow=200M[Install]WantedBy=multi-user.targetetcdctl.sh1、用于 etcdctl 的環境變量配置 /etc/etcd/etcdctl.env
export ETCDCTL_API=3export ETCDCTL_CACERT=/etc/etcd/pki/ca.crtexport ETCDCTL_CERT=/etc/etcd/pki/etcdctl-etcd-client.crtexport ETCDCTL_KEY=/etc/etcd/pki/etcdctl-etcd-client.keyexport ETCDCTL_DIAL_TIMEOUT=3s2、腳本 etcdctl.sh 是對 etcdctl 命令的簡單包裝 , 其用法與 etcdctl 一致
cat /opt/bin/etcdctl.sh#!/usr/bin/env shif ! [ -r "/etc/etcd/etcdctl.env" ]; thenecho "Unable to read the etcdctl environment file '/etc/etcd/etcdctl.env'. The file must exist, and this wrapper must be run as root."exit 1fi. "/etc/etcd/etcdctl.env"# 相當于 source 該環境變量配置文件"/opt/bin/etcdctl" "$@"# $@ 表示腳本 etcdctl.sh 的命令行參數管理命令# 查看命令行 init 或 join 的幫助信息etcdadm init|join --help# 從 etcd 集群移除當前節點etcdadm reset# 查看集群節點成員/opt/bin/etcdctl.sh member list# > 19fc11a542653f62, started, c9, https://192.168.31.39:2380, https://192.168.31.39:2379, false# > 9a246c6786d36273, started, c7, https://192.168.31.37:2380, https://192.168.31.37:2379, false# > a509d3d8e8aa4911, started, c8, https://192.168.31.38:2380, https://192.168.31.38:2379, false# 查看當前節點是否正常/opt/bin/etcdctl.sh endpoint health# 127.0.0.1:2379 is healthy: successfully committed proposal: took = 17.112587ms# 查看當前節點狀態/opt/bin/etcdctl.sh endpoint status# > 127.0.0.1:2379, 9a246c6786d36273, 3.5.5, 20 kB, true, false, 3, 10, 10,由于筆者時間、視野、認知有限,本文難免出現錯誤、疏漏等問題,期待各位讀者朋友、業界大佬指正交流, 共同進步 !!
【使用 etcdadm 快速、彈性部署 etcd 集群】

推薦閱讀