一、环境准备

  • CentOS Linux release 7.3.1611 (Core)
  • etcd-v3.2.6

二、ETCD下载

https://github.com/coreos/etcd/releases/download/v3.2.6/etcd-v3.2.6-linux-amd64.tar.gz

三、ETCD安装配置

1.部署架构

  • 192.168.108.128 节点1
  • 192.168.108.129 节点2
  • 192.168.108.130 节点3

2.解压安装:

$ tar -zxvf  etcd-v3.2.6-linux-amd64.tar.gz -C /opt/
$ cd /opt
$ mv etcd-v3.2.6-linux-amd64  etcd-v3.2.6
# 创建etcd配置文件目录
$ mkdir /etc/etcd           

3.创建etcd配置文件:

$ vi /etc/etcd/conf.yml

节点1,添加如下内容:

name: etcd-1
data-dir: /opt/etcd-v3.2.6/data
listen-client-urls: http://192.168.108.128:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.108.128:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.108.128:2380
initial-advertise-peer-urls: http://192.168.108.128:2380
initial-cluster: etcd-1=http://192.168.108.128:2380,etcd-2=http://192.168.108.129:2380,etcd-3=http://192.168.108.130:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

节点2,添加如下内容:

name: etcd-2
data-dir: /opt/etcd-v3.2.6/data
listen-client-urls: http://192.168.108.129:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.108.129:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.108.129:2380
initial-advertise-peer-urls: http://192.168.108.129:2380
initial-cluster: etcd-1=http://192.168.108.128:2380,etcd-2=http://192.168.108.129:2380,etcd-3=http://192.168.108.130:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

节点3,添加如下内容:

name: etcd-3
data-dir: /opt/etcd-v3.2.6/data
listen-client-urls: http://192.168.108.130:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.108.130:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.108.130:2380
initial-advertise-peer-urls: http://192.168.108.130:2380
initial-cluster: etcd-1=http://192.168.108.128:2380,etcd-2=http://192.168.108.129:2380,etcd-3=http://192.168.108.130:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

4.更新etcd系统默认配置:

当前使用的是etcd v3版本,系统默认的是v2,通过下面命令修改配置。

$ vi /etc/profile

在文件末尾追加:

export ETCDCTL_API=3

使文件生效:

$ source /etc/profile

四、ETCD命令

$ cd  /opt/etcd-v3.2.6

1.查看版本信息:

$ ./etcdctl versionetcdctl version: 3.2.6
API version: 3.2

2.启动命令:

$ ./etcd --config-file=/etc/etcd/conf.yml

3.查看集群成员信息:

$ ./etcdctl member list2618ce5cd761aa8e: name=etcd-3 peerURLs=http://192.168.108.130:2380 clientURLs=http://127.0.0.1:2379,http://192.168.108.130:2379 isLeader=false
9c359d48a2f34938: name=etcd-1 peerURLs=http://192.168.108.128:2380 clientURLs=http://127.0.0.1:2379,http://192.168.108.128:2379 isLeader=false
f3c45714407d68f3: name=etcd-2 peerURLs=http://192.168.108.129:2380 clientURLs=http://127.0.0.1:2379,http://192.168.108.129:2379 isLeader=true

4.查看集群状态(Leader节点):

$ ./etcdctl cluster-healthmember 2618ce5cd761aa8e is healthy: got healthy result from http://127.0.0.1:2379
member 9c359d48a2f34938 is healthy: got healthy result from http://127.0.0.1:2379
member f3c45714407d68f3 is healthy: got healthy result from http://127.0.0.1:2379
cluster is healthy

5.HTTPS加密下使用etcdctl检查集群健康状况:

$ etcdctl --ca-file /etc/ssl/etcd/ca.pem --cert-file /etc/ssl/etcd/server1.pem --key-file /etc/ssl/etcd/server1-key.pem member list
$ etcdctl --ca-file /etc/ssl/etcd/ca.pem --cert-file /etc/ssl/etcd/server1.pem --key-file /etc/ssl/etcd/server1-key.pem cluster-health

五、ECTD读写操作

基于HTTP协议的API使用起来比较简单,这里主要通过etcdctl和curl两种方式来做简单介绍。

1.下面通过给message key设置Hello值示例:

$ ./etcdctl set /message HelloHello$ curl -X PUT http://127.0.0.1:2379/v2/keys/message -d value="Hello"
{"action":"set","node":{"key":"/message","value":"Hello","modifiedIndex":4,"createdIndex":4}}

2.读取message的值:

$ ./etcdctl  get /message
Hello$ curl http://127.0.0.1:2379/v2/keys/message
{"action":"get","node":{"key":"/message","value":"Hello","modifiedIndex":9,"createdIndex":9}}

3.删除message key:

$ ./etcdctl  rm  /message$ curl -X DELETE http://127.0.0.1:2379/v2/keys/message
{"action":"delete","node":{"key":"/message","modifiedIndex":10,"createdIndex":9},"prevNode":{"key":"/message","value":"Hello","modifiedIndex":9,"createdIndex":9}}

说明:因为是集群,所以message在其中一个节点创建后,在集群中的任何节点都可以查询到。

4.查看所有key-value:

curl -s http://127.0.0.1:2379/v2/keys/?recursive=true

六、配置ETCD为启动服务

