ETCD linux C++

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容