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 ~]# |