etcd 集群搭建

现有三台机器 CentOS7 

node1 10.2.0.10

node2 10.2.0.11

node3 10.2.0.12

 1 源码解压命令行方式

node1

./etcd --name infra0 --data-dir /home/etcddata --initial-advertise-peer-urls http://10.2.0.10:2380 \
--listen-peer-urls http://10.2.0.10:2380 \
--listen-client-urls http://10.2.0.10:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.2.0.10:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://10.2.0.10:2380,infra1=http://10.2.0.11:2380,infra2=http://10.2.0.12:2380 \
--initial-cluster-state new

node2 

./etcd --name infra1 --data-dir /home/etcddata --initial-advertise-peer-urls http://10.2.0.11:2380 \
--listen-peer-urls http://10.2.0.11:2380 \
--listen-client-urls http://10.2.0.11:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.2.0.11:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://10.2.0.10:2380,infra1=http://10.2.0.11:2380,infra2=http://10.2.0.12:2380 \
--initial-cluster-state new

node3

./etcd --name infra2 --data-dir /home/etcddata --initial-advertise-peer-urls http://10.2.0.12:2380 \

--listen-peer-urls http://10.2.0.12:2380 \
--listen-client-urls http://10.2.0.12:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.2.0.12:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://10.2.0.10:2380,infra1=http://10.2.0.11:2380,infra2=http://10.2.0.12:2380 \
--initial-cluster-state new

变化的部分 --name 、host地址

2服务器启动方式

$cat /usr/lib/systemd/system/etcd.service

# cat /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=/var/lib/etcd/ EnvironmentFile=-/etc/etcd/etcd.conf #环境变量配置文件 User=etcd #用户 # set GOMAXPROCS to number of processors #ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\"" ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /home/install/etcd/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" --initial-advertise-peer-urls=\"${ETCD_INITIAL_ADVERTISE_PEER_URLS}\" --listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\" --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\" --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\"" #启动脚本 Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target [root@node1 etcddata]#

$ cat /etc/etcd/etcd.conf


# cat /etc/etcd/etcd.conf
# [member]
ETCD_NAME=etcd1
ETCD_DATA_DIR="/home/etcddata"
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://node1:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://node1:2380"
# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="etcd1=http://node1:2380,etcd2=http://node2:2380,etcd3=http://node3:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://node1:2379"
#ETCD_DISCOVERY=""
#ETCD_DISCOVERY_SRV=""
#ETCD_DISCOVERY_FALLBACK="proxy"
#ETCD_DISCOVERY_PROXY="

node2 node3 根据以上相应修改

备注 log查看 为系统日志 tail -500f /var/log/message

集群方式启动后不能清除数据文件,数据文件在第一次启动后生成,修改配置文件后重新系统如果不清除数据文件新配置不生效。

 

注意:etcd有要求,如果--listen-client-urls被设置了,那么就必须同时设置--advertise-client-urls,所以即使设置和默认相同,也必须显式设置 

 

原理说明参考

http://www.infoq.com/cn/articles/coreos-analyse-etcd/

posted @ 2016-04-15 13:49  Eamon13  阅读(1023)  评论(1编辑  收藏  举报