etcd简介 etcd是一个高可用的键值存储系统,主要用于共享配置和服务发现。etcd是由CoreOS开发并维护的,灵感来自于 ZooKeeper 和 Doozer,它使用Go语言编写,并通过Raft一致性算法处理日志复制以保证强一致性。Raft是一个来自Stanford的新的一致性算法,适用于分布式系统的日志复制,Raft通过选举的方式来实现一致性,在Raft中,任何一个节点都可能成为Leader。Google的容器集群管理系统Kubernetes、开源PaaS平台Cloud Foundry和CoreOS的Fleet都广泛使用了etcd。
1.软件环境
下载etcd-v3.3.9-linux-amd64.tar.gz
本例采用三台节点搭建集群
192.168.158.130 kylinos01
192.168.158.140 kylinos02
192.168.158.150 kylinos03
2.各节点配置
1)更改各节点主机名
hostnamectl set-hostname kylinos01..kylinos02...kylinos03
2)更改/etc/hosts文件
192.168.158.130 kylinos01
192.168.158.140 kylinos02
192.168.158.150 kylinos03
将/etc/hosts文件拷贝至其他两个节点
scp /etc/hosts kylinos02:/etc scp /etc/hsots kylinos03:/etc
3)创建etcd.service文件
解压etcd.tar.gz文件
tar xvf etcd.tar.gz
mv etcd /opt/etcd
cat /lib/systemd/system/etcd.service
[Unit] Description=ETCD
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/etcd
ExecStart=/opt/etcd/etcd --name ETCD0 --initial-advertise-peer-urls http://192.168.158.130:2380 --listen-peer-urls http://192.168.158.130:2380 --listen-client-urls http://192.168.158.130:2379,http://127.0.0.1:2379 --advertise-client-urls http://192.168.158.130:2379 --initial-cluster-token etcd-cluster --initial-cluster ETCD0=http://192.168.158.130:2380,ETCD1=http://192.168.158.140:2380,ETCD2=http://192.168.158.150:2380 --initial-cluster-state new
Restart=on-failure
其中
--initial-advertise-peer-urls 本地用于监听并连接其他 member 的地址,#广播给集群内其他成员访问的URL
--LISTEN_PEER_URLS #集群内部通信使用的URL
--listen-client-urls #供外部客户端使用的url
--advertise-client-urls #广播给外部客户端使用的url
--initial-cluster #初始集群成员列表
--initial-cluster-token #集群的名称
4)启动服务
systemctl daemon-reload
systemctl restart etcd.service
5)查看状态
创建etcdctl文件链接
ln -s /opt/etcd/etcdctl /usr/local/bin/etcdctl
etcdctl member list etcdctl cluster-health
6)数据操作
在一个节点etcdctl set name yst
在另一个节点 etcdctl get name