1、簡介html
「A highly-available key value store for shared configuration and service discovery.」 Etcd是coreos開發的分佈式服務系統,內部採用raft協議做爲一致性算法。做爲一個高可用的配置共享、服務發現的鍵值存儲系統,Etcd有如下的特色: 1)簡單:安裝配置簡單,並且提供了 HTTP API 進行交互,使用也很簡單 2)安全:支持 SSL 證書驗證 3)快速:根據官方提供的數據,單實例支持每秒2k+讀操做、1k寫操做 4)可靠:採用raft算法,實現分佈式系統數據的可用性和一致性 Etcd構建自身高可用集羣主要有三種形式: 1)靜態發現: 預先已知 Etcd 集羣中有哪些節點,在啓動時直接指定好Etcd的各個node節點地址 2)Etcd動態發現: 經過已有的Etcd集羣做爲數據交互點,而後在擴展新的集羣時實現經過已有集羣進行服務發現的機制 3)DNS動態發現: 經過DNS查詢方式獲取其餘節點地址信息 本文主要介紹第一種方式,後續會陸續介紹剩下的兩種方式。(直接docker安裝請移步:quay.io/coreos/etcd 基於Docker鏡像的集羣搭建)
2、環境介紹node
三臺虛擬機,系統環境均爲Centos7,對應節點名稱及IP地址以下(須要寫入/etc/hosts):算法
10.60.50.61 etcd-n1 10.60.50.62 etcd-n2 10.60.50.64 etcd-m
3、安裝、配置Etcddocker
yum install etcd -y
yum安裝的etcd默認配置文件在/etc/etcd/etcd.conf,如下將三個節點上的配置貼出來,請注意不一樣點(未貼出的,則代表不須要更改)安全
etcd-n1:
#[Member] #ETCD_CORS="" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" #ETCD_WAL_DIR="" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001" #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" ETCD_NAME="etcd-n1" #ETCD_SNAPSHOT_COUNT="100000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_QUOTA_BACKEND_BYTES="0" #ETCD_MAX_REQUEST_BYTES="1572864" #ETCD_GRPC_KEEPALIVE_MIN_TIME="5s" #ETCD_GRPC_KEEPALIVE_INTERVAL="2h0m0s" #ETCD_GRPC_KEEPALIVE_TIMEOUT="20s" # #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd-n1:2380" ETCD_ADVERTISE_CLIENT_URLS="http://etcd-n1:2379,http://etcd-n1:4001" #ETCD_DISCOVERY="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_DISCOVERY_SRV="" ETCD_INITIAL_CLUSTER="etcd-n1=http://etcd-n1:2380,etcd-n2=http://etcd-n2:2380,etcd-m=http://etcd-m:2380" ETCD_INITIAL_CLUSTER_TOKEN="mritd-etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_STRICT_RECONFIG_CHECK="true" #ETCD_ENABLE_V2="true" # #[Proxy] #ETCD_PROXY="off" #ETCD_PROXY_FAILURE_WAIT="5000" #ETCD_PROXY_REFRESH_INTERVAL="30000" #ETCD_PROXY_DIAL_TIMEOUT="1000" #ETCD_PROXY_WRITE_TIMEOUT="5000" #ETCD_PROXY_READ_TIMEOUT="0" # #[Security] #ETCD_CERT_FILE="" #ETCD_KEY_FILE="" #ETCD_CLIENT_CERT_AUTH="false" #ETCD_TRUSTED_CA_FILE="" #ETCD_AUTO_TLS="false" #ETCD_PEER_CERT_FILE="" #ETCD_PEER_KEY_FILE="" #ETCD_PEER_CLIENT_CERT_AUTH="false" #ETCD_PEER_TRUSTED_CA_FILE="" #ETCD_PEER_AUTO_TLS="false" # #[Logging] #ETCD_DEBUG="false" #ETCD_LOG_PACKAGE_LEVELS="" #ETCD_LOG_OUTPUT="default" # #[Unsafe] #ETCD_FORCE_NEW_CLUSTER="false" # #[Version] #ETCD_VERSION="false" #ETCD_AUTO_COMPACTION_RETENTION="0" # #[Profiling] #ETCD_ENABLE_PPROF="false" #ETCD_METRICS="basic" # #[Auth] #ETCD_AUTH_TOKEN="simple"
etcd-n2
#[Member] #ETCD_CORS="" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" #ETCD_WAL_DIR="" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001" #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" ETCD_NAME="etcd-n2" #ETCD_SNAPSHOT_COUNT="100000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_QUOTA_BACKEND_BYTES="0" #ETCD_MAX_REQUEST_BYTES="1572864" #ETCD_GRPC_KEEPALIVE_MIN_TIME="5s" #ETCD_GRPC_KEEPALIVE_INTERVAL="2h0m0s" #ETCD_GRPC_KEEPALIVE_TIMEOUT="20s" # #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd-n2:2380" ETCD_ADVERTISE_CLIENT_URLS="http://etcd-n2:2379,http://etcd-n2:4001" #ETCD_DISCOVERY="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_DISCOVERY_SRV="" ETCD_INITIAL_CLUSTER="etcd-n1=http://etcd-n1:2380,etcd-n2=http://etcd-n2:2380,etcd-m=http://etcd-m:2380" ETCD_INITIAL_CLUSTER_TOKEN="mritd-etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_STRICT_RECONFIG_CHECK="true" #ETCD_ENABLE_V2="true" # #[Proxy] #ETCD_PROXY="off" #ETCD_PROXY_FAILURE_WAIT="5000" #ETCD_PROXY_REFRESH_INTERVAL="30000" #ETCD_PROXY_DIAL_TIMEOUT="1000" #ETCD_PROXY_WRITE_TIMEOUT="5000" #ETCD_PROXY_READ_TIMEOUT="0" # #[Security] #ETCD_CERT_FILE="" #ETCD_KEY_FILE="" #ETCD_CLIENT_CERT_AUTH="false" #ETCD_TRUSTED_CA_FILE="" #ETCD_AUTO_TLS="false" #ETCD_PEER_CERT_FILE="" #ETCD_PEER_KEY_FILE="" #ETCD_PEER_CLIENT_CERT_AUTH="false" #ETCD_PEER_TRUSTED_CA_FILE="" #ETCD_PEER_AUTO_TLS="false" # #[Logging] #ETCD_DEBUG="false" #ETCD_LOG_PACKAGE_LEVELS="" #ETCD_LOG_OUTPUT="default" # #[Unsafe] #ETCD_FORCE_NEW_CLUSTER="false" # #[Version] #ETCD_VERSION="false" #ETCD_AUTO_COMPACTION_RETENTION="0" # #[Profiling] #ETCD_ENABLE_PPROF="false" #ETCD_METRICS="basic" # #[Auth] #ETCD_AUTH_TOKEN="simple"
etcd-m
#[Member] #ETCD_CORS="" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" #ETCD_WAL_DIR="" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001" #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" ETCD_NAME="etcd-m" #ETCD_SNAPSHOT_COUNT="100000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_QUOTA_BACKEND_BYTES="0" #ETCD_MAX_REQUEST_BYTES="1572864" #ETCD_GRPC_KEEPALIVE_MIN_TIME="5s" #ETCD_GRPC_KEEPALIVE_INTERVAL="2h0m0s" #ETCD_GRPC_KEEPALIVE_TIMEOUT="20s" # #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://etcd-m:2380" ETCD_ADVERTISE_CLIENT_URLS="http://etcd-m:2379,http://etcd-m:4001" #ETCD_DISCOVERY="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_DISCOVERY_SRV="" ETCD_INITIAL_CLUSTER="etcd-n1=http://etcd-n1:2380,etcd-n2=http://etcd-n2:2380,etcd-m=http://etcd-m:2380" ETCD_INITIAL_CLUSTER_TOKEN="mritd-etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_STRICT_RECONFIG_CHECK="true" #ETCD_ENABLE_V2="true" # #[Proxy] #ETCD_PROXY="off" #ETCD_PROXY_FAILURE_WAIT="5000" #ETCD_PROXY_REFRESH_INTERVAL="30000" #ETCD_PROXY_DIAL_TIMEOUT="1000" #ETCD_PROXY_WRITE_TIMEOUT="5000" #ETCD_PROXY_READ_TIMEOUT="0" # #[Security] #ETCD_CERT_FILE="" #ETCD_KEY_FILE="" #ETCD_CLIENT_CERT_AUTH="false" #ETCD_TRUSTED_CA_FILE="" #ETCD_AUTO_TLS="false" #ETCD_PEER_CERT_FILE="" #ETCD_PEER_KEY_FILE="" #ETCD_PEER_CLIENT_CERT_AUTH="false" #ETCD_PEER_TRUSTED_CA_FILE="" #ETCD_PEER_AUTO_TLS="false" # #[Logging] #ETCD_DEBUG="false" #ETCD_LOG_PACKAGE_LEVELS="" #ETCD_LOG_OUTPUT="default" # #[Unsafe] #ETCD_FORCE_NEW_CLUSTER="false" # #[Version] #ETCD_VERSION="false" #ETCD_AUTO_COMPACTION_RETENTION="0" # #[Profiling] #ETCD_ENABLE_PPROF="false" #ETCD_METRICS="basic" # #[Auth] #ETCD_AUTH_TOKEN="simple"
改好配置以後,在各個節點上開啓etcd服務:分佈式
systemctl restart etcd
4、測試驗證測試
[root@k8s-master ~]# etcdctl set testdir/testkey0 0 0 [root@k8s-master ~]# etcdctl set testdir/testkey1 1 1 [root@k8s-master ~]# etcdctl ls /testdir [root@k8s-master ~]# etcdctl ls testdir /testdir/testkey0 /testdir/testkey1 [root@k8s-master ~]# etcdctl get testdir/testkey1 1 [root@k8s-master ~]# etcdctl member list 4ba39103ae2e94df: name=etcd-n2 peerURLs=http://etcd-n2:2380 clientURLs=http://etcd-n2:2379,http://etcd-n2:4001 isLeader=false 94ae81297211716a: name=etcd-n1 peerURLs=http://etcd-n1:2380 clientURLs=http://etcd-n1:2379,http://etcd-n1:4001 isLeader=false f8f3c962865af414: name=etcd-m peerURLs=http://etcd-m:2380 clientURLs=http://etcd-m:2379,http://etcd-m:4001 isLeader=true
參考http://www.cnblogs.com/zhenyuyaodidiao/p/6237019.htmlspa