1.编辑/usr/lib/systemd/system/etcd.service,添加下面内容:

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target[Service]
Type=notify
WorkingDirectory=/opt/etcd-v3.2.6/
# User=etcd
ExecStart=/opt/etcd-v3.2.6/etcd --config-file=/etc/etcd/conf.yml
Restart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target

2.更新启动:

systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
systemctl restart etcdsystemctl status etcd.service -l

参考资料:

https://coreos.com/etcd/docs/latest/getting-started-with-etcd.html

ETCD集群安装配置及简单应用相关推荐

  1. 一步步教你Hadoop多节点集群安装配置

    一步步教你Hadoop多节点集群安装配置 1.集群部署介绍 1.1 Hadoop简介  Hadoop是Apache软件基金会旗下的一个开源分布式计算平台.以Hadoop分布式文件系统HDFS(Hado ...

  2. 原创:centos7.1下 ZooKeeper 集群安装配置+Python实战范例

    centos7.1下 ZooKeeper 集群安装配置+Python实战范例 下载:http://apache.fayea.com/zookeeper/zookeeper-3.4.9/zookeepe ...

  3. websphere一直安装部署_WebSphere集群安装配置及部署应用说明

    <WebSphere集群安装配置及部署应用说明>由会员分享,可在线阅读,更多相关<WebSphere集群安装配置及部署应用说明(27页珍藏版)>请在人人文库网上搜索. 1.We ...

  4. RabbitMQ集群安装配置+HAproxy+Keepalived高可用

    RabbitMQ集群安装配置+HAproxy+Keepalived高可用 转自:https://www.linuxidc.com/Linux/2016-10/136492.htm rabbitmq 集 ...

  5. ZooKeeper-3.3.4集群安装配置

    "ZooKeeper-3.3.4集群安装配置": 关键词:zookeeper-3.3.4 集群 安装 配置 zookeeper是一个分布式开源框架,提供了协调分布式应用的基本服务, ...

  6. Openpbs centos7集群安装配置心得

    Openpbs centos7集群安装配置心得 写在前面 准备工作 1.安装虚拟机 2.创建虚拟机集群 SSH免密登陆 网络环境配置 ssh免密登陆 建立NFS共享目录 关闭各节点防火墙和Selinu ...

  7. ElasticSearch-2.0.0集群安装配置与API使用实践

    ElasticSearch是基于全文搜索引擎库Lucene构建的分布式搜索引擎,我们可以直接使用ElasticSearch实现分布式搜索系统的搭建与使用,都知道,Lucene只是一个搜索框架,它提供了 ...

  8. 02.Kubernetes 和 KubeSphere 集群安装配置持久化存储(nfs)并通过StatefulSet动态为pod生成pv挂载

    Kubernetes 和 KubeSphere 集群安装配置持久化存储(nfs)并通过StatefulSet动态为pod生成pv挂载 简介 1. 安装配置前置环境 1.1 安装nfs文件系统 1.1. ...

  9. redis cluster 集群 安装 配置 详解

    redis cluster 集群 安装 配置 详解 张映 发表于 2015-05-01 分类目录: nosql 标签:cluster, redis, 安装, 配置, 集群 Redis 集群是一个提供在 ...

最新文章

  1. SAP HUM 如何将HU里的物料号换成另外一个物料号?
  2. 最大调用堆栈大小超出错误
  3. php mysqli new 连接,php mysqli 连接数据库
  4. 最长公共前缀(java实现)
  5. Scikit-Learn 与 TensorFlow 机器学习实用指南学习笔记1 — 机器学习基础知识简介
  6. Java对象容器——对象数组
  7. QT绘制饼图和自定义饼图切片
  8. HR--上载信息类型的长文本的样例代码
  9. 【渝粤题库】陕西师范大学165202 战略管理 作业(专升本)
  10. 十四、Canny边缘提取
  11. MOV指令在32位汇编程序和64位汇编程序下的相同与不同之处
  12. linux wget安装mysql_linux安装mysql
  13. gohost -- go 开发的命令行hosts配置管理工具
  14. python json转换为dict的编码问题_python中json和字符编码的转换
  15. 克隆PDB数据库操作
  16. freyja对分库分表设计绝对是最强大的
  17. 最后防线:三款开源HIDS应用对比评估
  18. 设置删除命令别名--用Enki学Linux系列(10)
  19. 程序猿思维释放:打破常态
  20. 几种机器学习常用调参方式对比(网格搜索,随机搜索,贝叶斯优化)

热门文章

  1. 神经网络与相对论质量和能量守恒
  2. 幸运盒子幸运砸金蛋微信盲盒游戏源码
  3. 计算机无法与硬盘,无法识别的硬盘原因和解决方法[详细]
  4. 关乎《机器学习实战》这本书基本刷完后的一些看法以及合集
  5. pandas库读取多个excel文件数据并进行筛选合并处理后导入到新表格中
  6. 【信息奥赛题解】流感传染(详细题解 C++代码)
  7. 领域驱动设计--业务架构映射为应用架构(五)
  8. visio和preject冲突_Office 365 和 Visio Project Pro 2019 共存安装方法
  9. 毕业设计 word2vec 加lstm 文本分类
  10. 如何使用 aph-cli 搭建本地静态开发环境(server + proxy + mock)