手动部署etcd-2018-0731
手动部署很简单,这里花了10分钟搞定
部署etcd
3台机器
- etcd:由于 raft 算法的特性,集群的节点数必须是奇数
[root@linux-node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.56.111 linux-node1 linux-node1.k8s.com 192.168.56.112 linux-node2 linux-node2.k8s.com 192.168.56.113 linux-node3 linux-node3.k8s.com [root@linux-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@linux-node1 ~]#
三台服务器分别创建 etcd 用户并指定用户组为etcd
groupadd etcd
分别在三台服务器创建 conf、data、bin 目录:
mkdir -p /home/etcd/{conf,data,bin}
将 etcd-v3.2.18-linux-amd64.tar.gz 分别上传至三台服务器中,解压后将 etcdctl、etcd 复制到 /home/etcd/bin 目录下,并将 /home/etcd/bin 目录配置到系统环境变量下
[root@linux-node2 ~]# mkdir -p /home/etcd/{conf,data,bin} [root@linux-node2 ~]# tar xfz etcd-v3.2.18-linux-amd64.tar.gz [root@linux-node2 ~]# ll total 10320 -rw-------. 1 root root 1259 Jun 11 18:14 anaconda-ks.cfg drwxr-xr-x 3 478493 89939 123 Mar 30 01:49 etcd-v3.2.18-linux-amd64 -rw-r--r-- 1 root root 10562874 Mar 30 01:58 etcd-v3.2.18-linux-amd64.tar.gz [root@linux-node2 ~]# cd etcd-v3.2.18-linux-amd64/ [root@linux-node2 ~/etcd-v3.2.18-linux-amd64]# ls Documentation etcd etcdctl README-etcdctl.md README.md READMEv2-etcdctl.md [root@linux-node2 ~/etcd-v3.2.18-linux-amd64]# cp etcd /home/etcd/bin/ [root@linux-node2 ~/etcd-v3.2.18-linux-amd64]# cp etcdctl /home/etcd/bin/ [root@linux-node2 ~/etcd-v3.2.18-linux-amd64]#
三台服务器分别编辑 systemd 启动文件:
vim /usr/lib/systemd/system/etcd.service
[root@linux-node1 ~]# 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=/home/etcd/data EnvironmentFile=-/home/etcd/conf/etcd.conf User=etcd ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /home/etcd/bin/etcd \ --name ${ETCD_NAME} \ --initial-advertise-peer-urls ${ETCD_INITIAL_ADVERTISE_PEER_URLS} \ --listen-peer-urls ${ETCD_LISTEN_PEER_URLS} \ --listen-client-urls ${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \ --advertise-client-urls ${ETCD_ADVERTISE_CLIENT_URLS} \ --initial-cluster-token ${ETCD_INITIAL_CLUSTER_TOKEN} \ --initial-cluster ${ETCD_CLUSTER_ADDRESS} \ --initial-cluster-state new \ --data-dir=${ETCD_DATA_DIR}" Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target [root@linux-node1 ~]#
配置文件解释
- 规划三个节点 etcd name 分别为:etcd1、etcd2、etcd3
- 下列配置文件内容中包含中文处需要根据当前服务器实际信息进行修改,ETCD_CLUSTER_ADDRESS 的值也要根据自己实际的 IP 就行修改,切记请勿直接 copy 后就立即使用
# [member] ETCD_NAME=当前节点的etcd name,例如:etcd1 ETCD_DATA_DIR="/home/etcd/data" ETCD_LISTEN_PEER_URLS="http://当前服务器IP:2380" ETCD_LISTEN_CLIENT_URLS="http://当前服务器IP:2379" #ETCD_WAL_DIR="" #ETCD_SNAPSHOT_COUNT="10000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" #ETCD_CORS="" #[cluster] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://当前服务器IP:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_ADVERTISE_CLIENT_URLS="http://当前服务器IP:2379" ETCD_CLUSTER_ADDRESS="etcd1=http://192.168.56.111:2380,etcd2=http://192.168.56.112:2380,etcd3=http://192.168.56.113:2380" #ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost: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="default=http://localhost:2380" #ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379" #ETCD_DISCOVERY="" #ETCD_DISCOVERY_SRV="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_STRICT_RECONFIG_CHECK="false" #ETCD_AUTO_COMPACTION_RETENTIO:N="0" # #[proxy] #ETCD_PROXY="off" #ETCD_PROXY_FAILURE_WAIT="5000"
配置文件,对于etcd1
# [member] ETCD_NAME=etcd1 ETCD_DATA_DIR="/home/etcd/data" ETCD_LISTEN_PEER_URLS="http://192.168.56.111:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.56.111:2379" #ETCD_WAL_DIR="" #ETCD_SNAPSHOT_COUNT="10000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" #ETCD_CORS="" #[cluster] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.56.111:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.56.111:2379" ETCD_CLUSTER_ADDRESS="etcd1=http://192.168.56.111:2380,etcd2=http://192.168.56.112:2380,etcd3=http://192.168.56.113:2380" #ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost: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="default=http://localhost:2380" #ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379" #ETCD_DISCOVERY="" #ETCD_DISCOVERY_SRV="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_STRICT_RECONFIG_CHECK="false" #ETCD_AUTO_COMPACTION_RETENTIO:N="0" # #[proxy] #ETCD_PROXY="off" #ETCD_PROXY_FAILURE_WAIT="5000"
对于etcd2
# [member] ETCD_NAME=etcd2 ETCD_DATA_DIR="/home/etcd/data" ETCD_LISTEN_PEER_URLS="http://192.168.56.112:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.56.112:2379" #ETCD_WAL_DIR="" #ETCD_SNAPSHOT_COUNT="10000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" #ETCD_CORS="" #[cluster] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.56.112:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.56.112:2379" ETCD_CLUSTER_ADDRESS="etcd1=http://192.168.56.111:2380,etcd2=http://192.168.56.112:2380,etcd3=http://192.168.56.113:2380" #ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost: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="default=http://localhost:2380" #ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379" #ETCD_DISCOVERY="" #ETCD_DISCOVERY_SRV="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_STRICT_RECONFIG_CHECK="false" #ETCD_AUTO_COMPACTION_RETENTIO:N="0" # #[proxy] #ETCD_PROXY="off" #ETCD_PROXY_FAILURE_WAIT="5000"
对于etcd3
# [member] ETCD_NAME=etcd3 ETCD_DATA_DIR="/home/etcd/data" ETCD_LISTEN_PEER_URLS="http://192.168.56.113:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.56.113:2379" #ETCD_WAL_DIR="" #ETCD_SNAPSHOT_COUNT="10000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" #ETCD_CORS="" #[cluster] ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.56.113:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.56.113:2379" ETCD_CLUSTER_ADDRESS="etcd1=http://192.168.56.111:2380,etcd2=http://192.168.56.112:2380,etcd3=http://192.168.56.113:2380" #ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost: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="default=http://localhost:2380" #ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379" #ETCD_DISCOVERY="" #ETCD_DISCOVERY_SRV="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_STRICT_RECONFIG_CHECK="false" #ETCD_AUTO_COMPACTION_RETENTIO:N="0" # #[proxy] #ETCD_PROXY="off" #ETCD_PROXY_FAILURE_WAIT="5000"
启动和检查
- systemctl daemon-reload
- systemctl start etcd
[root@linux-node1 ~]# etcdctl cluster-health member 2b4c476820842810 is healthy: got healthy result from http://192.168.56.112:2379 member 68dbdf0635b07025 is healthy: got healthy result from http://192.168.56.113:2379 member 9f025eed2d120b69 is healthy: got healthy result from http://192.168.56.111:2379 cluster is healthy [root@linux-node1 ~]#
配置完毕
参考
https://www.jianshu.com/p/0045ef6a64a7
https://www.cnblogs.com/skymyyang/p/9067280.html
- 编写/etc/etcd/etcd.conf文件
vim /etc/etcd/etcd.conf # [member] ETCD_NAME=etcd1 #etcd实例名称 ETCD_DATA_DIR="/var/lib/etcd" #etcd数据保存目录 ETCD_LISTEN_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379" #供外部客户端使用的url ETCD_ADVERTISE_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379" #广播给外部客户端使用的url #[cluster] ETCD_LISTEN_PEER_URLS="http://192.168.142.161:2380" #集群内部通信使用的URL ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.142.161:2380" #广播给集群内其他成员访问的URL ETCD_INITIAL_CLUSTER="etcd1=http://192.168.142.161:2380,etcd2=http://192.168.142.162:2380,etcd3=http://192.168.142.163:2380" #初始集群成员列表 ETCD_INITIAL_CLUSTER_STATE="new" #初始集群状态,new为新建集群 ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster" #集群的名称