2019獨角獸企業重金招聘Python工程師標準>>> 
一、etcd v3安裝:
tar -axf etcd-v3.2.0-linux-amd64.tar.gz -C /usr/local/src/ chmod a+x /usr/local/src/etcd-v3.2.0-linux-amd64/etcd* cp -a /usr/local/src/etcd-v3.2.0-linux-amd64/etcd* /usr/local/bin/ |
?
?
?
#如果不設置 ETCDCTL_API=3,則默認是的API版本是2
export ETCDCTL_API=3 echo 'export ETCDCTL_API=3' >> /etc/profile |
二、集群配置:
??????? 單機,雙點,可根據實際情況修改端口
#node1 etcd -name perofu1 -debug \ -initial-advertise-peer-urls http://0.0.0.0:2380 \ -listen-peer-urls http://0.0.0.0:2380 \ -listen-client-urls http://0.0.0.0:2379 \ -advertise-client-urls http://0.0.0.0:2379 \ -initial-cluster-token etcd-cluster-1 \ -initial-cluster perofu1=http://0.0.0.0:2380,perofu2=http://0.0.0.0:4380 \ -initial-cluster-state new? >> /var/log/kubernetes/test-etcd.log 2>&1 & #node2 etcd -name perofu2 -debug \ -initial-advertise-peer-urls http://0.0.0.0:4380 \ -listen-peer-urls http://0.0.0.0:4380 \ -listen-client-urls http://0.0.0.0:4379 \ -advertise-client-urls http://0.0.0.0:4379 \ -initial-cluster-token etcd-cluster-1 \ -initial-cluster perofu1=http://0.0.0.0:2380,perofu2=http://0.0.0.0:4380 \ -initial-cluster-state new? >> /var/log/kubernetes/test-etcd-1.log 2>&1 & |
??????? 參數說明:
● –data-dir 指定節點的數據存儲目錄,若不指定,則默認是當前目錄。這些數據包括節點ID,集群ID,集群初始化配置,Snapshot文件,若未指 定–wal-dir,還會存儲WAL文件 ● –wal-dir 指定節點的was文件存儲目錄,若指定了該參數,wal文件會和其他數據文件分開存儲 ● –name 節點名稱 ● –initial-advertise-peer-urls 告知集群其他節點的URL,tcp 2380端口用于集群通信 ● –listen-peer-urls 監聽URL,用于與其他節點通訊 ● –advertise-client-urls 告知客戶端的URL, 也就是服務的URL,tcp 2379端口用于監聽客戶端請求 ● –initial-cluster-token 集群的ID ● –initial-cluster 集群中所有節點 ● –initial-cluster-state 集群狀態,new為新創建集群,existing為已存在的集群 |
三、實例:
[root@www ~]# curl -s http://192.168.0.211:2379/v2/machines http://0.0.0.0:2379, http://0.0.0.0:4379 [root@www ~]# [root@www ~]# etcdctl member list 25a7dd0a87b3530: name=perofu2 peerURLs=http://0.0.0.0:4380 clientURLs=http://0.0.0.0:4379 isLeader=false 2006f2ad47deea09: name=perofu1 peerURLs=http://0.0.0.0:2380 clientURLs=http://0.0.0.0:2379 isLeader=true [root@www ~]# [root@www ~]# etcdctl cluster-health member 25a7dd0a87b3530 is healthy: got healthy result from http://0.0.0.0:4379 member 2006f2ad47deea09 is healthy: got healthy result from http://0.0.0.0:2379 cluster is healthy #設置key [root@www ~]# etcdctl --endpoints "http://127.0.0.1:2379" set api_server? http://192.168.0.211:8080 http://192.168.0.211:8080 [root@www ~]# [root@www ~]# etcdctl --endpoints "http://127.0.0.1:2379" get api_server http://192.168.0.211:8080 [root@www ~]# [root@www ~]# etcdctl --endpoints "http://127.0.0.1:4379" get api_server http://192.168.0.211:8080 [root@www ~]# |