Target:Create 4 sites cluster on 3 machines
1、download ETCD
ETCD_VER=v3.4.2
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GITHUB_URL}
wget ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar -zxvf ./etcd-v3.4.2-linux-amd64.tar.gz
mkdir /usr/local/etcd
cp ./etcd-v3.4.2-linux-amd64/etcd* /usr/local/etcd
# maybe need to add the Env-PATH:/usr/local/etcd
sudo vi /etc/profile
export PATH=$PATH:/usr/local/etcd
source /etc/profile
2、run the following commands
(0)run the following commands one 4 cmd(represent 4 sites)
TOKEN=token-01
CLUSTER_STATE=new
NAME_1=s1
NAME_2=s2
NAME_3=s3
NAME_4=s4
HOST_1=10.46.79.184
HOST_2=10.46.219.70
HOST_3=10.47.201.61
HOST_4=10.47.201.61
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380,${NAME_4}=http://${HOST_4}:22380
(1)site1
THIS_NAME=${NAME_1}
THIS_IP=${HOST_1}
etcd --data-dir=data.etcd --name${THIS_NAME}\
--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
--initial-cluster${CLUSTER}\
--initial-cluster-state${CLUSTER_STATE}--initial-cluster-token${TOKEN}
(2)site 2
THIS_NAME=${NAME_2}
THIS_IP=${HOST_2}
etcd --data-dir=data.etcd --name${THIS_NAME}\
--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
--initial-cluster${CLUSTER}\
--initial-cluster-state${CLUSTER_STATE}--initial-cluster-token${TOKEN}
(3)site 3
THIS_NAME=${NAME_3}
THIS_IP=${HOST_3}
etcd --data-dir=data.etcd --name${THIS_NAME}\
--initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
--advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
--initial-cluster${CLUSTER}\
--initial-cluster-state${CLUSTER_STATE}--initial-cluster-token${TOKEN}
(4)site 4(on machine 3,different folder with site3)
THIS_NAME=${NAME_4}
THIS_IP=${HOST_4}
etcd --data-dir=data.etcd --name${THIS_NAME}\
--initial-advertise-peer-urls http://${THIS_IP}:22380 --listen-peer-urls http://${THIS_IP}:22380 \
--advertise-client-urls http://${THIS_IP}:22379 --listen-client-urls http://${THIS_IP}:22379 \
--initial-cluster${CLUSTER}\
--initial-cluster-state${CLUSTER_STATE}--initial-cluster-token${TOKEN}
END:now, we have created the ETCD cluster, If needed, you can test the cluster by the following commands.
etcdctl --endpoints=110.46.79.184:2379 put foo hello
etcdctl --endpoints=110.46.79.184:2379 get foo