Linux:安装etcd集群
特别注意!!!
集群部署时,各节点主机的2379、2380是相互联通的,注意防火墙设置,否则将导致集群搭建失败。
1.部署环境
1.1.主机信息
主机 | IP |
---|---|
node1 | 192.168.75.128 |
node2 | 192.168.75.129 |
node3 | 192.168.75.130 |
1.2.系统版本
# cat /etc/redhat-release
CentOS release 6.8 (Final)
# cat /proc/version
Linux version 2.6.32-642.el6.x86_64 (mockbuild@worker1.bsys.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) ) #1 SMP Tue May 10 17:27:01 UTC 2016
1.3.软件版本
etcd各个tag版本地址:
https://github.com/etcd-io/etcd/tags
我是用的版本是:v3.4.14
https://github.com/etcd-io/etcd/releases/tag/v3.4.14
选择对应架构的安装包:
https://github.com/etcd-io/etcd/releases/download/v3.4.14/etcd-v3.4.14-linux-amd64.tar.gz
2.安装步骤
2.1.新建etcd账户
# useradd -d /home/etcd -m etcd
# passwd etcd
2.2.下载etcd安装包
# su - etcd
$ wget https://github.com/etcd-io/etcd/releases/download/v3.4.14/etcd-v3.4.14-linux-amd64.tar.gz
2.3.解压etcd安装包
$ tar zxf etcd-v3.4.14-linux-amd64.tar.gz
$ ll
total 16972
drwxr-xr-x. 3 etcd etcd 4096 Nov 25 12:27 etcd-v3.4.14-linux-amd64
-rw-rw-r--. 1 etcd etcd 17373058 Nov 25 12:35 etcd-v3.4.14-linux-amd64.tar.gz
2.4.配置环境变量
$ echo 'PATH=$HOME/etcd-v3.4.14-linux-amd64:$PATH' >> $HOME/.bash_profile
退出当前终端,重新登陆etcd账户。
2.5.启动etcd进程
在 node1 创建脚本 start-etcd.sh:
#/bin/bash
NODE1=192.168.75.128
NODE2=192.168.75.129
NODE3=192.168.75.130
TOKEN=test1280
nohup etcd \
--name node1 \
--initial-advertise-peer-urls http://$NODE1:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://$NODE1:2379 \
--initial-cluster-token $TOKEN \
--initial-cluster node1=http://$NODE1:2380,node2=http://$NODE2:2380,node3=http://$NODE3:2380 \
--initial-cluster-state new >/dev/null 2>&1 &
在 node2 创建脚本 start-etcd.sh:
#/bin/bash
NODE1=192.168.75.128
NODE2=192.168.75.129
NODE3=192.168.75.130
TOKEN=test1280
nohup etcd \
--name node2 \
--initial-advertise-peer-urls http://$NODE2:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://$NODE2:2379 \
--initial-cluster-token $TOKEN \
--initial-cluster node1=http://$NODE1:2380,node2=http://$NODE2:2380,node3=http://$NODE3:2380 \
--initial-cluster-state new >/dev/null 2>&1 &
在 node3 创建脚本 start-etcd.sh:
#/bin/bash
NODE1=192.168.75.128
NODE2=192.168.75.129
NODE3=192.168.75.130
TOKEN=test1280
nohup etcd \
--name node3 \
--initial-advertise-peer-urls http://$NODE3:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://$NODE3:2379 \
--initial-cluster-token $TOKEN \
--initial-cluster node1=http://$NODE1:2380,node2=http://$NODE2:2380,node3=http://$NODE3:2380 \
--initial-cluster-state new >/dev/null 2>&1 &
在 etcd@node1 & etcd@node2 & etcd@node3 分别启动脚本:
$ bash start-etcd.sh
2.6.查看etcd节点状态
etcdctl endpoint status
$ etcdctl endpoint status -w table --endpoints='192.168.75.128:2379,192.168.75.129:2379,192.168.75.130:2379'
+---------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+---------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 192.168.75.128:2379 | 15285f311847b1b | 3.4.14 | 20 kB | true | false | 3 | 9 | 9 | |
| 192.168.75.129:2379 | e841a27314d3aab6 | 3.4.14 | 25 kB | false | false | 3 | 9 | 9 | |
| 192.168.75.130:2379 | 44c97a848b40993 | 3.4.14 | 25 kB | false | false | 3 | 9 | 9 | |
+---------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
注意:
192.168.75.128 的 IS LEADER 字段是 true,代表其为 master 节点,其余的是 slaver 节点。
etcdctl member list
$ etcdctl --endpoints="192.168.75.128:2379,192.168.75.129:2379,192.168.75.130:2379" member list -w table
+------------------+---------+-------+----------------------------+----------------------------+------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
+------------------+---------+-------+----------------------------+----------------------------+------------+
| 15285f311847b1b | started | node1 | http://192.168.75.128:2380 | http://192.168.75.128:2379 | false |
| 44c97a848b40993 | started | node3 | http://192.168.75.130:2380 | http://192.168.75.130:2379 | false |
| e841a27314d3aab6 | started | node2 | http://192.168.75.129:2380 | http://192.168.75.129:2379 | false |
+------------------+---------+-------+----------------------------+----------------------------+------------+
参考:
https://github.com/etcd-io/etcd/blob/master/Documentation/demo.md