k8s HA 高可用集群之etcd集群
2016-08-15 16:13
288 查看
Etcd集群简介
etcd组件作为一个高可用强一致性的服务发现存储仓库。我们此次在三个主机上搭建了一个包含三个Etcd节点的集群,实现了集群的动态扩展和收缩,并测试和验证了Etcd集群键——值存储的一致性和高可用性。一、环境准备
OS: Ubuntu 14.04
user: root
ipaddress: etcd01: 192.168.200.24
etcd02: 192.168.200.25
etcd03: 192.168.200.26
下载etcd 源码包:https://github.com/coreos/etcd/releases/
这里用的是etcd-v2.3.7-linux-amd64.tar.gz
二、安装配置etcd
etcd01上安装
tar xf etcd-v2.3.7-linux-amd64.tar.gz cd etcd-v2.3.7-linux-amd64 cp etcd* /usr/local/bin/ |
创建etcd01脚本,可方便配置etcd启动参数 #cat etcd01 /usr/local/bin/etcd -name etcd01 \ -data-dir /data/etcd01 \ -advertise-client-urls http://192.168.200.24:2379,http://192.168.200.24:4001 \ -listen-client-urls http://0.0.0.0:2379,http://192.168.200.24:4001 \ -initial-advertise-peer-urls http://192.168.200.24:2380\ -listen-peer-urls http://0.0.0.0:2380 \ -initial-cluster-token etcd-cluster-1 \ -initial-cluster etcd01=http://192.168.200.24:2380,etcd02=http://192.168.200.25:2380,etcd03=http://192.168.200.26:2380 \ -initial-cluster-state new 参数说明:-name 指定名字 -data-dir 指定数据保存目录,默认是当前目录 -initial-cluster-state 集群状态 new为新创建集群 existing为已存在(可不指定) |
脚本中-advertise-client-urls 和 -initial-advertis-peer-urls 参数修改一下即可
然后分别运行脚本:nohup ./etcd01 &
三、测试
在任一台主机上执行etcdctl member list
#etcdctl member list 6a223770249e927d: name=etcd02 peerURLs=http://192.168.200.25:2380 clientURLs=http://192.168.200.25:2379,http://192.168.200.25:4001 isLeader=false 7e0ce16121dfea24: name=etcd01 peerURLs=http://192.168.200.24:2380 clientURLs=http://192.168.200.24:2379,http://192.168.200.24:4001 isLeader=true bfc28be8765b503e: name=etcd03 peerURLs=http://192.168.200.26:2380 clientURLs=http://192.168.200.26:2379,http://192.168.200.26:4001 isLeader=false |
我们在etcd01上设置一个key/value
root@etcd1:~# etcdctl set api_server http://192.168.5.44:8080 http://192. 4000 168.5.44:8080 |
root@etcd2:~# etcdctl get api_server http://192.168.5.44:8080 root@etcd3:~# etcdctl get api_server http://192.168.5.44:8080 |
用etcdctl cluster-health查看
root@etcd2:~# etcdctl cluster-health member 6a223770249e927d is healthy: got healthy result from http://192.168.200.25:2379 failed to check the health of member 7e0ce16121dfea24 on http://192.168.200.24:2379: Get http://192.168.200.24:2379/health: dial tcp 192.168.200.24:2379: getsockopt: connection refused failed to check the health of member 7e0ce16121dfea24 on http://192.168.200.24:4001: Get http://192.168.200.24:4001/health: dial tcp 192.168.200.24:4001: getsockopt: connection refused member 7e0ce16121dfea24 is unreachable: [http://192.168.200.24:2379 http://192.168.200.24:4001] are all unreachable member bfc28be8765b503e is healthy: got healthy result from http://192.168.200.26:2379 cluster is healthy |
root@etcd2:~# etcdctl member list 6a223770249e927d: name=etcd02 peerURLs=http://192.168.200.25:2380 clientURLs=http://192.168.200.25:2379,http://192.168.200.25:4001 isLeader=true 7e0ce16121dfea24: name=etcd01 peerURLs=http://192.168.200.24:2380 clientURLs=http://192.168.200.24:2379,http://192.168.200.24:4001 isLeader=false bfc28be8765b503e: name=etcd03 peerURLs=http://192.168.200.26:2380 clientURLs=http://192.168.200.26:2379,http://192.168.200.26:4001 isLeader=false |
root@etcd2:~# etcdctl set test01 123456 123456 root@etcd2:~# etcdctl set test02 abcdefg abcdefg |
root@etcd1:~# etcdctl cluster-health member 6a223770249e927d is healthy: got healthy result from http://192.168.200.25:2379 member 7e0ce16121dfea24 is healthy: got healthy result from http://192.168.200.24:2379 member bfc28be8765b503e is healthy: got healthy result from http://192.168.200.26:2379 cluster is healthy |
root@etcd1:~# etcdctl get test01 123456 root@etcd1:~# etcdctl get test02 abcdefg |
Etcd集群的扩展与收缩
etcd集群如果收缩很简单,直接在命令行输入etcdctl member remove {$memberID}
$memberID是你即将要删除节点的etcd的ID,etcd的扩展有一些地方需要注意一下,我在这里操作的时候遇到了不少坑。从上文写到现在,有一个文件夹很重要,几乎每个坑都与它有关,那就是-data-dir所声明的文件夹,注意要扩展一个etcd集群时,首先在集群内的任一台机器上输入
etcdctl member add $etcd_name$peer_url
$etcd_name:新加入的etcd节点的名字
$peer_url:一般为新加入的节点 IP:2380
相关文章推荐
- Linux系统 CentOS 7怎么搭建集群? 搭建高可用集群的步骤
- Keepalived高可用集群来实现web服务器负载均衡集群
- etcd 安装与集群配置
- etcd集群开机启动
- HA集群--高可用集群
- 负载均衡之LVS:实现高可用集群(WEB集群)
- Cetnos7安装etcd集群
- etcd+calico集群的部署
- etcd集群搭建--static方式
- Linux集群—高可用集群原理
- etcd 单机集群(静态无发现 无证书)
- etcd集群部署与遇到的坑
- 本地服务方式搭建etcd集群
- 深度剖析高可用集群的集群层次作用和每层的核心工具
- etcd集群启动参数说明及注意事项
- 金庸武功之“七伤拳”--etcd集群搭建
- etcd集群部署
- 集群介绍 、keepalived介绍 、 用keepalived配置高可用集群
- Etcd配置集群但不起作用的解决办法
- 集群介绍 keepalived介绍 用keepalived配置高可用集群