1. 规划:先安装三台组建集群,然后扩容一个安全节点进来
  2.  
  3. 、环境:
  4.  
  5. 三台centos7. 主机
  6.  
  7. 192.168.0.91
  8.  
  9. 192.168.0.92
  10.  
  11. 192.168.0.93
  12.  
  13. 都关闭防火墙
  14.  
  15. 都关闭selinux
  16.  
  17. 配置免密登录,参照:https://www.cnblogs.com/effortsing/p/10060748.html
  18.  
  19. 都配置主机名
  20.  
  21. sed -i '$a\hostname=test1' /etc/sysconfig/network && hostnamectl set-hostname test1
  22.  
  23. sed -i '$a\test1' /etc/hostname
  24.  
  25. cat >>/etc/hosts<< EOF
  26. 192.168.0.91 test1
  27. 192.168.0.92 test2
  28. 192.168.0.93 test3
  29. 192.168.0.94 test4
  30. EOF
  31.  
  32. 配置所有主机时间同步(非必须)
  33.  
  34. 都退出xshell重新登录,查看主机名
  35.  
  36. 启动etcd非安全集群
  37.  
  38. 2.1 安装并启动etcd
  39.  
  40. 3个节点上安装etcd
  41.  
  42. yum install -y etcd
  43. systemctl start etcd && systemctl enable etcd
  44.  
  45. 使用etcdctl访问etcd并检查其状态验证启动成功。
  46.  
  47. etcdctl cluster-health
  48. member 8e9e05c52164694d is healthy: got healthy result from http://localhost:2379
  49.  
  50. 2.2 修改配置启动集群
  51.  
  52. 目前这3个节点上的etcd并未形成集群,删除原先配置文件,添加如下参数
  53.  
  54. etcd1配置
  55.  
  56. cat >/etc/etcd/etcd.conf <<EOF
  57. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  58. ETCD_LISTEN_PEER_URLS="http://192.168.0.91:2380"
  59. ETCD_LISTEN_CLIENT_URLS="http://192.168.0.91:2379,http://127.0.0.1:2379"
  60. ETCD_NAME="etcd1"
  61. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.91:2380"
  62. ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.91:2379"
  63. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  64. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  65. EOF
  66.  
  67. etcd2配置
  68.  
  69. cat >/etc/etcd/etcd.conf <<EOF
  70. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  71. ETCD_LISTEN_PEER_URLS="http://192.168.0.92:2380"
  72. ETCD_LISTEN_CLIENT_URLS="http://192.168.0.92:2379,http://127.0.0.1:2379"
  73. ETCD_NAME="etcd2"
  74. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.92:2380"
  75. ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.92:2379"
  76. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  77. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  78. EOF
  79.  
  80. etcd3配置
  81.  
  82. cat >/etc/etcd/etcd.conf <<EOF
  83. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  84. ETCD_LISTEN_PEER_URLS="http://192.168.0.93:2380"
  85. ETCD_LISTEN_CLIENT_URLS="http://192.168.0.93:2379,http://127.0.0.1:2379"
  86. ETCD_NAME="etcd3"
  87. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.93:2380"
  88. ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.93:2379"
  89. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  90. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  91. EOF
  92.  
  93. 注意:ETCD_INITIAL_CLUSTER 选项决定了通过 etcdctl cluster-health 可以查看到节点的个数
  94.  
  95. 集群的配置信息如节点urltoken均存储在数据目录中,这些配置项仅在建立集群时生效。因此当修改已有etcd集群配置时(如新增节点,从http变为https通信等操作),
  96.  
  97. 并不是简单的修改配置文件就能完成,而是要通过etcdctl的集群管理工具通过复杂的步骤实现
  98.  
  99. 删除成员并启动
  100.  
  101. systemctl stop etcd
  102. rm -rf /var/lib/etcd/default.etcd
  103. systemctl daemon-reload && systemctl restart etcd
  104.  
  105. 如果不删除成员目录的话是无法启动的,
  106.  
  107. 注意三个节点要同时启动才可以启动成功
  108.  
  109. 在任意一个节点上使用etcdctl验证集群状态:
  110.  
  111. etcdctl cluster-health
  112.  
  113. [root@etcd1 ~]# etcdctl cluster-health
  114. member adff72f24ac33f4b is healthy: got healthy result from http://192.168.0.91:2379
  115. member c883f9e325d8667d is healthy: got healthy result from http://192.168.0.93:2379
  116. member c96f41ba37a00a16 is healthy: got healthy result from http://192.168.0.92:2379
  117. cluster is healthy
  118.  
  119. 、集群之间通信介绍
  120.  
  121. 集群服务中的通信一般包括两种场景:
  122.  
  123. 对外提供服务的通信,发生在集群外部的客户端和集群某个节点之间,etcd默认端口为2379,例如 etcdctl 就属于客户端
  124.  
  125. 集群内部的通信,发生在集群内部的任意两个节点之间,etcd的默认端口为2380
  126.  
  127. 刚安装完etcd可以看到配置文件里面都是http,这是不安全的,为了加强集群通信安全,需要使用https,下面就要介绍如何使用https来访问集群
  128.  
  129. 创建RootCA
  130.  
  131. 4.1 安装pki证书管理工具cfssl
  132.  
  133. 安装cfssl工具
  134.  
  135. 只要把安装包改下名字,移动到usr/local/bin/下,加上授权即可
  136.  
  137. 通过网盘下载cfssl工具
  138.  
  139. 链接:https://pan.baidu.com/s/1PGVlADPfCMhYEfYlMngDHQ
  140. 提取码:itrj
  141.  
  142. 链接:https://pan.baidu.com/s/1KsDKbbzwO82WegqPAlonyg
  143. 提取码:n8ce
  144.  
  145. 链接:https://pan.baidu.com/s/1dM8cJ38XAO_n6S-KKHZlqw
  146. 提取码:5n6m
  147.  
  148. mv cfssl-certinfo_linux-amd64 /usr/local/bin/cfssl-certinfo
  149. mv cfssl_linux-amd64 /usr/local/bin/cfssl
  150. mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
  151. chmod +x /usr/local/bin/cfssl*
  152.  
  153. 4.2、配置PKI
  154.  
  155. 证书分两种情况:
  156.  
  157. 服务器与客户端之间的通信,这种情况下服务器的证书仅用于服务器认证,客户端证书仅用于客户端认证
  158.  
  159. 服务器间的通信,这种情况下每个etcd既是服务器也是客户端,因此其证书既要用于服务器认证,也要用于客户端认证
  160.  
  161. 创建PKI配置文件
  162.  
  163. mkdir /etc/etcd/pki
  164.  
  165. cd /etc/etcd/pki
  166.  
  167. cfssl print-defaults config > ca-config.json
  168.  
  169. vi ca-config.json
  170.  
  171. cat >ca-config.json <<EOF
  172. {
  173. "signing": {
  174. "default": {
  175. "expiry": "168h"
  176. },
  177. "profiles": {
  178. "server": {
  179. "expiry": "8760h",
  180. "usages": [
  181. "signing",
  182. "key encipherment",
  183. "server auth"
  184. ]
  185. },
  186. "client": {
  187. "expiry": "8760h",
  188. "usages": [
  189. "signing",
  190. "key encipherment",
  191. "client auth"
  192. ]
  193. },
  194. "peer": {
  195. "expiry": "8760h",
  196. "usages": [
  197. "signing",
  198. "key encipherment",
  199. "server auth",
  200. "client auth"
  201. ]
  202. }
  203. }
  204. }
  205. }
  206. EOF
  207.  
  208. 在其中定义3profile
  209.  
  210. server,作为服务器与客户端通信时的服务器证书
  211.  
  212. client,作为服务器与客户端通信时的客户端证书
  213.  
  214. peer,作为服务器间通信时用的证书,既认证服务器也认证客户端
  215.  
  216. 4.3 创建RootCA证书
  217.  
  218. cfssl print-defaults csr > rootca-csr.json
  219. vi rootca-csr.json
  220.  
  221. 修改后内容如下,由于CA证书不表示任何一台服务器,因此此处无需hosts字段
  222.  
  223. cat >rootca-csr.json<<EOF
  224. {
  225. "CN": "ETCD Root CA",
  226. "key": {
  227. "algo": "ecdsa",
  228. "size":
  229. },
  230. "names": [
  231. {
  232. "C": "US",
  233. "L": "CA",
  234. "ST": "San Francisco"
  235. }
  236. ]
  237. }
  238. EOF
  239.  
  240. cfssl gencert -initca rootca-csr.json | cfssljson -bare rootca
  241.  
  242. ls rootca*
  243. rootca.csr rootca-csr.json rootca-key.pem rootca.pem
  244.  
  245. 把根CA证书拷贝到集群的所有节点当中:
  246.  
  247. scp /etc/etcd/pki/rootca.pem root@192.168.0.92:/etc/etcd/pki/rootca.pem
  248. scp /etc/etcd/pki/rootca.pem root@192.168.0.93:/etc/etcd/pki/rootca.pem
  249.  
  250. 证书授权
  251.  
  252. chown -R etcd:etcd /etc/etcd/pki/*
  253.  
  254. 根CA证书只有1个, 每个节点都保存,只保存证书即可。
  255.  
  256. 服务器server证书1个,本实验中为整个集群使用1个证书,每个服务器均保存该证书和私钥。
  257.  
  258. 客户端证书1个, 本实验环境中仅供etcdctl使用,因此在运行etcdctl的主机上保存证书和私钥即可。实际工作中中每个访问etcd的客户端都应该有自己的客户端证书和私钥。
  259.  
  260. 服务器peer证书3个, 每个节点保存自己的证书和私钥
  261.  
  262. 5、 集群外部开启pki安全认证
  263.  
  264. 注意:外部的意思在本篇就是使用 etcdtl来访问,etcdctl 就是外部客户端。如果k8s的apiserver访问etcd,那么apiserver就是客户端
  265.  
  266. 5.1、 创建服务器证书
  267.  
  268. 方式一、
  269.  
  270. 集群成员用各自的证书
  271.  
  272. 也就是说请求文件中hosts只写本机ip地址
  273.  
  274. 本文采用第一种方式
  275.  
  276. 生产etcd1服务端证书
  277.  
  278. cfssl print-defaults csr > etcd1-csr.json
  279. vi etcd1-csr.json
  280.  
  281. cat > etcd1-csr.json<< EOF
  282. {
  283. "CN": "ETCD Cluster-1",
  284. "hosts": [
  285. "192.168.0.91"
  286. ],
  287. "key": {
  288. "algo": "ecdsa",
  289. "size": 256
  290. },
  291. "names": [
  292. {
  293. "C": "US",
  294. "L": "CA",
  295. "ST": "San Francisco"
  296. }
  297. ]
  298. }
  299. EOF
  300.  
  301. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=server etcd1-csr.json | cfssljson -bare etcd1
  302.  
  303. 生产etcd2服务端证书
  304.  
  305. cfssl print-defaults csr > etcd2-csr.json
  306. vi etcd2-csr.json
  307.  
  308. cat > etcd2-csr.json<< EOF
  309. {
  310. "CN": "ETCD Cluster-2",
  311. "hosts": [
  312. "192.168.0.92"
  313. ],
  314. "key": {
  315. "algo": "ecdsa",
  316. "size": 256
  317. },
  318. "names": [
  319. {
  320. "C": "US",
  321. "L": "CA",
  322. "ST": "San Francisco"
  323. }
  324. ]
  325. }
  326. EOF
  327.  
  328. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=server etcd2-csr.json | cfssljson -bare etcd2
  329.  
  330. 生产etcd3服务端证书
  331.  
  332. cfssl print-defaults csr > etcd3-csr.json
  333. vi etcd3-csr.json
  334.  
  335. cat > etcd3-csr.json<< EOF
  336. {
  337. "CN": "ETCD Cluster-3",
  338. "hosts": [
  339. "192.168.0.93"
  340. ],
  341. "key": {
  342. "algo": "ecdsa",
  343. "size": 256
  344. },
  345. "names": [
  346. {
  347. "C": "US",
  348. "L": "CA",
  349. "ST": "San Francisco"
  350. }
  351. ]
  352. }
  353. EOF
  354.  
  355. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=server etcd3-csr.json | cfssljson -bare etcd3
  356.  
  357. 复制证书
  358.  
  359. 复制证书到对应节点
  360.  
  361. 所有节点创建目录
  362.  
  363. mkdir -p /etc/etcd/pki/
  364.  
  365. scp /etc/etcd/pki/etcd2*.pem root@192.168.0.92:/etc/etcd/pki/
  366. scp /etc/etcd/pki/etcd3*.pem root@192.168.0.93:/etc/etcd/pki/
  367.  
  368. 授权
  369.  
  370. 给所有节点证书授权,否则启动报错
  371.  
  372. 因为用root用户生成的证书文件,证书权限为rw-------,etcd用户没有读权限,而配置文件里面的ETCD_就代表etcd用户,因此需要将其属主修改为etcd。
  373.  
  374. chown -R etcd:etcd /etc/etcd/pki/*
  375.  
  376. 方式二、
  377.  
  378. 集群成员用统一的证书
  379.  
  380. 也就是说请求文件中hosts填写集群所有ip地址
  381.  
  382. 注意 hosts也可以改成域名
  383.  
  384. 所有使用证书的服务器都要写到下面hosts列表里面,否则无法建立连接,以后添加新成员的话,hosts也要改
  385.  
  386. 从上面可以看到hosts中有三个地址,如果以后要扩充集群节点,就需要修改hosts列表重新生成证书,重新分发到所有节点上,这样容易出错,也麻烦
  387.  
  388. 生产环境一般把hosts写成统一的对外域名。这里最好分开创建三个配置文件,每个配置文件里面填写一个ip,不公用。以后扩容也方便。
  389.  
  390. cfssl print-defaults csr > etcd-csr.json
  391. vi etcd-csr.json
  392.  
  393. cat >etcd-csr.json<<EOF
  394. {
  395. "CN": "ETCD Cluster",
  396. "hosts": [
  397. "192.168.0.91",
  398. "192.168.0.92",
  399. "192.168.0.93"
  400. ],
  401. "key": {
  402. "algo": "ecdsa",
  403. "size": 256
  404. },
  405. "names": [
  406. {
  407. "C": "US",
  408. "L": "CA",
  409. "ST": "San Francisco"
  410. }
  411. ]
  412. }
  413. EOF
  414.  
  415. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=server etcd-csr.json | cfssljson -bare etcd
  416.  
  417. 所有节点创建目录
  418.  
  419. mkdir -p /etc/etcd/pki/
  420.  
  421. scp /etc/etcd/pki/etcd*.pem root@192.168.0.92:/etc/etcd/pki/
  422. scp /etc/etcd/pki/etcd*.pem root@192.168.0.93:/etc/etcd/pki/
  423.  
  424. 给所有节点证书授权
  425.  
  426. 因为用root用户生成的证书文件,证书权限为rw-------,etcd用户没有读权限,而配置文件里面的ETCD_就代表etcd用户,因此需要将其属主修改为etcd。
  427.  
  428. chown -R etcd:etcd /etc/etcd/pki/*
  429.  
  430. 5.2、 修改etcd1配置并重启
  431.  
  432. cat >/etc/etcd/etcd.conf << EOF
  433. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  434. ETCD_LISTEN_PEER_URLS="http://192.168.0.91:2380"
  435. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.91:2379,http://127.0.0.1:2379"
  436. ETCD_NAME="etcd1"
  437. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.91:2380"
  438. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.91:2379"
  439. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  440. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  441.  
  442. #开启集群外部服务端认证
  443. ETCD_CERT_FILE="/etc/etcd/pki/etcd1.pem"
  444. ETCD_KEY_FILE="/etc/etcd/pki/etcd1-key.pem"
  445. EOF
  446.  
  447. 重启
  448.  
  449. systemctl daemon-reload && systemctl restart etcd
  450.  
  451. 此时改变的仅仅时集群对外的服务方式,内部的通信方式并没有改变,因此无需删除实例,可直接重启etcd。
  452.  
  453. 重启后,使用etcdctl指令访问集群,如果在不指定–ca-file参数,结果会提示 https://192.168.0.91:2379 访问失败,因为其证书是不受信任的。
  454.  
  455. [root@test1 ~]# etcdctl cluster-health
  456. failed to check the health of member 6c70a880257288f on https://192.168.0.91:2379: Get https://192.168.0.91:2379/health: x509: certificate signed by unknown authority
  457. member 6c70a880257288f is unreachable: [https://192.168.0.91:2379] are all unreachable
  458. member 3f7336e156287ed0 is healthy: got healthy result from http://192.168.0.93:2379
  459. member 5bbe42788a239cc6 is healthy: got healthy result from http://192.168.0.92:2379
  460. cluster is healthy
  461.  
  462. 注意:ETCD_LISTEN_CLIENT_URLS中包含了http://127.0.0.1:2379, 因此直接指定该地址可以访问etcd,但是ETCD_ADVERTISE_CLIENT_URLS中不包含http://127.0.0.1:2379, 因此etcd在给客户端广播集群节点的地址时,只会广播https://192.168.56.41:2379, etcdctl紧接着用这个地址去查询集群健康状态时,但证书不受信任无法访问。
  463.  
  464. 加上–ca-file参数指定用于校验的CA证书,即根CA证书后,访问正常。
  465.  
  466. [root@test1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem cluster-health
  467. member 6c70a880257288f is healthy: got healthy result from https://192.168.0.91:2379
  468. member 3f7336e156287ed0 is healthy: got healthy result from http://192.168.0.93:2379
  469. member 5bbe42788a239cc6 is healthy: got healthy result from http://192.168.0.92:2379
  470. cluster is healthy
  471.  
  472. 上面输出可以看到,仅有1个节点启动了https。对其余两个节点重复本节操作即可。出于对rootca的安全考虑,服务器证书的生成操作在一台服务器上完成,生成后将其拷贝到相应节点即可。配置并重启完所有节点后,应该可以看到所有节点的侦听URL均为https协议。
  473.  
  474. 5.3、 修改etcd2配置并重启
  475.  
  476. cat >/etc/etcd/etcd.conf << EOF
  477. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  478. ETCD_LISTEN_PEER_URLS="http://192.168.0.92:2380"
  479. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.92:2379,http://127.0.0.1:2379"
  480. ETCD_NAME="etcd2"
  481. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.92:2380"
  482. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.92:2379"
  483. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  484. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  485.  
  486. #开启集群外部服务端认证
  487. ETCD_CERT_FILE="/etc/etcd/pki/etcd2.pem"
  488. ETCD_KEY_FILE="/etc/etcd/pki/etcd2-key.pem"
  489. EOF
  490.  
  491. 重启
  492.  
  493. systemctl daemon-reload && systemctl restart etcd
  494.  
  495. 5.4、 修改etcd3配置并重启
  496.  
  497. cat >/etc/etcd/etcd.conf << EOF
  498. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  499. ETCD_LISTEN_PEER_URLS="http://192.168.0.93:2380"
  500. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.93:2379,http://127.0.0.1:2379"
  501. ETCD_NAME="etcd3"
  502. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.93:2380"
  503. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.93:2379"
  504. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  505. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  506.  
  507. #开启集群外部服务端认证
  508. ETCD_CERT_FILE="/etc/etcd/pki/etcd3.pem"
  509. ETCD_KEY_FILE="/etc/etcd/pki/etcd3-key.pem"
  510. EOF
  511.  
  512. 重启
  513.  
  514. systemctl daemon-reload && systemctl restart etcd
  515.  
  516. 查看健康状态
  517.  
  518. [root@test1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem cluster-health
  519. member 6c70a880257288f is healthy: got healthy result from https://192.168.0.91:2379
  520. member 3f7336e156287ed0 is healthy: got healthy result from https://192.168.0.93:2379
  521. member 5bbe42788a239cc6 is healthy: got healthy result from https://192.168.0.92:2379
  522. cluster is healthy
  523.  
  524. 发现都变成了https模式
  525.  
  526. 6、 客户端验证
  527.  
  528. 6.1.1、 修改etcd1配置并重启
  529.  
  530. 启动客户端认证需要修改以下参数:
  531.  
  532. ETCD_CLIENT_CERT_AUTH="true"
  533. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  534.  
  535. cat > /etc/etcd/etcd.conf <<EOF
  536. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  537. ETCD_LISTEN_PEER_URLS="http://192.168.0.91:2380"
  538. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.91:2379,http://127.0.0.1:2379"
  539. ETCD_NAME="etcd1"
  540. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.91:2380"
  541. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.91:2379"
  542. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  543. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  544.  
  545. #开启集群外部服务端认证
  546. ETCD_CERT_FILE="/etc/etcd/pki/etcd1.pem"
  547. ETCD_KEY_FILE="/etc/etcd/pki/etcd1-key.pem"
  548.  
  549. #开启集群外部客户端认证
  550. ETCD_CLIENT_CERT_AUTH="true"
  551. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  552. EOF
  553.  
  554. 重启etcd1
  555.  
  556. systemctl daemon-reload && systemctl restart etcd
  557.  
  558. 重启etcd服务后发现即使指定了–ca-file参数,https节点仍然无法访问。这次的错误是证书错误,因为客户端没有提供任何证书。
  559.  
  560. [root@test1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem cluster-health
  561. failed to check the health of member 6c70a880257288f on https://192.168.0.91:2379: Get https://192.168.0.91:2379/health: remote error: tls: bad certificate
  562. member 6c70a880257288f is unreachable: [https://192.168.0.91:2379] are all unreachable
  563. member 3f7336e156287ed0 is healthy: got healthy result from https://192.168.0.93:2379
  564. member 5bbe42788a239cc6 is healthy: got healthy result from https://192.168.0.92:2379
  565. cluster is healthy
  566.  
  567. 6.1.2、 创建客户端证书
  568.  
  569. 修改后内容如下,etcdctl可能运行在多台节点上,因此不指定可以使用该证书的主机列表。
  570.  
  571. 创建客户端证书请求文件所需配置:
  572.  
  573. cfssl print-defaults csr > etcdctl-csr.json
  574. vi etcdctl-csr.json
  575.  
  576. cat >etcdctl-csr.json<<EOF
  577. {
  578. "CN": "ETCDCTL",
  579. "key": {
  580. "algo": "ecdsa",
  581. "size": 256
  582. },
  583. "names": [
  584. {
  585. "C": "US",
  586. "L": "CA",
  587. "ST": "San Francisco"
  588. }
  589. ]
  590. }
  591. EOF
  592.  
  593. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=client etcdctl-csr.json | cfssljson -bare etcdctl
  594.  
  595. 授权
  596.  
  597. chown -R etcd:etcd /etc/etcd/pki/*
  598.  
  599. 复制证书
  600.  
  601. scp /etc/etcd/pki/etcdctl*.pem root@192.168.0.92:/etc/etcd/pki/
  602. scp /etc/etcd/pki/etcdctl*.pem root@192.168.0.93:/etc/etcd/pki/
  603.  
  604. 授权
  605.  
  606. 复制过去要给对方节点授权
  607.  
  608. chown -R etcd:etcd /etc/etcd/pki/*
  609.  
  610. 然后在etcdctl命令行中指定生成的证书和私钥,才能成功访问节点:
  611.  
  612. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  613. member 6c70a880257288f is healthy: got healthy result from https://192.168.0.91:2379
  614. member 3f7336e156287ed0 is healthy: got healthy result from https://192.168.0.93:2379
  615. member 5bbe42788a239cc6 is healthy: got healthy result from https://192.168.0.92:2379
  616. cluster is healthy
  617.  
  618. 6.2.1、 修改etcd2配置并重启
  619.  
  620. 启动客户端认证需要修改以下参数:
  621.  
  622. ETCD_CLIENT_CERT_AUTH="true"
  623. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  624.  
  625. cat > /etc/etcd/etcd.conf <<EOF
  626. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  627. ETCD_LISTEN_PEER_URLS="http://192.168.0.92:2380"
  628. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.92:2379,http://127.0.0.1:2379"
  629. ETCD_NAME="etcd2"
  630. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.92:2380"
  631. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.92:2379"
  632. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  633. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  634.  
  635. #开启集群外部服务端认证
  636. ETCD_CERT_FILE="/etc/etcd/pki/etcd2.pem"
  637. ETCD_KEY_FILE="/etc/etcd/pki/etcd2-key.pem"
  638.  
  639. #开启集群外部客户端认证
  640. ETCD_CLIENT_CERT_AUTH="true"
  641. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  642. EOF
  643.  
  644. 重启etcd2
  645.  
  646. systemctl daemon-reload && systemctl restart etcd
  647.  
  648. 然后在etcdctl命令行中指定生成的客户端证书和私钥,访问节点:
  649.  
  650. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  651. member 6c70a880257288f is healthy: got healthy result from https://192.168.0.91:2379
  652. member 3f7336e156287ed0 is healthy: got healthy result from https://192.168.0.93:2379
  653. member 5bbe42788a239cc6 is healthy: got healthy result from https://192.168.0.92:2379
  654. cluster is healthy
  655.  
  656. 6.3.1、 修改etcd3配置并重启
  657.  
  658. 启动客户端认证需要修改以下参数:
  659.  
  660. ETCD_CLIENT_CERT_AUTH="true"
  661. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  662.  
  663. cat > /etc/etcd/etcd.conf <<EOF
  664. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  665. ETCD_LISTEN_PEER_URLS="http://192.168.0.93:2380"
  666. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.93:2379,http://127.0.0.1:2379"
  667. ETCD_NAME="etcd3"
  668. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.93:2380"
  669. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.93:2379"
  670. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=http://192.168.0.93:2380"
  671. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  672.  
  673. #开启集群外部服务端认证
  674. ETCD_CERT_FILE="/etc/etcd/pki/etcd3.pem"
  675. ETCD_KEY_FILE="/etc/etcd/pki/etcd3-key.pem"
  676.  
  677. #开启集群外部客户端认证
  678. ETCD_CLIENT_CERT_AUTH="true"
  679. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  680. EOF
  681.  
  682. 重启etcd3
  683.  
  684. systemctl daemon-reload && systemctl restart etcd
  685.  
  686. 然后在etcdctl命令行中指定生成的客户端证书和私钥,访问节点:
  687.  
  688. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  689. member 6c70a880257288f is healthy: got healthy result from https://192.168.0.91:2379
  690. member 3f7336e156287ed0 is healthy: got healthy result from https://192.168.0.93:2379
  691. member 5bbe42788a239cc6 is healthy: got healthy result from https://192.168.0.92:2379
  692. cluster is healthy
  693.  
  694. 7、集群内部开启pki安全认证
  695.  
  696. 方式一: 不重建集群开启pki安全认证
  697.  
  698. 7.1、先修改etcd3节点为安全通信
  699.  
  700. 7.1.1、准备peer证书
  701.  
  702. 注意:peer证书既是服务端证书又是客户端证书,从下面参数 -profile=peer中可以看到
  703.  
  704. 和server证书一样,3个节点的peer证书其实也可以共用一个,考虑到以后扩容代理的麻烦,所以这里每个节点都配置自己的peer证书3个节点分别创建peer证书请求文件
  705.  
  706. 生产peer1证书
  707.  
  708. cfssl print-defaults csr > etcd1-peer-csr.json
  709. vi etcd1-peer-csr.json
  710.  
  711. cat >etcd1-peer-csr.json <<EOF
  712. {
  713. "CN": "ETCD Peer on etcd1",
  714. "hosts": [
  715. "192.168.0.91"
  716. ],
  717. "key": {
  718. "algo": "ecdsa",
  719. "size": 256
  720. },
  721. "names": [
  722. {
  723. "C": "US",
  724. "L": "CA",
  725. "ST": "San Francisco"
  726. }
  727. ]
  728. }
  729. EOF
  730.  
  731. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=peer etcd1-peer-csr.json | cfssljson -bare etcd1-peer
  732.  
  733. 生产peer2证书
  734.  
  735. cfssl print-defaults csr > etcd2-peer-csr.json
  736. vi etcd2-peer-csr.json
  737.  
  738. cat >etcd2-peer-csr.json <<EOF
  739. {
  740. "CN": "ETCD Peer on etcd2",
  741. "hosts": [
  742. "192.168.0.92"
  743. ],
  744. "key": {
  745. "algo": "ecdsa",
  746. "size": 256
  747. },
  748. "names": [
  749. {
  750. "C": "US",
  751. "L": "CA",
  752. "ST": "San Francisco"
  753. }
  754. ]
  755. }
  756. EOF
  757.  
  758. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=peer etcd2-peer-csr.json | cfssljson -bare etcd2-peer
  759.  
  760. 生产peer3证书
  761.  
  762. cfssl print-defaults csr > etcd3-peer-csr.json
  763. vi etcd3-peer-csr.json
  764.  
  765. cat >etcd3-peer-csr.json <<EOF
  766. {
  767. "CN": "ETCD Peer on etcd3",
  768. "hosts": [
  769. "192.168.0.93"
  770. ],
  771. "key": {
  772. "algo": "ecdsa",
  773. "size": 256
  774. },
  775. "names": [
  776. {
  777. "C": "US",
  778. "L": "CA",
  779. "ST": "San Francisco"
  780. }
  781. ]
  782. }
  783. EOF
  784.  
  785. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=peer etcd3-peer-csr.json | cfssljson -bare etcd3-peer
  786.  
  787. 注意:peer证书既是服务端证书又是客户端证书,从上面参数 -profile=peer中可以看到
  788.  
  789. 7.1.2、复制证书
  790.  
  791. scp /etc/etcd/pki/etcd2-peer*.pem root@192.168.0.92:/etc/etcd/pki/
  792. scp /etc/etcd/pki/etcd3-peer*.pem root@192.168.0.93:/etc/etcd/pki/
  793.  
  794. 7.1.3、授权
  795.  
  796. 所有节点授权,复制过去要记得给授权,否则启动报错
  797.  
  798. chown -R etcd:etcd /etc/etcd/pki/*
  799.  
  800. 7.1.4、查看节点列表,获取节点标识
  801.  
  802. [root@etcd1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  803. adff72f24ac33f4b: name=etcd1 peerURLs=http://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  804. c883f9e325d8667d: name=etcd3 peerURLs=http://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  805. c96f41ba37a00a16: name=etcd2 peerURLs=http://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  806.  
  807. 7.1.5、修改etcd3节点的peer url为https
  808.  
  809. [root@etcd1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update c883f9e325d8667d https://192.168.0.93:2380
  810. Updated member with ID c883f9e325d8667d in cluster
  811.  
  812. 7.1.6、重新检查节点列表和集群健康状态
  813.  
  814. [root@etcd1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  815. adff72f24ac33f4b: name=etcd1 peerURLs=http://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  816. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  817. c96f41ba37a00a16: name=etcd2 peerURLs=http://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  818.  
  819. [root@etcd3 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  820. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  821. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  822. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  823. cluster is healthy
  824.  
  825. 可以看到etcd3的peer地址已经是https了,但实际上此时etcd3的侦听地址没有修改,https所需要的相关证书都没有配置,https通信是不可能建立的,因此事实上此时与etcd3的通信仍然是通过http。
  826.  
  827. 注意:如果发现peerURLs不是https,原因在于执行"修改etcd3节点的peer url为https步骤"的时候掉了步骤最后面的https://192.168.0.93:2380 或者ID不正确,重新执行几遍即可
  828.  
  829. 7.1.7、修改etcd3的peer工作端口为https
  830.  
  831. 修改内容如下:
  832.  
  833. ETCD_LISTEN_PEER_URLS="https://192.168.0.93:2380"
  834. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.93:2380"
  835. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  836.  
  837. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  838. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  839. ETCD_PEER_CLIENT_CERT_AUTH="true"
  840. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  841.  
  842. cat >/etc/etcd/etcd.conf <<EOF
  843. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  844. ETCD_LISTEN_PEER_URLS="https://192.168.0.93:2380"
  845. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.93:2379,http://127.0.0.1:2379"
  846. ETCD_NAME="etcd3"
  847. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.93:2380"
  848. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.93:2379"
  849. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  850. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  851.  
  852. #开启集群外部服务端认证
  853. ETCD_CERT_FILE="/etc/etcd/pki/etcd3.pem"
  854. ETCD_KEY_FILE="/etc/etcd/pki/etcd3-key.pem"
  855.  
  856. #开启集群外部客户端认证
  857. ETCD_CLIENT_CERT_AUTH="true"
  858. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  859.  
  860. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  861. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  862. ETCD_PEER_CLIENT_CERT_AUTH="true"
  863. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  864. EOF
  865.  
  866. 重启
  867.  
  868. systemctl daemon-reload && systemctl restart etcd
  869.  
  870. 查看集群状态
  871.  
  872. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  873. 6c70a880257288f: name=etcd1 peerURLs=http://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  874. 3f7336e156287ed0: name=etcd3 peerURLs=http://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  875. 5bbe42788a239cc6: name=etcd2 peerURLs=http://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  876.  
  877. 上述配置在etcd3启动了服务器端的https通信,并且要求进行客户端验证,而作为客户端的etcd1和etcd2还没有相关配置,因此https通信仍然会失败,与etcd3的通信仍然fallback到http上
  878.  
  879. 因此需要修改etcd1和etcd2进行客户端验证
  880.  
  881. 7.1.8、 在etcd1和etcd2上配置客户端所需证书
  882.  
  883. 涉及的参数主要是客户端自身的证书和私钥,以及用于验证etcd3的根CA证书:
  884.  
  885. etcd1
  886.  
  887. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd1-peer.pem"
  888. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd1-peer-key.pem"
  889. ETCD_PEER_CLIENT_CERT_AUTH="true"
  890. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  891.  
  892. 执行:
  893.  
  894. cat > /etc/etcd/etcd.conf <<EOF
  895. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  896. ETCD_LISTEN_PEER_URLS="http://192.168.0.91:2380"
  897. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.91:2379,http://127.0.0.1:2379"
  898. ETCD_NAME="etcd1"
  899. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.91:2380"
  900. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.91:2379"
  901. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  902. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  903.  
  904. #开启集群外部服务端认证
  905. ETCD_CERT_FILE="/etc/etcd/pki/etcd1.pem"
  906. ETCD_KEY_FILE="/etc/etcd/pki/etcd1-key.pem"
  907.  
  908. #开启集群外部客户端认证
  909. ETCD_CLIENT_CERT_AUTH="true"
  910. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  911.  
  912. #开启集群内部服务端认证同时带上客户端证书
  913. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd1-peer.pem"
  914. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd1-peer-key.pem"
  915. ETCD_PEER_CLIENT_CERT_AUTH="true"
  916. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  917. EOF
  918.  
  919. systemctl daemon-reload && systemctl restart etcd
  920.  
  921. etcd2
  922.  
  923. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd2-peer.pem"
  924. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd2-peer-key.pem"
  925. ETCD_PEER_CLIENT_CERT_AUTH="true"
  926. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  927.  
  928. 执行:
  929.  
  930. cat > /etc/etcd/etcd.conf <<EOF
  931. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  932. ETCD_LISTEN_PEER_URLS="http://192.168.0.92:2380"
  933. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.92:2379,http://127.0.0.1:2379"
  934. ETCD_NAME="etcd2"
  935. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.92:2380"
  936. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.92:2379"
  937. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=http://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  938. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  939.  
  940. #开启集群外部服务端认证
  941. ETCD_CERT_FILE="/etc/etcd/pki/etcd2.pem"
  942. ETCD_KEY_FILE="/etc/etcd/pki/etcd2-key.pem"
  943.  
  944. #开启集群外部客户端认证
  945. ETCD_CLIENT_CERT_AUTH="true"
  946. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  947.  
  948. #开启集群内部服务端认证同时带上客户端证书
  949. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd2-peer.pem"
  950. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd2-peer-key.pem"
  951. ETCD_PEER_CLIENT_CERT_AUTH="true"
  952. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  953. EOF
  954.  
  955. systemctl daemon-reload && systemctl restart etcd
  956.  
  957. 查看集群状态
  958.  
  959. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  960. 6c70a880257288f: name=etcd1 peerURLs=http://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  961. 3f7336e156287ed0: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  962. 5bbe42788a239cc6: name=etcd2 peerURLs=http://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  963.  
  964. 发现etcd3上的报错随即停
  965.  
  966. 注意:如果先在节点上修改配置文件启用https URL,再使用etcdctl指令修改集群的peer访问端点,在两步之间的时间里,实际上是客户端使用http协议访问服务器的https服务,
  967.  
  968. 这段时间实际集群间的通信是失败的。可在服务器上看到https请求被拒绝的错误:
  969.  
  970. [root@etcd3 ~]# systemctl status etcd -l
  971.  
  972. Jan 26 01:48:12 etcd3 etcd[2525]: rejected connection from "192.168.0.92:43682"
  973.  
  974. Jan 26 01:48:12 etcd3 etcd[2525]: rejected connection from "192.168.0.91:47588"
  975.  
  976. 7.2、修改etcd2节点为安全通信
  977.  
  978. 查看节点列表,获取节点标识
  979.  
  980. [root@etcd1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  981. adff72f24ac33f4b: name=etcd1 peerURLs=http://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  982. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  983. c96f41ba37a00a16: name=etcd2 peerURLs=http://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  984.  
  985. 修改etcd2节点的peer url为https
  986.  
  987. etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update adff72f24ac33f4b https://192.168.0.91:2380
  988.  
  989. 执行结果:
  990.  
  991. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update 5bbe42788a239cc6 https://192.168.0.91:2380
  992. Updated member with ID 5bbe42788a239cc6 in cluster
  993.  
  994. 重新检查节点列表和集群健康状态
  995.  
  996. [root@etcd3 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  997. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  998. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=true
  999. c96f41ba37a00a16: name=etcd2 peerURLs=http://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1000.  
  1001. [root@etcd3 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1002. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1003. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1004. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1005. cluster is healthy
  1006.  
  1007. 发现etcd2节点的peerURLs改成了https
  1008.  
  1009. 注意:如果发现peerURLs不是https,原因在于执行"修改etcd3节点的peer url为https步骤"的时候掉了步骤最后面的https://192.168.0.93:2380 或者ID不正确,重新执行几遍即可
  1010.  
  1011. 修改etcd2的peer工作端口为https
  1012.  
  1013. ETCD_LISTEN_PEER_URLS="https://192.168.0.91:2380"
  1014. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.91:2380"
  1015. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1016.  
  1017. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  1018. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  1019. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1020. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1021.  
  1022. 执行:
  1023.  
  1024. cat > /etc/etcd/etcd.conf <<EOF
  1025. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1026. ETCD_LISTEN_PEER_URLS="https://192.168.0.92:2380"
  1027. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.92:2379,http://127.0.0.1:2379"
  1028. ETCD_NAME="etcd2"
  1029. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.92:2380"
  1030. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.92:2379"
  1031. ETCD_INITIAL_CLUSTER="etcd1=http://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1032. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1033.  
  1034. #开启集群外部服务端认证
  1035. ETCD_CERT_FILE="/etc/etcd/pki/etcd2.pem"
  1036. ETCD_KEY_FILE="/etc/etcd/pki/etcd2-key.pem"
  1037.  
  1038. #开启集群外部客户端认证
  1039. ETCD_CLIENT_CERT_AUTH="true"
  1040. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1041.  
  1042. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd2-peer.pem"
  1043. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd2-peer-key.pem"
  1044. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1045. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1046. EOF
  1047.  
  1048. 重启
  1049.  
  1050. systemctl daemon-reload && systemctl restart etcd
  1051.  
  1052. 7.2、修改etcd1节点为安全通信
  1053.  
  1054. 查看节点列表,获取节点标识
  1055.  
  1056. [root@etcd1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1057. adff72f24ac33f4b: name=etcd1 peerURLs=http://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  1058. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  1059. c96f41ba37a00a16: name=etcd2 peerURLs=http://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1060.  
  1061. 修改etcd1节点的peer url为https
  1062.  
  1063. etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update c96f41ba37a00a16 https://192.168.0.91:2380
  1064.  
  1065. 执行结果:
  1066.  
  1067. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update adff72f24ac33f4b https://192.168.0.91:2380
  1068. membership: peerURL exists
  1069.  
  1070. 重新检查节点列表和集群健康状态
  1071.  
  1072. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1073. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1074. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=true
  1075. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1076.  
  1077. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1078. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1079. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1080. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1081. cluster is healthy
  1082.  
  1083. 发现etcd1节点 peerURLs变为https
  1084.  
  1085. 注意:如果发现peerURLs不是https,原因在于执行"修改etcd3节点的peer url为https步骤"的时候掉了步骤最后面的https://192.168.0.93:2380 或者ID不正确,重新执行几遍即可
  1086.  
  1087. 修改etcd1的peer工作端口为https
  1088.  
  1089. ETCD_LISTEN_PEER_URLS="https://192.168.0.92:2380"
  1090. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.92:2380"
  1091. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1092.  
  1093. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  1094. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  1095. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1096. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1097.  
  1098. 执行:
  1099.  
  1100. cat > /etc/etcd/etcd.conf <<EOF
  1101. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1102. ETCD_LISTEN_PEER_URLS="https://192.168.0.91:2380"
  1103. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.91:2379,http://127.0.0.1:2379"
  1104. ETCD_NAME="etcd1"
  1105. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.91:2380"
  1106. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.91:2379"
  1107. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1108. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1109.  
  1110. #开启集群外部服务端认证
  1111. ETCD_CERT_FILE="/etc/etcd/pki/etcd1.pem"
  1112. ETCD_KEY_FILE="/etc/etcd/pki/etcd1-key.pem"
  1113.  
  1114. #开启集群外部客户端认证
  1115. ETCD_CLIENT_CERT_AUTH="true"
  1116. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1117.  
  1118. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd1-peer.pem"
  1119. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd1-peer-key.pem"
  1120. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1121. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1122. EOF
  1123.  
  1124. 重启
  1125.  
  1126. systemctl daemon-reload && systemctl restart etcd
  1127.  
  1128. 重新检查节点列表和集群健康状态
  1129.  
  1130. [root@etcd3 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1131. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1132. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=true
  1133. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1134.  
  1135. [root@etcd3 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1136. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1137. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1138. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1139. cluster is healthy
  1140.  
  1141. 可以看到peerURLs改变为https模式
  1142.  
  1143. 如果先在节点上修改配置文件启用https URL,再使用etcdctl指令修改集群的peer访问端点,会报如下错误,所以最好是先使用etcdct指令修改访问端点,再修改服务器配置文件启用https。
  1144.  
  1145. [root@etcd3 ~]# systemctl status etcd -l
  1146. ● etcd.service - Etcd Server
  1147. Loaded: loaded (/usr/lib/systemd/system/etcd.service; enabled; vendor preset: disabled)
  1148. Active: active (running) since Sat 2019-01-26 01:43:20 EST; 4min 52s ago
  1149. Main PID: 2525 (etcd)
  1150. CGroup: /system.slice/etcd.service
  1151. └─2525 /usr/bin/etcd --name=etcd3 --data-dir=/var/lib/etcd/default.etcd --listen-client-urls=https://192.168.0.93:2379,http://127.0.0.1:2379
  1152.  
  1153. Jan 26 01:48:12 etcd3 etcd[2525]: rejected connection from "192.168.0.92:43682" (error "remote error: tls: bad certificate", ServerName "")
  1154. Jan 26 01:48:12 etcd3 etcd[2525]: rejected connection from "192.168.0.91:47588" (error "remote error: tls: bad certificate", ServerName "")
  1155. Jan 26 01:48:12 etcd3 etcd[2525]: rejected connection from "192.168.0.92:43684" (error "remote error: tls: bad certificate", ServerName "")
  1156. Jan 26 01:48:12 etcd3 etcd[2525]: rejected connection from "192.168.0.91:47590" (error "remote error: tls: bad certificate", ServerName "")
  1157.  
  1158. 7.3、所有文件改成https并重启
  1159.  
  1160. etcd1节点etcd配置文件
  1161.  
  1162. cat > /etc/etcd/etcd.conf <<EOF
  1163. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1164. ETCD_LISTEN_PEER_URLS="https://192.168.0.91:2380"
  1165. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.91:2379,http://127.0.0.1:2379"
  1166. ETCD_NAME="etcd1"
  1167. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.91:2380"
  1168. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.91:2379"
  1169. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1170. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1171.  
  1172. #开启集群外部服务端认证
  1173. ETCD_CERT_FILE="/etc/etcd/pki/etcd1.pem"
  1174. ETCD_KEY_FILE="/etc/etcd/pki/etcd1-key.pem"
  1175.  
  1176. #开启集群外部客户端认证
  1177. ETCD_CLIENT_CERT_AUTH="true"
  1178. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1179.  
  1180. #开启集群内部服务端认证并带上客户端证书
  1181. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd1-peer.pem"
  1182. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd1-peer-key.pem"
  1183. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1184. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1185. EOF
  1186.  
  1187. 重启
  1188.  
  1189. systemctl daemon-reload && systemctl restart etcd
  1190.  
  1191. etcd2节点etcd配置文件
  1192.  
  1193. cat >/etc/etcd/etcd.conf << EOF
  1194. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1195. ETCD_LISTEN_PEER_URLS="https://192.168.0.92:2380"
  1196. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.92:2379,http://127.0.0.1:2379"
  1197. ETCD_NAME="etcd2"
  1198. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.92:2380"
  1199. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.92:2379"
  1200. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1201. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1202.  
  1203. #开启集群外部服务端认证
  1204. ETCD_CERT_FILE="/etc/etcd/pki/etcd2.pem"
  1205. ETCD_KEY_FILE="/etc/etcd/pki/etcd2-key.pem"
  1206.  
  1207. #开启集群外部客户端认证
  1208. ETCD_CLIENT_CERT_AUTH="true"
  1209. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1210.  
  1211. #开启集群内部服务端认证并带上客户端证书
  1212. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd2-peer.pem"
  1213. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd2-peer-key.pem"
  1214. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1215. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1216. EOF
  1217.  
  1218. 重启
  1219.  
  1220. systemctl daemon-reload && systemctl restart etcd
  1221.  
  1222. etcd3节点etcd配置文件
  1223.  
  1224. cat >/etc/etcd/etcd.conf << EOF
  1225. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1226. ETCD_LISTEN_PEER_URLS="https://192.168.0.93:2380"
  1227. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.93:2379,http://127.0.0.1:2379"
  1228. ETCD_NAME="etcd3"
  1229. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.93:2380"
  1230. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.93:2379"
  1231. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1232. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1233.  
  1234. #开启集群外部服务端认证
  1235. ETCD_CERT_FILE="/etc/etcd/pki/etcd3.pem"
  1236. ETCD_KEY_FILE="/etc/etcd/pki/etcd3-key.pem"
  1237.  
  1238. #开启集群外部客户端认证
  1239. ETCD_CLIENT_CERT_AUTH="true"
  1240. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1241.  
  1242. #开启集群内部服务端认证并带上客户端证书
  1243. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  1244. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  1245. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1246. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1247. EOF
  1248.  
  1249. 重启
  1250.  
  1251. systemctl daemon-reload && systemctl restart etcd
  1252.  
  1253. 报错解决:
  1254.  
  1255. [root@etcd1 ~]# systemctl status etcd -l
  1256. ● etcd.service - Etcd Server
  1257. Loaded: loaded (/usr/lib/systemd/system/etcd.service; enabled; vendor preset: disabled)
  1258. Active: active (running) since Sat 2019-01-26 02:35:51 EST; 4min 18s ago
  1259. Main PID: 3117 (etcd)
  1260. CGroup: /system.slice/etcd.service
  1261. └─3117 /usr/bin/etcd --name=etcd1 --data-dir=/var/lib/etcd/default.etcd --listen-client-urls=https://192.168.0.91:2379,http://127.0.0.1:2379
  1262.  
  1263. Jan 26 02:35:51 etcd1 etcd[3117]: established a TCP streaming connection with peer c96f41ba37a00a16 (stream Message writer)
  1264. Jan 26 02:35:51 etcd1 etcd[3117]: established a TCP streaming connection with peer c883f9e325d8667d (stream MsgApp v2 writer)
  1265. Jan 26 02:35:51 etcd1 bash[3117]: WARNING: 2019/01/26 02:35:51 Failed to dial 192.168.0.91:2379: connection error: desc = "transport:
  1266.  
  1267. 查看错误: WARNING: 2019/01/26 02:35:51 Failed to dial 192.168.0.91:2379: connection error:
  1268.  
  1269. 原因:
  1270.  
  1271. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,k8s=https://192.168.0.92:2380,k8=https://192.168.0.93:2380"
  1272.  
  1273. 纠正:
  1274.  
  1275. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,k83=https://192.168.0.93:2380"
  1276.  
  1277. 重启
  1278.  
  1279. systemctl daemon-reload && systemctl restart etcd
  1280.  
  1281. 方式二:重建集群启用https
  1282.  
  1283. 注意:这种方式会丢失所有数据,一般在新建集群时使用。一般不使用这种方式
  1284.  
  1285. 集群节点的peer访问端点存储在数据目录,因此修改ETCD_INITIAL_CLUSTER参数后,最简单让其生效的方法就是重建集群。
  1286.  
  1287. 在所有节点上修改etcd配置文件,将peer的url修改为https,配置相关证书,以etcd3为例,涉及参数如下:
  1288.  
  1289. ETCD_LISTEN_PEER_URLS="https://192.168.0.93:2380"
  1290. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.93:2380"
  1291. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380"
  1292. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd1-peer.pem"
  1293. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd1-peer-key.pem"
  1294. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1295. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1296.  
  1297. [root@etcd3 ~]# cat /etc/etcd/etcd.conf
  1298. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1299. ETCD_LISTEN_PEER_URLS="https://192.168.0.93:2380"
  1300. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.93:2379,http://127.0.0.1:2379"
  1301. ETCD_NAME="etcd3"
  1302. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.93:2380"
  1303. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.93:2379"
  1304. ETCD_INITIAL_CLUSTER="etcd4=https://192.168.0.94:2380,etcd1=https://192.168.0.91:2380,etcd3=https://192.168.0.93:2380,etcd2=https://192.168.0.92:2380"
  1305. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1306. ETCD_INITIAL_CLUSTER_STATE="new"
  1307.  
  1308. ETCD_CERT_FILE="/etc/etcd/pki/etcd.pem"
  1309. ETCD_KEY_FILE="/etc/etcd/pki/etcd-key.pem"
  1310.  
  1311. ETCD_CLIENT_CERT_AUTH="true"
  1312. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1313.  
  1314. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  1315. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  1316. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1317. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1318.  
  1319. 在所有节点上删除已有实例,重启etcd。
  1320.  
  1321. systemctl stop etcd
  1322. rm -rf /var/lib/etcd/default.etcd
  1323. systemctl daemon-reload && systemctl restart etcd
  1324.  
  1325. 8、etcd节点扩容
  1326.  
  1327. 8.1、安装etcd
  1328.  
  1329. 本文通篇注意:对于新加入的成员,新成员自己每次修改配置文件后如果重启失败,那么新成员本身需要删除残留成员目录,且lesder节点需要剔除新成员才可以启动。
  1330.  
  1331. 假如要扩容etcd4节点
  1332.  
  1333. etc4节点设置主机名、关闭防火墙、关闭selinux
  1334.  
  1335. sed -i '$a\hostname=test4' /etc/sysconfig/network && hostnamectl set-hostname test4
  1336.  
  1337. sed -i '$a\test4' /etc/hostname
  1338.  
  1339. cat >>/etc/hosts<< EOF
  1340. 192.168.0.91 test1
  1341. 192.168.0.92 test2
  1342. 192.168.0.93 test3
  1343. 192.168.0.94 test1
  1344. EOF
  1345.  
  1346. 重启
  1347.  
  1348. 重启目的是让主机名永久生效
  1349.  
  1350. reboot
  1351.  
  1352. 配置免密登录
  1353.  
  1354. 配置ntp服务器保证所有节点时间一致 ,参照 https://www.cnblogs.com/effortsing/p/10011459.html(这一步非必须)
  1355.  
  1356. etcd4节点安装、启动etcd
  1357.  
  1358. yum install -y etcd
  1359.  
  1360. systemctl start etcd && systemctl enable etcd
  1361.  
  1362. 查看状态
  1363.  
  1364. etcdctl cluster-health
  1365. member 8e9e05c52164694d is healthy: got healthy result from http://localhost:2379
  1366.  
  1367. 不安装etcd也可以添加新成员,这是添加了也没有用
  1368.  
  1369. 注意:安装完etcd后就可以在leader上添加新成员了,但是这个时候不要添加,严格按照步骤做,否则会报各种错误。
  1370.  
  1371. 8.2、以集群模式启动
  1372.  
  1373. 停掉etcd
  1374.  
  1375. systemctl stop etcd
  1376.  
  1377. 修改配置文件
  1378.  
  1379. cat > /etc/etcd/etcd.conf<< EOF
  1380. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1381. ETCD_LISTEN_PEER_URLS="http://192.168.0.94:2380"
  1382. ETCD_LISTEN_CLIENT_URLS="http://192.168.0.94:2379,http://127.0.0.1:2379"
  1383. ETCD_NAME="etcd4"
  1384. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.94:2380"
  1385. ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.94:2379"
  1386. ETCD_INITIAL_CLUSTER="etcd4=http://192.168.0.94:2380"
  1387. ETCD_INITIAL_CLUSTER_STATE="new"
  1388. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1389. EOF
  1390.  
  1391. 注意:ETCD_INITIAL_CLUSTER_STATE="new" 这个new代表新成员,没有这句话是无法加入的
  1392.  
  1393. 删除原来成员
  1394.  
  1395. 必须删除原来成员,否则导致冲突,无法启动
  1396.  
  1397. rm -rf /var/lib/etcd/default.etcd
  1398.  
  1399. 启动
  1400.  
  1401. systemctl daemon-reload && systemctl restart etcd
  1402.  
  1403. 8.3、leader节点上添加新成员
  1404.  
  1405. 原集群的三个节点,其中有一个是leader节点,可以通过查看成员列表看到,isLeader=true,必须在leader节点上添加,否则报错。
  1406.  
  1407. 如果出现如下错误,说明之前添加过该成员,但是没有剔除,所以再次添加该成员时候会如下报错;
  1408.  
  1409. 如果没有出现如下错误,说明之前没有添加过该成员。之前实验的集群中添加过etcd4节点,但是没有剔除etcd4,后来把etcd4虚拟机删除后重新克隆了一份,所以会报如下错误。
  1410.  
  1411. etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member add etcd4 http://192.168.0.94:2380
  1412.  
  1413. 如果出现如下错误:
  1414.  
  1415. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member add etcd4 http://192.168.0.94:2380
  1416. client: etcd cluster is unavailable or misconfigured; error #0: client: etcd member https://192.168.0.93:2379 has no leader
  1417. ; error #1: client: etcd member https://192.168.0.91:2379 has no leader
  1418. ; error #2: client: etcd member https://192.168.0.92:2379 has no leader
  1419. ; error #3: EOF
  1420.  
  1421. 如果添加失败有两种情况
  1422.  
  1423. 第一种情况:
  1424.  
  1425. 是因为原有集群中已经有etcd4节点了,需要删除该节点后才可以添加,删除操作看下面:
  1426.  
  1427. 先查看成员列表
  1428.  
  1429. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1430. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1431. bc721669bdca5256[unstarted]: peerURLs=http://192.168.0.94:2380
  1432. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  1433. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=true
  1434.  
  1435. 发现果然存在etcd4成员,这是之前残留的,剔除掉,否则冲突导致无法添加
  1436.  
  1437. 删除etcd4节点
  1438.  
  1439. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member remove bc721669bdca5256
  1440. Removed member bc721669bdca5256 from cluster
  1441.  
  1442. 再次查看成员列表
  1443.  
  1444. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1445. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1446. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=true
  1447. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1448.  
  1449. 发现没有了etcd4节点
  1450.  
  1451. 第二种情况:
  1452.  
  1453. 查看leader节点日志如下
  1454.  
  1455. [root@test1 pki]# journalctl -xe
  1456. Jan 28 08:55:18 test1 etcd[2267]: failed to find member 6c70a880257288f in cluster a03ca7b6ecf1d2d4
  1457. Jan 28 08:55:18 test1 etcd[2267]: failed to find member 6c70a880257288f in cluster a03ca7b6ecf1d2d4
  1458. Jan 28 08:55:18 test1 etcd[2267]: streaming request ignored (ID mismatch got 5bbe42788a239cc6 want 6c70a880257288f)
  1459. Jan 28 08:55:18 test1 etcd[2267]: streaming request ignored (ID mismatch got 5bbe42788a239cc6 want 6c70a880257288f)
  1460. Jan 28 08:55:18 test1 etcd[2267]: failed to find member 6c70a880257288f in cluster a03ca7b6ecf1d2d4
  1461.  
  1462. 再查看之前执行的命令过程
  1463.  
  1464. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1465. 6c70a880257288f: name=etcd1 peerURLs=http://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1466. 3f7336e156287ed0: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=true
  1467. 5bbe42788a239cc6: name=etcd2 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1468. 62f2353f81e89de3[unstarted]: peerURLs=http://192.168.0.94:2380
  1469.  
  1470. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update 6c70a880257288f https://192.168.0.4:2380
  1471. Updated member with ID 6c70a880257288f in cluster
  1472.  
  1473. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1474. 6c70a880257288f: name=etcd1 peerURLs=https://192.168.0.4:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1475. 3f7336e156287ed0: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=true
  1476. 5bbe42788a239cc6: name=etcd2 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1477. 62f2353f81e89de3[unstarted]: peerURLs=http://192.168.0.94:2380
  1478.  
  1479. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member remove 62f2353f81e89de3
  1480. Removed member 62f2353f81e89de3 from cluster
  1481.  
  1482. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1483. 6c70a880257288f: name=etcd1 peerURLs=https://192.168.0.4:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1484. 3f7336e156287ed0: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=true
  1485. 5bbe42788a239cc6: name=etcd2 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1486.  
  1487. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member add etcd4 http://192.168.0.94:2380
  1488. client: etcd cluster is unavailable or misconfigured; error #0: client: etcd member https://192.168.0.92:2379 has no leader
  1489. ; error #1: client: etcd member https://192.168.0.91:2379 has no leader
  1490. ; error #2: client: etcd member https://192.168.0.93:2379 has no leader
  1491.  
  1492. [root@test1 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update 6c70a880257288f https://192.168.0.4:2380
  1493. Updated member with ID 6c70a880257288f in cluster
  1494.  
  1495. 上面是之前执行的命令,找出update 6c70a880257288f https://192.168.0.4:2380,这里看出来把etcd1的id更新成了 https://192.168.0.4:2380,ip也没写全,
  1496.  
  1497. 然后又剔除了62f2353f81e89de3,然后又开始添加etcd4节点,之后就开始报错。
  1498.  
  1499. 解决:
  1500.  
  1501. 原理:把etcd1节点剔除重新添加即可,但是我没有做成。
  1502.  
  1503. leader节点上剔除etcd1
  1504.  
  1505. [root@test3 pki]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member remove 6c70a880257288f
  1506. Removed member 6c70a880257288f from cluster
  1507.  
  1508. 添加etcd1
  1509.  
  1510. [root@test3 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member add etcd1 http://192.168.0.91:2380
  1511. Added member named etcd1 with ID f62393f31ba7a865 to cluster
  1512.  
  1513. ETCD_NAME="etcd1"
  1514. ETCD_INITIAL_CLUSTER="etcd3=https://192.168.0.93:2380,etcd2=https://192.168.0.91:2380,etcd1=http://192.168.0.91:2380"
  1515. ETCD_INITIAL_CLUSTER_STATE="existing"
  1516.  
  1517. 暂时先不用etcd1了
  1518.  
  1519. 再次添加新成员
  1520.  
  1521. etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member add etcd4 http://192.168.0.94:2380
  1522.  
  1523. 执行结果:
  1524.  
  1525. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member add etcd4 http://192.168.0.94:2380
  1526. Added member named etcd4 with ID 7cdd9649a07e40fb to cluster
  1527.  
  1528. ETCD_NAME="etcd4"
  1529. ETCD_INITIAL_CLUSTER="etcd4=http://192.168.0.94:2380,etcd1=https://192.168.0.91:2380,etcd3=https://192.168.0.93:2380,etcd2=https://192.168.0.92:2380"
  1530. ETCD_INITIAL_CLUSTER_STATE="existing"
  1531.  
  1532. 到此添加成功
  1533.  
  1534. 查看节点列表和集群健康状态
  1535.  
  1536. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1537. 7cdd9649a07e40fb[unstarted]: peerURLs=http://192.168.0.94:2380
  1538. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=false
  1539. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  1540. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=true
  1541.  
  1542. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1543. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1544. member 7cdd9649a07e40fb is unreachable: no available published client urls
  1545. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1546. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1547. cluster is healthy
  1548.  
  1549. 刚添加完新成员看到集群时不健康的,需要修改etcd4配置文件,进行如下操作
  1550.  
  1551. 8.4、纠正集群为健康状态
  1552.  
  1553. 创建证书目录
  1554.  
  1555. mkdir -p /etc/etcd/pki/
  1556.  
  1557. 拷贝根证书并授权
  1558.  
  1559. scp root@192.168.0.91:/etc/etcd/pki/rootca* /etc/etcd/pki/
  1560.  
  1561. 生成etcd4服务端证书
  1562.  
  1563. cfssl print-defaults csr > etcd4-csr.json
  1564. vi etcd4-csr.json
  1565.  
  1566. cat >etcd4-csr.json <<EOF
  1567. {
  1568. "CN": "ETCD Peer on etcd4",
  1569. "hosts": [
  1570. "192.168.0.94"
  1571. ],
  1572. "key": {
  1573. "algo": "ecdsa",
  1574. "size": 256
  1575. },
  1576. "names": [
  1577. {
  1578. "C": "US",
  1579. "L": "CA",
  1580. "ST": "San Francisco"
  1581. }
  1582. ]
  1583. }
  1584. EOF
  1585.  
  1586. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=server etcd4-csr.json | cfssljson -bare etcd4
  1587.  
  1588. 拷贝服务端证书并授权
  1589.  
  1590. scp /etc/etcd/pki/etcd4*.pem root@192.168.0.94:/etc/etcd/pki/
  1591.  
  1592. 生成peer4证书
  1593.  
  1594. cfssl print-defaults csr > etcd4-peer-csr.json
  1595. vi etcd4-csr.json
  1596.  
  1597. cat >etcd4-peer-csr.json<<EOF
  1598. {
  1599. "CN": "ETCD Peer on etcd4",
  1600. "hosts": [
  1601. "192.168.0.94"
  1602. ],
  1603. "key": {
  1604. "algo": "ecdsa",
  1605. "size": 256
  1606. },
  1607. "names": [
  1608. {
  1609. "C": "US",
  1610. "L": "CA",
  1611. "ST": "San Francisco"
  1612. }
  1613. ]
  1614. }
  1615. EOF
  1616.  
  1617. cfssl gencert -ca=rootca.pem -ca-key=rootca-key.pem -config=ca-config.json -profile=peer etcd4-peer-csr.json | cfssljson -bare etcd4-peer
  1618.  
  1619. 拷贝peer4证书并授权
  1620.  
  1621. scp /etc/etcd/pki/etcd4-peer*.pem root@192.168.0.94:/etc/etcd/pki/
  1622.  
  1623. 给所有证书授权
  1624.  
  1625. chown -R etcd:etcd /etc/etcd/pki/*
  1626.  
  1627. 修改etcd4配置文件
  1628.  
  1629. 把添加新成员那一步生成的结果写到配置文件里面
  1630.  
  1631. 注意:可不跨越步骤,直接进行下一步操作,否则无法启动,会报各种错误
  1632.  
  1633. 注意:添加PEER参数改变了集群内部通信方式需要删除实例后重启
  1634.  
  1635. cat > /etc/etcd/etcd.conf << EOF
  1636. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1637. ETCD_LISTEN_PEER_URLS="http://192.168.0.94:2380"
  1638. ETCD_LISTEN_CLIENT_URLS="http://192.168.0.94:2379,http://127.0.0.1:2379"
  1639. ETCD_NAME="etcd4"
  1640. ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.0.94:2380"
  1641. ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.94:2379"
  1642. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380,etcd4=http://192.168.0.94:2380"
  1643. ETCD_INITIAL_CLUSTER_STATE="existing"
  1644. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1645. #带上集群内部客户端证书同时开启集群内部服务端认证
  1646. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd4-peer.pem"
  1647. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd4-peer-key.pem"
  1648. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1649. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1650. EOF
  1651.  
  1652. 注意:本次修改不能修改peerURLs、clientURLs为https模式,试过多次,修改后总是无法启动。遵循之前的过程,逐步替换为https模式,
  1653.  
  1654. 注意:本次修改配置文件里面必须要带上peer证书和开启服务端认证,否则无法启动,会报如下错误。因为从添加新成员产生的结果看到其他节点都是安全访问模式,
  1655.  
  1656. 所以配置文件里面要带上客户端证书才可以访问安全端口,peer证书既是服务端证书又是客户端证书
  1657.  
  1658. 启动
  1659.  
  1660. systemctl daemon-reload && systemctl restart etcd
  1661.  
  1662. 如果启动失败:
  1663.  
  1664. [root@etcd4 ~]# systemctl daemon-reload && systemctl restart etcd
  1665. Job for etcd.service failed because the control process exited with error code. See "systemctl status etcd.service" and "journalctl -xe" for details.
  1666. [root@etcd4 ~]# journalctl -xe
  1667. Jan 27 22:08:31 etcd4 etcd[1638]: listening for client requests on 127.0.0.1:2379
  1668. Jan 27 22:08:31 etcd4 etcd[1638]: listening for client requests on 192.168.0.94:2379
  1669. Jan 27 22:08:31 etcd4 etcd[1638]: open /etc/etcd/pki/etcd4-peer-key.pem: permission denied
  1670. Jan 27 22:08:31 etcd4 systemd[1]: etcd.service: main process exited, code=exited, status=1/FAILURE
  1671. Jan 27 22:08:31 etcd4 systemd[1]: Failed to start Etcd Server.
  1672.  
  1673. 发现看到倒数第三行错误:open /etc/etcd/pki/etcd4-peer-key.pem: permission denied 是因为权限不足问题导致启动失败
  1674.  
  1675. 添加授权
  1676.  
  1677. chown -R etcd:etcd /etc/etcd/pki/*
  1678.  
  1679. 再次重启:
  1680.  
  1681. systemctl daemon-reload && systemctl restart etcd
  1682.  
  1683. 启动成功
  1684.  
  1685. 本文通篇注意:对于新加入的成员,每次修改配置文件后如果启动失败就需要删除本节点残留成员目录,而且需要从lesder节点剔除新成员,否则会有冲突,导致无法启动成功,
  1686.  
  1687. 查看节点列表和集群健康状态
  1688.  
  1689. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1690. 7cdd9649a07e40fb[unstarted]: peerURLs=http://192.168.0.94:2380
  1691. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  1692. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  1693. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1694.  
  1695. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1696. member 7cdd9649a07e40fb is unreachable: no available published client urls
  1697. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1698. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1699. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1700. cluster is healthy
  1701.  
  1702. 如果发现集群仍然是不健康状态,就需要删除残留成员目录并重启,如果是健康的,跳过下一步
  1703.  
  1704. 查看日志报错
  1705.  
  1706. [root@etcd4 ~]# systemctl status etcd
  1707. ● etcd.service - Etcd Server
  1708. Loaded: loaded (/usr/lib/systemd/system/etcd.service; enabled; vendor preset: disabled)
  1709. Active: active (running) since Sun 2019-01-27 21:50:28 EST; 17min ago
  1710. Main PID: 1533 (etcd)
  1711. CGroup: /system.slice/etcd.service
  1712. └─1533 /usr/bin/etcd --name=etcd4 --data-dir=/var/lib/etcd/default.etcd --listen-client-urls=http://192.168.0.94:2379,ht...
  1713.  
  1714. Jan 27 22:08:16 etcd4 etcd[1533]: request cluster ID mismatch (got 9488eae2b4328f45 want 29ae782d95021b85)
  1715. Jan 27 22:08:16 etcd4 etcd[1533]: request cluster ID mismatch (got 9488eae2b4328f45 want 29ae782d95021b85)
  1716. Jan 27 22:08:16 etcd4 etcd[1533]: request cluster ID mismatch (got 9488eae2b4328f45 want 29ae782d95021b85)
  1717. Jan 27 22:08:16 etcd4 etcd[1533]: request cluster ID mismatch (got 9488eae2b4328f45 want 29ae782d95021b85)
  1718. Jan 27 22:08:16 etcd4 etcd[1533]: request cluster ID mismatch (got 9488eae2b4328f45 want 29ae782d95021b85)
  1719. Jan 27 22:08:16 etcd4 etcd[1533]: request cluster ID mismatch (got 9488eae2b4328f45 want 29ae782d95021b85)
  1720.  
  1721. 发现上面错误说明数据目录中的成员和请求要加入的成员不匹配,删除本节点数据目录重启即可
  1722.  
  1723. 删除残留成员目录并重启
  1724.  
  1725. systemctl stop etcd
  1726. rm -rf /var/lib/etcd/default.etcd
  1727. systemctl daemon-reload && systemctl restart etcd
  1728.  
  1729. 如果删除后无法启动就查看日志报错,对应解决即可
  1730.  
  1731. 例如下面错误:
  1732.  
  1733. [root@test1 pki]# systemctl daemon-reload && systemctl restart etcd
  1734. Jan 28 09:57:01 test1 etcd[3687]: couldn't find local name "etcd4" in the initial cluster configuration
  1735.  
  1736. 从错误中很容易解决的,就是配置文件里面的名义定义错误了,
  1737.  
  1738. 如果解决完错误还是无法启动,那就剔除掉新成员重新添加,重复这个过程,直至提添加成功。
  1739.  
  1740. 再次查看节点列表和集群健康状态
  1741.  
  1742. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1743. 7cdd9649a07e40fb: name=etcd4 peerURLs=http://192.168.0.94:2380 clientURLs=http://192.168.0.94:2379 isLeader=false
  1744. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  1745. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  1746. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1747.  
  1748. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1749. member 7cdd9649a07e40fb is healthy: got healthy result from http://192.168.0.94:2379
  1750. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1751. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1752. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1753. cluster is healthy
  1754.  
  1755. 可以看到集群已经是健康状态,但是peerURLs、clientURLs 都还不是https安全模式,下面就要修改为安全模式
  1756.  
  1757. 先看下日志
  1758.  
  1759. [root@etcd4 ~]# journalctl -xe
  1760. Jan 27 11:52:53 etcd4 etcd[3657]: could not get cluster response from https://192.168.0.92:2380: Get https://192.168.0.92:2380/members
  1761. Jan 27 11:52:53 etcd4 etcd[3657]: could not get cluster response from https://192.168.0.93:2380: Get https://192.168.0.93:2380/members
  1762. Jan 27 11:52:53 etcd4 etcd[3657]: cannot fetch cluster info from peer urls: could not retrieve cluster information from the given urls
  1763. Jan 27 11:52:53 etcd4 systemd[1]: etcd.service: main process exited, code=exited, status=1/FAILURE
  1764. Jan 27 11:52:53 etcd4 systemd[1]: Failed to start Etcd Server.
  1765.  
  1766. 出现上面报错没有关系,继续进行下面操作:修改为安全模式
  1767.  
  1768. 8.5、开启集群peer安全模式
  1769.  
  1770. 修改etcd4节点的peer url为https
  1771.  
  1772. etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update 7cdd9649a07e40fb https://192.168.0.4:2380
  1773.  
  1774. 执行结果:
  1775.  
  1776. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member update 7cdd9649a07e40fb https://192.168.0.4:2380
  1777. Updated member with ID 7cdd9649a07e40fb in cluster
  1778.  
  1779. 修改etcd4的peer工作端口为https;同时修改client工作端口为https,修改client url为https,带上证书
  1780.  
  1781. cat >/etc/etcd/etcd.conf << EOF
  1782. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1783. ETCD_LISTEN_PEER_URLS="https://192.168.0.94:2380"
  1784. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.94:2379,http://127.0.0.1:2379"
  1785. ETCD_NAME="etcd4"
  1786. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.94:2380"
  1787. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.94:2379"
  1788. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380,etcd4=https://192.168.0.94:2380"
  1789. ETCD_INITIAL_CLUSTER_STATE="existing"
  1790. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1791.  
  1792. #集群内部互相通信用的证书
  1793. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd4-peer.pem"
  1794. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd4-peer-key.pem"
  1795.  
  1796. # 开启集群内部客户端认证
  1797. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1798. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1799.  
  1800. # 开启集群外部服务端认证
  1801. ETCD_CERT_FILE="/etc/etcd/pki/etcd4.pem"
  1802. ETCD_KEY_FILE="/etc/etcd/pki/etcd4-key.pem"
  1803.  
  1804. # 开启集群外部客户端认证
  1805. ETCD_CLIENT_CERT_AUTH="true"
  1806. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1807. EOF
  1808.  
  1809. 启动
  1810.  
  1811. systemctl daemon-reload && systemctl restart etcd
  1812.  
  1813. 查看节点列表和集群健康状态
  1814.  
  1815. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1816. 7cdd9649a07e40fb: name=etcd4 peerURLs=https://192.168.0.94:2380 clientURLs=http://192.168.0.94:2379 isLeader=false
  1817. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  1818. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  1819. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1820.  
  1821. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1822. member 7cdd9649a07e40fb is healthy: got healthy result from https://192.168.0.94:2379
  1823. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1824. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1825. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1826. cluster is healthy
  1827.  
  1828. 如果看到etcd4节点peerURLs已经是https模式了
  1829.  
  1830. 注意:如果发现peerURLs不是https,原因在于执行"修改etcd3节点的peer url为https步骤"的时候掉了步骤最后面的https://192.168.0.93:2380 或者ID不正确,重新执行几遍即可
  1831.  
  1832. 在etcd4节点上查看日志
  1833.  
  1834. [root@etcd4 ~]# journalctl -xe
  1835. Jan 27 13:25:06 etcd4 etcd[3926]: rejected connection from "192.168.0.91:55218" (error "tls: first record does not look like a TLS han
  1836. Jan 27 13:25:06 etcd4 etcd[3926]: rejected connection from "192.168.0.91:55220" (error "tls: first record does not look like a TLS han
  1837. Jan 27 13:25:06 etcd4 etcd[3926]: rejected connection from "192.168.0.93:42674" (error "tls: first record does not look like a TLS han
  1838. Jan 27 13:25:06 etcd4 etcd[3926]: rejected connection from "192.168.0.93:42676" (error "tls: first record does not look like a TLS han
  1839.  
  1840. 让然有报错,需要修改所有节点一致
  1841.  
  1842. 8.6、修改所有节点配置文件一致并重启
  1843.  
  1844. 主要修改http改成https:ETCD_INITIAL_CLUSTER="etcd4=https://192.168.0.94:2380"
  1845.  
  1846. 修改etcd1
  1847.  
  1848. cat > /etc/etcd/etcd.conf<< EOF
  1849. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1850. ETCD_LISTEN_PEER_URLS="https://192.168.0.91:2380"
  1851. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.91:2379,http://127.0.0.1:2379"
  1852. ETCD_NAME="etcd1"
  1853. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.91:2380"
  1854. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.91:2379"
  1855. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380,etcd4=https://192.168.0.94:2380"
  1856. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1857. ETCD_INITIAL_CLUSTER_STATE="new"
  1858.  
  1859. ETCD_CERT_FILE="/etc/etcd/pki/etcd1.pem"
  1860. ETCD_KEY_FILE="/etc/etcd/pki/etcd1-key.pem"
  1861. ETCD_CLIENT_CERT_AUTH="true"
  1862. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1863.  
  1864. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd1-peer.pem"
  1865. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd1-peer-key.pem"
  1866. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1867. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1868. EOF
  1869.  
  1870. 重启
  1871.  
  1872. systemctl daemon-reload && systemctl restart etcd
  1873.  
  1874. 修改etcd2
  1875.  
  1876. cat > /etc/etcd/etcd.conf<< EOF
  1877. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1878. ETCD_LISTEN_PEER_URLS="https://192.168.0.92:2380"
  1879. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.92:2379,http://127.0.0.1:2379"
  1880. ETCD_NAME="etcd2"
  1881. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.92:2380"
  1882. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.92:2379"
  1883. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380,etcd4=https://192.168.0.94:2380"
  1884. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1885. ETCD_INITIAL_CLUSTER_STATE="new"
  1886.  
  1887. ETCD_CERT_FILE="/etc/etcd/pki/etcd2.pem"
  1888. ETCD_KEY_FILE="/etc/etcd/pki/etcd2-key.pem"
  1889.  
  1890. ETCD_CLIENT_CERT_AUTH="true"
  1891. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1892.  
  1893. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd2-peer.pem"
  1894. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd2-peer-key.pem"
  1895. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1896. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1897. EOF
  1898.  
  1899. 重启
  1900.  
  1901. systemctl daemon-reload && systemctl restart etcd
  1902.  
  1903. 修改etcd3
  1904.  
  1905. cat > /etc/etcd/etcd.conf<< EOF
  1906. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1907. ETCD_LISTEN_PEER_URLS="https://192.168.0.93:2380"
  1908. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.93:2379,http://127.0.0.1:2379"
  1909. ETCD_NAME="etcd3"
  1910. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.93:2380"
  1911. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.93:2379"
  1912. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380,etcd4=https://192.168.0.94:2380"
  1913. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1914. ETCD_INITIAL_CLUSTER_STATE="new"
  1915.  
  1916. ETCD_CERT_FILE="/etc/etcd/pki/etcd3.pem"
  1917. ETCD_KEY_FILE="/etc/etcd/pki/etcd3-key.pem"
  1918.  
  1919. ETCD_CLIENT_CERT_AUTH="true"
  1920. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1921.  
  1922. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  1923. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  1924. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1925. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1926. EOF
  1927.  
  1928. 重启
  1929.  
  1930. systemctl daemon-reload && systemctl restart etcd
  1931.  
  1932. 修改etcd4
  1933.  
  1934. cat > /etc/etcd/etcd.conf<< EOF
  1935. ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  1936. ETCD_LISTEN_PEER_URLS="https://192.168.0.93:2380"
  1937. ETCD_LISTEN_CLIENT_URLS="https://192.168.0.93:2379,http://127.0.0.1:2379"
  1938. ETCD_NAME="etcd3"
  1939. ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.93:2380"
  1940. ETCD_ADVERTISE_CLIENT_URLS="https://192.168.0.93:2379"
  1941. ETCD_INITIAL_CLUSTER="etcd1=https://192.168.0.91:2380,etcd2=https://192.168.0.92:2380,etcd3=https://192.168.0.93:2380,etcd4=https://192.168.0.94:2380"
  1942. ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
  1943. ETCD_INITIAL_CLUSTER_STATE="new"
  1944.  
  1945. ETCD_CERT_FILE="/etc/etcd/pki/etcd4.pem"
  1946. ETCD_KEY_FILE="/etc/etcd/pki/etcd4-key.pem"
  1947.  
  1948. ETCD_CLIENT_CERT_AUTH="true"
  1949. ETCD_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1950.  
  1951. ETCD_PEER_CERT_FILE="/etc/etcd/pki/etcd3-peer.pem"
  1952. ETCD_PEER_KEY_FILE="/etc/etcd/pki/etcd3-peer-key.pem"
  1953. ETCD_PEER_CLIENT_CERT_AUTH="true"
  1954. ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/pki/rootca.pem"
  1955. EOF
  1956.  
  1957. 重启
  1958.  
  1959. systemctl daemon-reload && systemctl restart etcd
  1960.  
  1961. 查看节点列表和集群健康状态
  1962.  
  1963. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1964. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  1965. c775cff37a58077c: name=etcd4 peerURLs=https://192.168.0.94:2380 clientURLs=https://192.168.0.94:2379 isLeader=false
  1966. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  1967. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  1968.  
  1969. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem cluster-health
  1970. member adff72f24ac33f4b is healthy: got healthy result from https://192.168.0.91:2379
  1971. member c775cff37a58077c is healthy: got healthy result from https://192.168.0.94:2379
  1972. member c883f9e325d8667d is healthy: got healthy result from https://192.168.0.93:2379
  1973. member c96f41ba37a00a16 is healthy: got healthy result from https://192.168.0.92:2379
  1974. cluster is healthy
  1975.  
  1976. 可以看到全部是https模式
  1977.  
  1978. 在etcd4节点上查看日志
  1979.  
  1980. [root@etcd4 ~]# journalctl -xe
  1981. Jan 27 16:57:45 etcd4 etcd[5902]: rejected connection from "192.168.0.93:39910" (error "EOF", ServerName "")
  1982. Jan 27 16:57:45 etcd4 etcd[5902]: rejected connection from "192.168.0.93:39914" (error "EOF", ServerName "")
  1983. Jan 27 16:57:46 etcd4 etcd[5902]: peer c883f9e325d8667d became active
  1984. Jan 27 16:57:46 etcd4 etcd[5902]: established a TCP streaming connection with peer c883f9e325d8667d (stream MsgApp v2 reader)
  1985. Jan 27 16:57:46 etcd4 etcd[5902]: established a TCP streaming connection with peer c883f9e325d8667d (stream Message reader)
  1986.  
  1987. 仍然报错,暂时未解决,不影响使用
  1988.  
  1989. 9、删除成员
  1990.  
  1991. 注意:删除成员是针对新成员来说的,对于原有集群成员,不能随便删除,因为已经有很多数据。如果必须删除,需要做备份迁移后才可以删除
  1992.  
  1993. 例如要删除etcd4成员
  1994.  
  1995. 先查看成员列表
  1996.  
  1997. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member list
  1998. 1da3d0181b2c051: name=etcd4 peerURLs=http://192.168.0.94:2380 clientURLs=http://192.168.0.94:2379 isLeader=false
  1999. adff72f24ac33f4b: name=etcd1 peerURLs=https://192.168.0.91:2380 clientURLs=https://192.168.0.91:2379 isLeader=true
  2000. c883f9e325d8667d: name=etcd3 peerURLs=https://192.168.0.93:2380 clientURLs=https://192.168.0.93:2379 isLeader=false
  2001. c96f41ba37a00a16: name=etcd2 peerURLs=https://192.168.0.92:2380 clientURLs=https://192.168.0.92:2379 isLeader=false
  2002.  
  2003. 剔除成员
  2004.  
  2005. etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member remove 1da3d0181b2c051
  2006.  
  2007. 执行结果:
  2008.  
  2009. [root@etcd1 ~]# etcdctl --ca-file /etc/etcd/pki/rootca.pem --cert-file /etc/etcd/pki/etcdctl.pem --key-file /etc/etcd/pki/etcdctl-key.pem member remove 1da3d0181b2c051
  2010. Removed member 1da3d0181b2c051 from cluster
  2011.  
  2012. 停掉etcd服务
  2013.  
  2014. systemctl stop etcd
  2015.  
  2016. 删除成员目录
  2017.  
  2018. rm -rf /var/lib/etcd/default.etcd
  2019.  
  2020. 如果上面不按顺序来,再次添加完成员客户端是无法启动的,会报如下错误,看里面提示 the data-dir used by this member must be removed.
  2021.  
  2022. [root@etcd4 ~]# systemctl daemon-reload && systemctl restart etcd
  2023. [root@etcd4 ~]# systemctl status etcd -l
  2024. ● etcd.service - Etcd Server
  2025. Loaded: loaded (/usr/lib/systemd/system/etcd.service; enabled; vendor preset: disabled)
  2026. Active: inactive (dead) since Sun 2019-01-27 14:38:29 CST; 1s ago
  2027. Process: 4503 ExecStart=/bin/bash -c GOMAXPROCS=$(nproc) /usr/bin/etcd --name="${ETCD_NAME}" --data-dir="${ETCD_DATA_DIR}" --listen-client-urls="${ETCD_LISTEN_CLIENT_URLS}" (code=exited, status=0/SUCCESS)
  2028. Main PID: 4503 (code=exited, status=0/SUCCESS)
  2029.  
  2030. Jan 27 14:38:29 etcd4 etcd[4503]: the data-dir used by this member must be removed.
  2031. Jan 27 14:38:29 etcd4 etcd[4503]: aborting publish because server is stopped
  2032. Jan 27 14:38:29 etcd4 etcd[4503]: stopping peer c96f41ba37a00a16...
  2033. Jan 27 14:38:29 etcd4 etcd[4503]: stopped streaming with peer c96f41ba37a00a16 (writer)
  2034. Jan 27 14:38:29 etcd4 etcd[4503]: stopped streaming with peer c96f41ba37a00a16 (writer)
  2035. Jan 27 14:38:29 etcd4 etcd[4503]: stopped HTTP pipelining with peer c96f41ba37a00a16
  2036. Jan 27 14:38:29 etcd4 etcd[4503]: stopped streaming with peer c96f41ba37a00a16 (stream MsgApp v2 reader)
  2037. Jan 27 14:38:29 etcd4 etcd[4503]: stopped streaming with peer c96f41ba37a00a16 (stream Message reader)
  2038. Jan 27 14:38:29 etcd4 etcd[4503]: stopped peer c96f41ba37a00a16
  2039. Jan 27 14:38:29 etcd4 systemd[1]: Started Etcd Server.
  2040.  
  2041. 参照文档:
  2042.  
  2043. https://www.jianshu.com/p/3015d514bae3
  2044. https://lprincewhn.github.io/2018/09/15/etcd-ha-pki-01.html
  2045. http://www.mamicode.com/info-detail-1737556.html
  2046. http://www.cnblogs.com/breg/p/5728237.html

etcd安全集群三节点扩容至四个节点的更多相关文章

  1. etcd三节点安全集群搭建-pki安全认证

    etcd安全集群搭建就是 pki安装认证 1.环境: 三台centos7. 主机 192.168.0.91 192.168.0.92 192.168.0.93 都关闭防火墙 都关闭selinux 配置 ...

  2. 基于kerberos的hadoop安全集群搭建

    目录 前置条件 kerberos相关 给hadoop各组件创建kerberos账号 将这些账号做成keytab core-site.xml HDFS datanode的安全配置 证书生成和安装 hdf ...

  3. etcd节点扩容至两个节点

    本篇已经安装了单个etcd,然后进行扩容etcd节点至2个,安装单节点请参照:https://www.cnblogs.com/effortsing/p/10295261.html 实验架构 test1 ...

  4. Redis集群节点扩容及其 Redis 哈希槽

    Redis 集群中内置了 16384 个哈希槽,当需要在 Redis 集群中放置一个 key-value 时,redis 先对 key 使用 crc16 算法算出一个结果,然后把结果对 16384 求 ...

  5. redis集群扩容(添加新节点)

    一.创建节点(接上文) 1.在H1服务器/root/soft目录下创建7002目录 2.将7001目录的配置文件redis.conf拷贝到7002,并修改配置文件的端口 3.进入 redis-5.0. ...

  6. Redis Cluster 集群搭建与扩容、缩容

    说明:仍然是伪集群,所有的Redis节点,都在一个服务器上,采用不同配置文件,不同端口的形式实现 前提:已经安装好了Redis,本文的redis的版本是redis-6.2.3 Redis的下载.安装参 ...

  7. 更强、更稳、更高效:解读 etcd 技术升级的三驾马车

    点击下载<不一样的 双11 技术:阿里巴巴经济体云原生实践> 本文节选自<不一样的 双11 技术:阿里巴巴经济体云原生实践>一书,点击上方图片即可下载! 作者 | 陈星宇(宇慕 ...

  8. OpenShift实战(二):OpenShift节点扩容

    1.新增节点信息 增加节点如下,请将xxx改为自己的域名 node6.xxx.net Node 192.168.8.90 8G 20G/60G 4C node7.xxx.net Node 192.16 ...

  9. centos LB负载均衡集群 三种模式区别 LVS/NAT 配置 LVS/DR 配置 LVS/DR + keepalived配置 nginx ip_hash 实现长连接 LVS是四层LB 注意down掉网卡的方法 nginx效率没有LVS高 ipvsadm命令集 测试LVS方法 第三十三节课

    centos   LB负载均衡集群 三种模式区别 LVS/NAT 配置  LVS/DR 配置  LVS/DR + keepalived配置  nginx ip_hash 实现长连接  LVS是四层LB ...

随机推荐

  1. Codeforce Round #424

    A 略 B 略 C: 先对Ai数列预处理前缀和 然后把Bi的每个都加一次 最终得到的结果为ans[sum]++; 最后如果有一个ans[sum]>=k即满足所有K个条件就输出(注意!!前缀和要进 ...

  2. 第一章 Vue介绍

    5 MVC和MVVM的关系图解 MVVM是前端视图层的分层开发思想,主要把每个页面,分层了M.V和VM.其中,VM是MVVM思想的核心,因为VM是M和V之间的调度者 6 Vue基本代码和MVVM之间对 ...

  3. 下载安装mysql-connector

    执行命令:python -m pip install mysql-connector 测试

  4. ngnix之笔记

    ############################################################################# 我们在使用的时候会遇到很多的恶意IP攻击,这 ...

  5. python---win32gui、win32con、win32api:winAPI操作

    python操作winAPI 窗口操作: import sys from PyQt5.QtWidgets import QApplication, QWidget from lianxi import ...

  6. python---硬件序列号

    安装wmi : pip install wmi -i https://pypi.douban.com/simple 还要安装  pip install pywin32 import wmi c = w ...

  7. mac使用sublime text3打开当前文件夹的终端

    打开sublime text3,同时按住shift+command+p打开扩展列表, 选择Package Control: Install Pageage,回车. 在输入框输入: terminal,回 ...

  8. Keras学习笔记一:修改数据读入方式为本地图片读入

    第一种方法: Keras官方给的图片去噪示例要自动下载mnist数据集并处理,不能修改和加入自己的数据集. from keras.datasets import mnist (x_train, _), ...

  9. 批量插入数据@Insert

    // 批量插入数据 @Insert("<script>" + "insert into index_kline (currency_id, currency, ...

  10. Teamviewer解决许可证授权的问题

    提交商业用途表 https://www.teamviewer.com/zhCN/pricing/commercial-use/