CentOS7安装etcd并部署集群etcdcluster

407 阅读1分钟

CentOS7安装etcd并部署集群etcdcluster

1. github地址

[https://github.com/etcd-io](url)

2. 解压

tar -zxvf etcd-v3.3.8-linux-amd64.tar.gz

3. 在目录中创建data、logs、conf目录

image.png

4. 在conf目录编写配置文件

image.png

name:当前etcd节点名称。
data-dir:数据存储目录。
listen-client-urls:当前节点通过该地址监听客户端发送的信息。
advertise-client-urls:客户端通过该地址与当前节点通信
listen-peer-urls:当前节点通过该地址监听集群其他节点发送的信息。
initial-advertise-peer-urls:集群的其他节点通过该地址与当前节点通信。
initial-cluster:当前集群的所有节点信息,当前节点根据此信息与其他节点取得联系。
initial-cluster-token:用于区分不同的集群,同一集群的所有节点配置相同的值。
initial-cluster-state: 本次是否为新建集群,有两个取值:new和existing。

conf_01.yml

name: etcd01
data-dir: /home/etcd/data
listen-client-urls: http://0.0.0.0:12371
advertise-client-urls: http://0.0.0.0:12371
listen-peer-urls: http://0.0.0.0:12381
initial-advertise-peer-urls: http://0.0.0.0:12381
initial-cluster: etcd01=http://192.168.10.154:12381,etcd02=http://192.168.10.154:12382,etcd03=http://192.168.10.154:12383
initial-cluster-token: etcd-cluster
initial-cluster-state: new

conf_02.yml

name: etcd02
data-dir: /home/etcd/data
listen-client-urls: http://0.0.0.0:12372
advertise-client-urls: http://0.0.0.0:12372
listen-peer-urls: http://0.0.0.0:12382
initial-advertise-peer-urls: http://0.0.0.0:12382
initial-cluster: etcd01=http://192.168.10.154:12381,etcd02=http://192.168.10.154:12382,etcd03=http://192.168.10.154:12383
initial-cluster-token: etcd-cluster
initial-cluster-state: new

conf_03.yml

name: etcd03
data-dir: /home/etcd/data
listen-client-urls: http://0.0.0.0:12373
advertise-client-urls: http://0.0.0.0:12373
listen-peer-urls: http://0.0.0.0:12383
initial-advertise-peer-urls: http://0.0.0.0:12383
initial-cluster: etcd01=http://192.168.10.154:12381,etcd02=http://192.168.10.154:12382,etcd03=http://192.168.10.154:12383
initial-cluster-token: etcd-cluster
initial-cluster-state: new

5. 编写运行脚本

run_01.sh

nohup /home/etcd/etcd --config-file=/home/etcd/conf/conf_01.yml > /home/etcd/logs/etcd_01.log 2>&1 &

run_02.sh

nohup /home/etcd/etcd --config-file=/home/etcd/conf/conf_02.yml > /home/etcd/logs/etcd_02.log 2>&1 &

run_03.sh

nohup /home/etcd/etcd --config-file=/home/etcd/conf/conf_03.yml > /home/etcd/logs/etcd_03.log 2>&1 &

6. 运行sh脚本

./run_01.sh
./run_02.sh
./run_03.sh

更多集群可以按照这种方式累加