ETCD集群安装配置

一、环境准备

CentOS7
etcd-v3.3.10

部署架构
192.168.0.101 节点1
192.168.0.102 节点2
192.168.0.103 节点3

二、ETCD安装配置

1,下载

https://github.com/etcd-io/etcd/releases

$wget https://github.com/etcd-io/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz

2,安装:

解压

$tar zxvf etcd-v3.3.10-linux-amd64.tar.gz

安装

$sudo mkdir -p /k8s/etcd/bin
$cd etcd-v3.3.10-linux-amd64
$cp etcd etcdctl /k8s/etcd/bin/

etcd环境变量文件

mkdir -p /k8s/etcd/data
$cat << EOF | tee /k8s/etcd/etcd.conf
name: ETCD-1
data-dir: /k8s/etcd/data
listen-client-urls: http://192.168.0.101:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.0.101:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.0.101:2380,http://127.0.0.1:2380
#initial-advertise-peer-urls: http://192.168.0.101:2380
#initial-cluster: ETCD-1=http://192.168.0.101:2380,ETCD-2=http://192.168.0.102:2380,ETCD-3=http://192.168.0.103:2380
initial-cluster-token: etcd-cluster-token

EOF

主要配置说明:

配置 说明
ETCD_NAME 节点名称 默认为default,本例中三台机器分别为:etcd-node01,etcd-node02,etcd-node03
ETCD_DATA_DIR 服务运行数据保存的路径 本例中指定独立分区,/etcd_data
ETCD_LISTEN_PEER_URLS 监听的同伴通信的地址 比如http://ip:2380,如果有多个,使用逗号分隔。需要所有节点都能够访问,所以不要使用 localhost!
ETCD_LISTEN_CLIENT_URLS 监听的客户端服务地址
ETCD_ADVERTISE_CLIENT_URLS 对外公告的该节点客户端监听地址,这个值会告诉集群中其他节点。
ETCD_INITIAL_ADVERTISE_PEER_URLS 对外公告的该节点同伴监听地址,这个值会告诉集群中其他节点
ETCD_INITIAL_CLUSTER 集群中所有节点的信息,格式为node1=http://ip1:2380,node2=http://ip2:2380,…,注意:这里的 node1 是节点的 —name 指定的名字;后面的 ip1:2380 是 —initial-advertise-peer-urls 指定的值。
ETCD_INITIAL_CLUSTER_STATE 新建集群的时候,这个值为 new;假如加入已经存在的集群,这个值为 existing。
ETCD_INITIAL_CLUSTER_TOKEN 集群的ID,多个集群的时候,每个集群的ID必须保持唯一,否则会引发不可知错误,可以访问 https://discovery.etcd.io/new 生成一个token。

三、ETCD命令

1,查看版本信息

$/k8s/etcd/bin/etcdctl -version
etcdctl version: 3.3.10
API version: 2

2,启动命令

$/k8s/etcd/bin/etcd /k8s/etcd/bin/etcd --config-file=/k8s/etcd/etcd.conf &

查看:

&/k8s/etcd/bin/etcdctl cluster-health 
member f9f108f1db929b9f is healthy: got healthy result from http://127.0.0.1:2379
cluster is healthy

3,其他命令

请参考: http://www.xmoot.com/7zz.html

四、配置ETCD为启动服务

1,编辑Vim /usr/lib/systemd/system/etcd.service

添加下面内容:

[Unit]
Description=etcd.service
[Service]
Type=notify
TimeoutStartSec=0
Restart=always
WorkingDirectory=/k8s/etcd/

ExecStart=/k8s/etcd/bin/etcd  --config-file=/k8s/etcd/etcd.conf

[Install]
WantedBy=multi-user.target

2,配置启动项:

systemctl daemon-reload #重载 `/usr/lib/systemd/system` 的配置文件
#systemctl enable etcd
systemctl start etcd //启动
systemctl restart etcd //重启
systemctl stop etcd //重启
systemctl status etcd.service -l //查看状态

五、其他节点设置

1,节点2 [ip=192.168.0.102]

name: ETCD-2
data-dir: /k8s/etcd/data
listen-client-urls: http://192.168.0.102:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.0.102:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.0.102:2380,http://127.0.0.1:2380
initial-advertise-peer-urls: http://192.168.0.102:2380
initial-cluster: ETCD-1=http://192.168.0.101:2380,ETCD-2=http://192.168.0.102:2380,ETCD-3=http://192.168.0.103:2380
initial-cluster-token: etcd-cluster-token

2,节点3 [ip=192.168.0.103]

name: ETCD-3
data-dir: /k8s/etcd/data
listen-client-urls: http://192.168.0.103:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.0.103:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.0.103:2380,http://127.0.0.1:2380
initial-advertise-peer-urls: http://192.168.0.102:2380
initial-cluster: ETCD-1=http://192.168.0.101:2380,ETCD-2=http://192.168.0.102:2380,ETCD-3=http://192.168.0.103:2380
initial-cluster-token: etcd-cluster-token

注意:测试集群是别忘了把 节点1initial-advertise-peer-urlsinitial-cluster 注释 # 去掉。

ph.w
ph.w 11个月前

已被 1 人挖起

回应
登录 后发表评论
  • 消灭零回应