1.192.168.10.20
2.192.168.10.30
3.192.168.10.33
节点192.168.10.20
tee /usr/lib/systemd/system/etcd.service <<-'EOF'
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=notify
ExecStart=/usr/local/etcd-v3.5.2-linux-amd64/etcd \
--name=etcd-1 \
--data-dir=/data/etcd/default.etcd \
--listen-peer-urls=https://192.168.10.20:2380 \
--listen-client-urls=https://192.168.10.20:2379 \
--advertise-client-urls=https://192.168.10.20:2379,http://127.0.0.1:2379 \
--initial-advertise-peer-urls=https://192.168.10.20:2380 \
--initial-cluster=etcd-1=https://192.168.10.20:2380,etcd-2=https://192.168.10.30:2380,etcd-3=https://192.168.10.33:2380 \
--initial-cluster-token=etcd-cluster \
--initial-cluster-state=new \
--cert-file=/usr/local/tools/server.pem \
--key-file=/usr/local/tools/server-key.pem \
--peer-cert-file=/usr/local/tools/server.pem \
--peer-key-file=/usr/local/tools/server-key.pem \
--trusted-ca-file=/usr/local/tools/ca.pem \
--peer-trusted-ca-file=/usr/local/tools/ca.pem \
--logger=zap
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
节点192.168.10.30
tee /usr/lib/systemd/system/etcd.service <<-'EOF'
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=notify
#EnvironmentFile=$ETCD_CONF
ExecStart=/usr/local/etcd-v3.5.2-linux-amd64/etcd \
--name=etcd-2 \
--data-dir=/data/etcd/default.etcd \
--listen-peer-urls=https://192.168.10.30:2380 \
--listen-client-urls=https://192.168.10.30:2379 \
--advertise-client-urls=https://192.168.10.30:2379,http://127.0.0.1:2379 \
--initial-advertise-peer-urls=https://192.168.10.30:2380 \
--initial-cluster=etcd-1=https://192.168.10.20:2380,etcd-2=https://192.168.10.30:2380,etcd-3=https://192.168.10.33:2380 \
--initial-cluster-token=etcd-cluster \
--initial-cluster-state=new \
--cert-file=/usr/local/tools/server.pem \
--key-file=/usr/local/tools/server-key.pem \
--peer-cert-file=/usr/local/tools/server.pem \
--peer-key-file=/usr/local/tools/server-key.pem \
--trusted-ca-file=/usr/local/tools/ca.pem \
--peer-trusted-ca-file=/usr/local/tools/ca.pem \
--logger=zap
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
节点192.168.10.33
tee /usr/lib/systemd/system/etcd.service <<-'EOF'
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=notify
#EnvironmentFile=$ETCD_CONF
ExecStart=/usr/local/etcd-v3.5.2-linux-amd64/etcd \
--name=etcd-3 \
--data-dir=/data/etcd/default.etcd \
--listen-peer-urls=https://192.168.10.33:2380 \
--listen-client-urls=https://192.168.10.33:2379 \
--advertise-client-urls=https://192.168.10.33:2379,http://127.0.0.1:2379 \
--initial-advertise-peer-urls=https://192.168.10.33:2380 \
--initial-cluster=etcd-1=https://192.168.10.20:2380,etcd-2=https://192.168.10.30:2380,etcd-3=https://192.168.10.33:2380 \
--initial-cluster-token=etcd-cluster \
--initial-cluster-state=new \
--cert-file=/usr/local/tools/server.pem \
--key-file=/usr/local/tools/server-key.pem \
--peer-cert-file=/usr/local/tools/server.pem \
--peer-key-file=/usr/local/tools/server-key.pem \
--trusted-ca-file=/usr/local/tools/ca.pem \
--peer-trusted-ca-file=/usr/local/tools/ca.pem \
--logger=zap
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
启动
systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
systemctl status etcd
客户端查询
etcdctl --endpoints="https://192.168.10.20:2379",https://192.168.10.30:2379,https://192.168.10.33:2379 \
--cacert=/usr/local/tools/ca.pem \
--cert=/usr/local/tools/server.pem \
--key=/usr/local/tools/server-key.pem \
endpoint status -w table
目前192.168.10.33节点为主
etcdctl --endpoints="https://192.168.10.20:2379",https://192.168.10.30:2379,https://192.168.10.33:2379 \
--cacert=/usr/local/tools/ca.pem \
--cert=/usr/local/tools/server.pem \
--key=/usr/local/tools/server-key.pem \
endpoint health