Etcd v3.1.15 在Linux CentOS7 集群配置 (多台电脑机实现)
注意Etcd在每个版本都会有命令或功能变化,看教程时注意版本。
环境:
Node0节点IP:192.168.200.132
Node1节点IP:192.168.200.133
Node2节点IP:192.168.200.134
将Etcd服务端布置到上面3台机器上,集群和每个节点都会生成一个uuid。启动的时候会运行Raft,选举出Leader。
防火墙端口,开放 2379、2380、4001,显示success表示创建成功
[root@Cent0S7]# firewall-cmd --zone=public --add-port=2379/tcp --permanent success [root@Cent0S7]# firewall-cmd --zone=public --add-port=2380/tcp --permanent success [root@Cent0S7]# firewall-cmd --zone=public --add-port=4001/tcp --permanent success [root@Cent0S7]# firewall-cmd --reload success [root@Cent0S7]# firewall-cmd --list-all
Node0节点,将下面配置内容加入之前创建的/etc/etcd.conf 配置文件中。
#节点名称 ETCD_NAME=etcd #缓存数据存放位置 ETCD_DATA_DIR=/var/lib/etcd/ ETCD_LISTEN_PEER_URLS="http://192.168.200.132:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.200.132:2379,http://127.0.0.1:2379" #[cluster] ETCD_HEARTBEAT_INTERVAL="200" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.200.132:2380" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.200.132:2379" ETCD_INITIAL_CLUSTER="etcd=http://192.168.200.132:2380,etcd1=http://192.168.200.133:2380,etcd2=http://192.168.200.134:2380"
ps : 如果不写127.0.0.1或localhost 在测试时 回环地址将被拒绝链接。
Node1节点,将下面配置内容加入之前创建的/etc/etcd.conf 配置文件中。
#节点名称 ETCD_NAME=etcd1 #缓存数据存放位置 ETCD_DATA_DIR=/var/lib/etcd/ ETCD_LISTEN_PEER_URLS="http://192.168.200.133:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.200.133:2379,http://127.0.0.1:2379" #[cluster] ETCD_HEARTBEAT_INTERVAL="200" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.200.133:2380" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.200.133:2379" ETCD_INITIAL_CLUSTER="etcd=http://192.168.200.132:2380,etcd1=http://192.168.200.133:2380,etcd2=http://192.168.200.134:2380"
ps : 如果不写127.0.0.1或localhost 在测试时 回环地址将被拒绝链接。
Node2节点,将下面配置内容加入之前创建的/etc/etcd.conf 配置文件中。
#节点名称 ETCD_NAME=etcd2 #缓存数据存放位置 ETCD_DATA_DIR=/var/lib/etcd/ ETCD_LISTEN_PEER_URLS="http://192.168.200.134:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.200.134:2379,http://127.0.0.1:2379" #[cluster] ETCD_HEARTBEAT_INTERVAL="200" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.200.134:2380" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.200.134:2379" ETCD_INITIAL_CLUSTER="etcd=http://192.168.200.132:2380,etcd1=http://192.168.200.133:2380,etcd2=http://192.168.200.134:2380"
ps : 如果不写127.0.0.1或localhost 在测试时 回环地址将被拒绝链接。
Node0、Node1、Node2节点守护进程 /etc/systemd/system/etcd.service配置
[Unit] Description=Etcd Server Documentation=https://github.com/coreos/etcd After=network.target [Service] User=root Type=notify EnvironmentFile=/etc/etcd.conf ExecStart=/usr/local/sbin/etcd Restart=on-failure RestartSec=10s LimitNOFILE=40000 [Install] WantedBy=multi-user.target
PS:修改配置后,要删除缓存,默认是用之前的缓存启动。
删除缓存文件夹
[root@Cent0S7 ~]# rm -rf /var/lib/etcd/ [root@Cent0S7 ~]# mkdir -p /var/lib/etcd/
刷新配置
[root@Cent0S7 ~]# systemctl daemon-reload
Node0、Node1、Node2节点,分别执行下面命令启动(先启动node节点的ectd服务,然后再启动master端的etcd服务,避免timeout)。
[root@Cent0S7 ~]# systemctl start etcd.service
PS:启动时光标一直闪,也没报错,因为其他节点还没启动,所以在查找,不用管,多开几个SecureCRT的Shell窗口启动每个service就可以了。
验证:在任意一台node上执行都能看到所有member信息
[root@Cent0S7 ~]# etcdctl -w="table" --endpoints=192.168.200.132:2379 member list +------------------+---------+-------+-----------------------------+-----------------------------+------------+ | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER | +------------------+---------+-------+-----------------------------+-----------------------------+------------+ | 724a7b614cfa065 | started | etcd1 | http://192.168.200.133:2380 | http://192.168.200.133:2379 | false | | 171955058e9a4708 | started | etcd2 | http://192.168.200.134:2380 | http://192.168.200.134:2379 | false | | 3942148265deeadf | started | etcd | http://192.168.200.132:2380 | http://192.168.200.132:2379 | false | +------------------+---------+-------+-----------------------------+-----------------------------+------------+
[root@Cent0S7 ~]# etcdctl --write-out=table --endpoints=192.168.200.132:2379,192.168.200.133:2379,192.168.200.134:2379 endpoint status +----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | 192.168.200.132:2379 | 3942148265deeadf | 3.1.15 | 20 kB | false | false | 4 | 9 | 9 | | | 192.168.200.133:2379 | 724a7b614cfa065 | 3.1.15 | 20 kB | false | false | 4 | 9 | 9 | | | 192.168.200.134:2379 | 171955058e9a4708 | 3.1.15 | 20 kB | true | false | 4 | 9 | 9 | | +----------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
在网络上任意一台访问,这段内容是很久之后补充的,所以版本号和上面不一样:
#当前在192.168.200.133服务器上,访问132,可以看到132的etcd版本号 [root@CentOs7-1 ~]# curl -L http://192.168.200.132:2379/version && echo -e "\n" {"etcdserver":"3.4.14","etcdcluster":"3.4.0"}
测试key/value,现在192.168.200.132下执行set get操作
[root@Cent0S7 ~]# etcdctl set /mytest "mytest in 192.168.200.132" mytest in 192.168.200.132 [root@Cent0S7 ~]# etcdctl get /mytest mytest in 192.168.200.132
而后在另一台192.168.111.134下执行get操作,发现数据可以正常同步了
[root@Cent0S7 ~]# etcdctl get /mytest mytest in 192.168.200.132
http://blog.csdn.net/qq_19734597/article/details/108184160?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160691704219195283042295%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=160691704219195283042295&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_v2~rank_blog_default-2-108184160.pc_v2_rank_blog_default&utm_term=etcd&spm=1018.2118.3001.4450
http://blog.csdn.net/mesos/article/details/52759303
http://stackoverrun.com/cn/q/9129852