ETCD集群初始化及开启身份验证

etcd集群初始化及开启身份验证

各节点信息

主机名ip角色
etcd-1172.17.43.1etcd-1
etcd-2172.17.43.2etcd-2
etcd-3172.17.43.3etcd-3
ETCD_VER=v3.5.7

# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GOOGLE_URL}

rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test

curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download-test --strip-components=1
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

/tmp/etcd-download-test/etcd --version
/tmp/etcd-download-test/etcdctl version
/tmp/etcd-download-test/etcdutl version
  • 初始化集群

有两种方式可以启动集群,一种是通过yml文件启动,一种是通过命令行启动

1. yml方式启动
etcd-1

name: etcd-cluster-1
listen-peer-urls: http://172.17.43.1:2380
listen-client-urls: http://172.17.43.1:2379,http://127.0.0.1:2379
advertise-client-urls: http://etcd-1:2379
initial-advertise-peer-urls: http://etcd-cluster-1:2380
initial-cluster: etcd-1=http://172.17.43.1:2380,etcd-2=http://172.17.43.2:2380,etcd-3=http://172.17.43.3:2380
initial-cluster-state: new
initial-cluster-token: etcd-cluster

etcd-2

name: etcd-cluster-2
listen-peer-urls: http://172.17.43.2:2380
listen-client-urls: http://172.17.43.2:2379,http://127.0.0.1:2379
advertise-client-urls: http://etcd-2:2379
initial-advertise-peer-urls: http://etcd-cluster-2:2380
initial-cluster: etcd-1=http://172.17.43.1:2380,etcd-2=http://172.17.43.2:2380,etcd-3=http://172.17.43.3:2380
initial-cluster-state: new
initial-cluster-token: etcd-cluster

etcd-3

name: etcd-cluster-3
listen-peer-urls: http://172.17.43.3:2380
listen-client-urls: http://172.17.43.3:2379,http://127.0.0.1:2379
advertise-client-urls: http://etcd-3:2379
initial-advertise-peer-urls: http://etcd-cluster-3:2380
initial-cluster: etcd-1=http://172.17.43.1:2380,etcd-2=http://172.17.43.2:2380,etcd-3=http://172.17.43.3:2380
initial-cluster-state: new
initial-cluster-token: etcd-cluster

编辑好配置文件后用下面的命令再各个主机依次启动

nohup etcd --config-file=etcd-1.yml &
nohup etcd --config-file=etcd-2.yml &
nohup etcd --config-file=etcd-3.yml &

2. 命令行方式启动
请参考官方例子,这里不再赘述
https://etcd.io/docs/v3.5/op-guide/clustering/#static

  • 开启身份验证

root用户自带所有权限,因此只需创建该用户,开启认证即有所有权限。

创建root用户

etcdctl --endpoints http://172.17.43.1:2379,http://172.17.43.2:2379,http://172.17.43.3:2379 user add root

随后根据提示设置密码即可
开启身份验证

etcdctl --endpoints http://172.17.43.1:2379,http://172.17.43.2:2379,http://172.17.43.3:2379 auth enable

测试(使用用户)

# 设置
etcdctl  --user='root' --password='root' put name "jinyangh"
# 获取
etcdctl  --user='root' --password='root' get name
name
jinyangh

大功告成!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值