linux(centos)部署etcd集群

2 篇文章 0 订阅
2 篇文章 0 订阅

转载请注明出处:https://blog.csdn.net/sublio/article/details/112888870

注:

本文是在单台机器上搭建集群,多台搭建同理且更简单,因为不用考虑端口以及各种目录冲突问题,配置几乎大多一样,细微差别会在文中指出。

下载解压

cd /opt
wget https://github.com/etcd-io/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz
tar zxvf etcd-v3.3.10-linux-amd64.tar.gz
mv etcd-v3.3.10-linux-amd64 etcd
cd etcd

配置文件准备

个别需要注意的配置文件描述:

#name: 节点名,区分各个节点
#initial-cluster: 集群配置,这里会用到各个节点的name
#整三份配置文件
mkdir config
vim config/etcd01.yaml
vim config/etcd02.yaml
vim config/etcd03.yaml
#etcd01.yaml
name: etcd-1
data-dir: /data/etcd01
listen-client-urls: http://ip1:2379,http://127.0.0.1:2379
advertise-client-urls: http://ip1:2379,http://127.0.0.1:2379
listen-peer-urls: http://ip1:2380
initial-advertise-peer-urls: http://ip1:2380
initial-cluster: etcd-1=http://ip1:2380,etcd-2=http://ip2:2480,etcd-3=http://ip3:2580
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
enable-v2: true
#etcd02.yaml
name: etcd-2
data-dir: /data/etcd02
listen-client-urls: http://ip2:2479,http://127.0.0.1:2479
advertise-client-urls: http://ip2:2479,http://127.0.0.1:2479
listen-peer-urls: http://ip2:2480
initial-advertise-peer-urls: http://ip2:2480
initial-cluster: etcd-1=http://ip1:2380,etcd-2=http://ip2:2480,etcd-3=http://ip3:2580
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
enable-v2: true
#etcd03.yaml
name: etcd-3
data-dir: /data/etcd03
listen-client-urls: http://ip3:2579,http://127.0.0.1:2579
advertise-client-urls: http://ip3:2579,http://127.0.0.1:2579
listen-peer-urls: http://ip3:2580
initial-advertise-peer-urls: http://ip3:2580
initial-cluster: etcd-1=http://ip1:2380,etcd-2=http://ip2:2480,etcd-3=http://ip3:2580
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
enable-v2: true

 启动(这里用的是supercisor)

配置如下:

#vim /etc/supervisord.d/etcd01.ini
[program:etcd01]
command = /opt/etcd/etcd --config-file /opt/etcd/config/etcd01.yaml
autostart = true
startsecs = 5
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /data/etcd01-log/etcd.log
#vim /etc/supervisord.d/etcd02.ini
[program:etcd02]
command = /opt/etcd/etcd --config-file /opt/etcd/config/etcd02.yaml
autostart = true
startsecs = 5
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /data/etcd02-log/etcd.log
#vim /etc/supervisord.d/etcd03.ini
[program:etcd03]
command = /opt/etcd/etcd --config-file /opt/etcd/config/etcd03.yaml
autostart = true
startsecs = 5
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /data/etcd03-log/etcd.log

 重新载入supervisor下所有服务

supervisorctl
#进入之后
reload

测试是否搭建成功

#因为--endpoints=是3的用法(大概)
export ETCDCTL_API=3
#put
/opt/etcd/etcdctl --endpoints=[ip1:2379,ip2:2479,ip3:2579] put test1 value1
#get
/opt/etcd/etcdctl --endpoints=[ip1:2379,ip2:2479,ip3:2579] get test1

开启用户认证,参考:

https://blog.csdn.net/ucmir183/article/details/84454506

https://blog.csdn.net/weixin_45541368/article/details/103846584

#创建root角色
/opt/etcd/etcdctl role add root --endpoints=[addr,逗号分隔]
#创建root用户(这里需要输入密码并确认)
/opt/etcd/etcdctl user add root --endpoints=[addr,逗号分隔]
#给root用户赋予root角色
/opt/etcd/etcdctl user grant-role root root --endpoints=[addr,逗号分隔]
#开启auth
/opt/etcd/etcdctl auth enable --endpoints=[addr,逗号分隔]

#赋予角色root
/opt/etcd/etcdctl role grant-permission root --prefix=true readwrite / --endpoints=[addr,逗号分隔]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值