etcd v3 集群——简单配置

本文介绍了etcdv3的安装步骤及集群配置方法,包括如何设置环境变量、配置集群参数等,并通过实例展示了如何使用etcdctl工具进行集群健康检查及键值操作。

一、etcd v3安装:

tar -axf etcd-v3.2.0-linux-amd64.tar.gz -C /usr/local/src/
chmod a+x /usr/local/src/etcd-v3.2.0-linux-amd64/etcd*
cp -a /usr/local/src/etcd-v3.2.0-linux-amd64/etcd* /usr/local/bin/

 

 

 

#如果不设置 ETCDCTL_API=3,则默认是的API版本是2

export ETCDCTL_API=3
echo 'export ETCDCTL_API=3' >> /etc/profile

二、集群配置:

        单机,双点,可根据实际情况修改端口

#node1

etcd -name perofu1 -debug \
-initial-advertise-peer-urls http://0.0.0.0:2380 \
-listen-peer-urls http://0.0.0.0:2380 \
-listen-client-urls http://0.0.0.0:2379 \
-advertise-client-urls http://0.0.0.0:2379 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster perofu1=http://0.0.0.0:2380,perofu2=http://0.0.0.0:4380 \
-initial-cluster-state new  >> /var/log/kubernetes/test-etcd.log 2>&1 &

#node2

etcd -name perofu2 -debug \
-initial-advertise-peer-urls http://0.0.0.0:4380 \
-listen-peer-urls http://0.0.0.0:4380 \
-listen-client-urls http://0.0.0.0:4379 \
-advertise-client-urls http://0.0.0.0:4379 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster perofu1=http://0.0.0.0:2380,perofu2=http://0.0.0.0:4380 \
-initial-cluster-state new  >> /var/log/kubernetes/test-etcd-1.log 2>&1 &

        参数说明

● –data-dir 指定节点的数据存储目录,若不指定,则默认是当前目录。这些数据包括节点ID,集群ID,集群初始化配置,Snapshot文件,若未指 定–wal-dir,还会存储WAL文件
● –wal-dir 指定节点的was文件存储目录,若指定了该参数,wal文件会和其他数据文件分开存储
● –name 节点名称
● –initial-advertise-peer-urls 告知集群其他节点的URL,tcp 2380端口用于集群通信
● –listen-peer-urls 监听URL,用于与其他节点通讯
● –advertise-client-urls 告知客户端的URL, 也就是服务的URL,tcp 2379端口用于监听客户端请求
● –initial-cluster-token 集群的ID
● –initial-cluster 集群中所有节点
● –initial-cluster-state 集群状态,new为新创建集群,existing为已存在的集群

三、实例:

[root@www ~]# curl -s http://192.168.0.211:2379/v2/machines
http://0.0.0.0:2379, http://0.0.0.0:4379
[root@www ~]#
[root@www ~]# etcdctl member list
25a7dd0a87b3530: name=perofu2 peerURLs=http://0.0.0.0:4380 clientURLs=http://0.0.0.0:4379 isLeader=false
2006f2ad47deea09: name=perofu1 peerURLs=http://0.0.0.0:2380 clientURLs=http://0.0.0.0:2379 isLeader=true

[root@www ~]#
[root@www ~]# etcdctl cluster-health
member 25a7dd0a87b3530 is healthy: got healthy result from http://0.0.0.0:4379
member 2006f2ad47deea09 is healthy: got healthy result from http://0.0.0.0:2379

cluster is healthy

#设置key
[root@www ~]# etcdctl --endpoints "http://127.0.0.1:2379" set api_server  http://192.168.0.211:8080
http://192.168.0.211:8080
[root@www ~]#
[root@www ~]# etcdctl --endpoints "http://127.0.0.1:2379" get api_server
http://192.168.0.211:8080
[root@www ~]#
[root@www ~]# etcdctl --endpoints "http://127.0.0.1:4379" get api_server
http://192.168.0.211:8080
[root@www ~]#

转载于:https://my.oschina.net/fufangchun/blog/1499682

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值