码迷,mamicode.com
首页 > 其他好文 > 详细

etcd集群的搭建

时间:2018-05-21 16:16:34      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:directory   数据保存   节点   exe   ip地址   target   列表   stat   listen   

由于最近在学习kubernetes,etcd作为kubernetes集群的主数据库,必须先启动。

etcds实例名称 IP地址 Hostname
etcd 1 192.168.142.161 kubernetes-node1.example.com
etcd 2 192.168.142.162 kubernetes-node2.example.com
etcd 3 192.168.142.163 kubernetes-node3.example.com
从GitHub官网上下载etcd发布的二进制文件,etcd和etcdctl文件复制到/usr/bin目录。
  • 设置systemd服务文件。
vim /usr/lib/systemd/system/etcd.service
内容如下:
[Unit]
Description=Etcd Server
After=network.target


[Service]
Type=simple
WorkingDirectory=/var/lib/etcd/   
EnvironmentFile=-/etc/etcd/etcd.conf #配置文件路径
ExecStart=/usr/bin/etcd
Type=notify
[Install]
WantedBy=multi-user.target
  • 编写/etc/etcd/etcd.conf文件
vim /etc/etcd/etcd.conf
# [member]
ETCD_NAME=etcd1   #etcd实例名称
ETCD_DATA_DIR="/var/lib/etcd"  #etcd数据保存目录
ETCD_LISTEN_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379"
#供外部客户端使用的url
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379"
#广播给外部客户端使用的url

#[cluster]
ETCD_LISTEN_PEER_URLS="http://192.168.142.161:2380"   #集群内部通信使用的URL
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.142.161:2380"
#广播给集群内其他成员访问的URL
ETCD_INITIAL_CLUSTER="etcd1=http://192.168.142.161:2380,etcd2=http://192.168.142.162:2380,etcd3=http://192.168.142.163:2380"
#初始集群成员列表
ETCD_INITIAL_CLUSTER_STATE="new"
#初始集群状态,new为新建集群
ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster"  #集群的名称
  • 启动etcd1服务器上的etcd服务。

    systemctl restart etcd
  • etcd2和etcd3为加入k8s-etcd-cluster集群的实例,需要将其ETCD_INITIAL_CLUSTER_STATE设置为"exist"。etcd2的完整配置如下:

# [member]
ETCD_NAME=etcd2
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_LISTEN_CLIENT_URLS="http://192.168.142.162:2379,http://127.0.0.1:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.142.162:2379,http://127.0.0.1:2379"

#[cluster]
ETCD_LISTEN_PEER_URLS="http://192.168.142.162:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.142.162:2380"
ETCD_INITIAL_CLUSTER="etcd1=http://192.168.142.161:2380,etcd2=http://192.168.142.162:2380,etcd3=http://192.168.142.163:2380"
ETCD_INITIAL_CLUSTER_STATE="exist"
ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster"
  • 启动etcd2和etcd3服务器上的etcd服务。

    systemctl restart etcd

    启动完成后,在任意节点执行etcdctl cluster-healthy命令来查看运行状态。

    使用etcdctl member list 来查看集群中的成员列表。

另外一种安装方法
etcd集群搭建
下载二进制软件包
https://github.com/coreos/etcd/releases   

解压

将两个执行文件复制到/usr/bin/
etcd和etcdctl文件复制到/usr/bin目录

配置etcd-1

vi /etc/etcd/etcd.yml


name: etcd-1
data-dir: /var/lib/etcd
listen-client-urls: http://163.44.167.92:2379,http://127.0.0.1:2379
advertise-client-urls: http://163.44.167.92:2379,http://127.0.0.1:2379
listen-peer-urls: http://163.44.167.92:2380
initial-advertise-peer-urls: http://163.44.167.92:2380
initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

配置etcd-2

vi /etc/etcd/etcd.yml
name: etcd-2
data-dir: /var/lib/etcd
listen-client-urls: http://150.95.148.52:2379,http://127.0.0.1:2379
advertise-client-urls: http://150.95.148.52:2379,http://127.0.0.1:2379
listen-peer-urls: http://150.95.148.52:2380
initial-advertise-peer-urls: http://150.95.148.52:2380
initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new


配置etcd-3
name: etcd-3
data-dir: /var/lib/etcd
listen-client-urls: http://133.130.122.48:2379,http://127.0.0.1:2379
advertise-client-urls: http://133.130.122.48:2379,http://127.0.0.1:2379
listen-peer-urls: http://133.130.122.48:2380
initial-advertise-peer-urls: http://133.130.122.48:2380
initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new



最后启动
etcd --config-file=/etc/etcd/etcd.yml &

查看成员
etcdctl member list
每个节点上执行查看健康状态
etcdctl cluster-health

etcd集群的搭建

标签:directory   数据保存   节点   exe   ip地址   target   列表   stat   listen   

原文地址:https://www.cnblogs.com/skymyyang/p/9067280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!