实验准备
三台服务器
etcd1: 192.168.70.93
etcd2: 192.168.87.140
etcd3: 192.168.66.23
在etcd01 上运行如下
useradd -M -s /bin/false etcd
cd /usr/local/
wget https://github.com/etcd-io/etcd/releases/download/v3.4.14/etcd-v3.4.14-linux-amd64.tar.gz
tar zxf etcd-v3.4.14-linux-amd64.tar.gz
ln -s etcd-v3.4.14-linux-amd64 etcd
cd etcd
mkdir etc bin data
mv etcd ./bin
mv etcdctl ./bin
ln -s ./bin/etcd /usr/bin/
ln -s ./bin/etcdctl /usr/bin/
cat > ./etc/etcd.json << EOF
{
"name":"etcd1",
"data-dir":"/usr/local/etcd/data",
"listen-peer-urls":"http://192.168.70.93:2380",
"listen-client-urls":"http://192.168.70.93:2379,http://127.0.0.1:2379",
"initial-advertise-peer-urls":"http://192.168.70.93:2380",
"initial-cluster":"etcd1=http://192.168.70.93:2380,etcd2=http://192.168.87.140:2380,etcd3=http://192.168.66.23:2380",
"initial-cluster-state":"new",
"initial-cluster-token":"etcd-cluster-token",
"advertise-client-urls":"http://192.168.70.93:2379"
}
EOF
cat > /usr/lib/systemd/system/etcd.service << EOF
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=simple
Restart=on-failure
LimitNOFILE=40000
User=etcd
WorkingDirectory=/usr/local/etcd/data/
ExecStart=/usr/local/etcd/bin/etcd --config-file=/usr/local/etcd/etc/etcd.json
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
systemctl restart etcd
在etcd02上
和etcd1上的区别是在etcd.json文件的配置
cat > ./etc/etcd.json << EOF
{
"name":"etcd2",
"data-dir":"/usr/local/etcd/data",
"listen-peer-urls":"http://192.168.87.140:2380",
"listen-client-urls":"http://192.168.87.140:2379,http://127.0.0.1:2379",
"initial-advertise-peer-urls":"http://192.168.87.140:2380",
"initial-cluster":"etcd1=http://192.168.70.93:2380,etcd2=http://192.168.87.140:2380,etcd3=http://192.168.66.23:2380",
"initial-cluster-state":"new",
"initial-cluster-token":"etcd-cluster-token",
"advertise-client-urls":"http://192.168.87.140:2379"
}
EOF
在etcd03上
和etcd1上的区别是在etcd.json文件的配置
cat > ./etc/etcd.json << EOF
{
"name":"etcd3",
"data-dir":"/usr/local/etcd/data",
"listen-peer-urls":"http://192.168.66.23:2380",
"listen-client-urls":"http://192.168.66.23:2379,http://127.0.0.1:2379",
"initial-advertise-peer-urls":"http://192.168.66.23:2380",
"initial-cluster":"etcd1=http://192.168.70.93:2380,etcd2=http://192.168.87.140:2380,etcd3=http://192.168.66.23:2380",
"initial-cluster-state":"new",
"initial-cluster-token":"etcd-cluster-token",
"advertise-client-urls":"http://192.168.66.23:2379"
}
EOF
通过etcdctl member list 检查集群状态