etcd 集羣搭建

現有三臺機器 CentOS7 node

node1 10.2.0.10bash

node2 10.2.0.11服務器

node3 10.2.0.12this

 1 源碼解壓命令行方式url

node1spa

./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地址code

2服務器啓動方式blog

$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

集羣方式啓動後不能清除數據文件,數據文件在第一次啓動後生成,修改配置文件後從新系統若是不清除數據文件新配置不生效。

 

原理說明參考

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

相關文章
相關標籤/搜索