etcd是由一家位于旧金山的初创公司CoreOS公司(现已被Red Hat收购)于2013年6月发起的开源项目,旨在构建一个高可用的分布式键值(key-value)存储系统。CoreOS系统通过etcd来解决分布式系统配置信息共享、服务发现等问题。
etcd这个名字由两部分组成:etc和d,即UNIX/Linux操作系统的“/etc”目录和分布式(distributed)首字母的“d”。我们都知道,/etc目录一般用于存储UNIX/Linux操作系统的配置信息,因此etc和d合起来就是一个分布式的/etc目录。由此可见,etcd的寓意是为大规模分布式系统存储配置信息。
一个etcd集群要求有三个节点,配置相对简单,记录如下(以v3.5.9为例):
例子中三台服务器的IP地址:192.168.0.1、192.168.0.2、192.168.0.3
一、下载及安装
wget https://github.com/etcd-io/etcd/releases/download/v3.5.9/etcd-v3.5.9-linux-amd64.tar.gz tar xvf etcd-v3.5.9-linux-amd64.tar.gz mv etcd-v3.5.9-linux-amd64 /usr/local/etcd #查看etcd版本/usr/local/etcd/etcd -–version /usr/local/etcd/etcdctl version
二、配置
cd /usr/local/etcd vi etcd.yaml
参数 |
值 |
name |
[node01][node02][node03]三个节点分别配置不同的值 |
data-dir |
/data/etcd |
listen-client-urls |
|
advertise-client-urls |
http://[本机IP地址]:2379 |
listen-peer-urls |
http://[本机IP地址]:2380 |
initial-advertise-peer-urls |
http://[本机IP地址]:2380 |
initial-cluster |
node01=http://[node01 IP地址]:2380, node02=http://[node02 IP地址]:2380, node03=http://[node03 IP地址]:2380 |
initial-cluster-token |
etcd-pg-cluster |
initial-cluster-state |
new |
node1(192.168.0.1)配置文件:
name'node01'data-dir'/data/etcd'listen-client-urls'http://0.0.0.0:2379'advertise-client-urls'http://192.168.0.1:2379'listen-peer-urls'http://192.168.0.1:2380'initial-advertise-peer-urls'http://192.168.0.1:2380'initial-cluster'node01=http://192.168.0.1:2380,node02=http://192.168.0.2:2380,node03=http://192.168.0.3:2380'
node2(192.168.0.2)配置文件:
name'node02'data-dir'/data/etcd'listen-client-urls'http://0.0.0.0:2379'advertise-client-urls'http://192.168.0.2:2379'listen-peer-urls'http://192.168.0.2:2380'initial-advertise-peer-urls'http://192.168.0.2:2380'initial-cluster'node01=http://192.168.0.1:2380,node02=http://192.168.0.2:2380,node03=http://192.168.0.3:2380'
node3(192.168.0.3)配置文件:
name'node01'data-dir'/data/etcd'listen-client-urls'http://0.0.0.0:2379'advertise-client-urls'http://192.168.0.3:2379'listen-peer-urls'http://192.168.0.3:2380'initial-advertise-peer-urls'http://192.168.0.3:2380'initial-cluster'node01=http://192.168.0.1:2380,node02=http://192.168.0.2:2380,node03=http://192.168.0.3:2380'
三、启动etcd
etcd –config-file=/usr/local/etcd/etcd.yaml &
四、验证etcd
etcdctl endpoint status --endpoints=http://192.168.0.1:2380,http://192.168.0.2:2380,http://192.168.0.3:2380 -w table
验证无误后,可通过systemd开机启动
# vi /lib/systemd/system/etcd.servce[Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target [Service] Type=notify WorkingDirectory=/usr/local/etcd/ EnvironmentFile=-/usr/local/etcd/etcd.yaml User=runner # set GOMAXPROCS to number of processorsRestart=on-failure LimitNOFILE=65536ExecStart=/usr/local/etcd/etcd --config-file=/usr/local/etcd/etcd.yaml [Install] WantedBy=multi-user.target # systemctl enable etcd.service# systemctl start etcd# systemctl status etcd