在局域網中部署組件時,想要經過證書來實現身份的認證,確保通訊的安全性,能夠經過cfssl工具來進行CA證書,服務端證書,客戶端證書的建立。
node
[root@nccztsjb-node-17 data]# ls -ltr total 35936 -rw-r--r-- 1 root root 15108368 Nov 27 14:07 cfssl_1.5.0_linux_amd64 -rw-r--r-- 1 root root 9663504 Nov 27 14:21 cfssljson_1.5.0_linux_amd64 -rw-r--r-- 1 root root 12021008 Nov 30 11:22 cfssl-certinfo_1.5.0_linux_amd64
[root@nccztsjb-node-17 data]# chmod +x cfssl* [root@nccztsjb-node-17 data]# cp cfssl_1.5.0_linux_amd64 /usr/local/bin/cfssl [root@nccztsjb-node-17 data]# cp cfssljson_1.5.0_linux_amd64 /usr/local/bin/cfssljson [root@nccztsjb-node-17 data]# cp cfssl-certinfo_1.5.0_linux_amd64 /usr/local/bin/cfssl-certinfo [root@nccztsjb-node-17 data]# cfssl version Version: 1.5.0 Runtime: go1.12.12
備註:此時cfssl工具安裝完成。linux
ca根證書主要是用來簽發其餘的證書web
cat >ca-config.json <<EOF { "signing": { "default": { "expiry": "262800h" }, "profiles": { "kubernetes": { "usages": [ "signing", "key encipherment", "server auth", "client auth" ], "expiry": "262800h" } } } } EOF
說明:能夠設置默認的簽名出來的證書的有效時間。能夠同時設置不一樣的profile用於不一樣的用途。json
cat > ca-csr.json <<EOF { "CN": "kubernetes", "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "Beijing", "L": "Beijing", "O": "DC", "OU": "System" } ], "ca": { "expiry": "262800h" } } EOF
[root@nccztsjb-node-17 data]# cfssl gencert -initca ca-csr.json | cfssljson -bare ca 2020/12/04 14:20:39 [INFO] generating a new CA key and certificate from CSR 2020/12/04 14:20:39 [INFO] generate received request 2020/12/04 14:20:39 [INFO] received CSR 2020/12/04 14:20:39 [INFO] generating key: rsa-2048 2020/12/04 14:20:39 [INFO] encoded CSR 2020/12/04 14:20:39 [INFO] signed certificate with serial number 497233672920328375338343228164630446467151606126 [root@nccztsjb-node-17 data]# ls -l ca* -rw-r--r-- 1 root root 294 Dec 4 14:13 ca-config.json -rw-r--r-- 1 root root 1045 Dec 4 14:20 ca.csr -rw-r--r-- 1 root root 246 Dec 4 14:19 ca-csr.json -rw------- 1 root root 1675 Dec 4 14:20 ca-key.pem -rw-r--r-- 1 root root 1310 Dec 4 14:20 ca.pem
ca.pem就是ca的證書,ca-key.pem就是ca的私鑰。安全
cat >etcd-csr.json <<EOF { "CN": "etcd", "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "Beijing", "L": "Beijing", "O": "DC", "OU": "System" } ] } EOF
cfssl gencert \ -ca=ca.pem \ -ca-key=ca-key.pem \ -config=ca-config.json \ -profile=kubernetes etcd-csr.json | cfssljson -bare etcd 2020/12/04 14:33:00 [INFO] generate received request 2020/12/04 14:33:00 [INFO] received CSR 2020/12/04 14:33:00 [INFO] generating key: rsa-2048 2020/12/04 14:33:00 [INFO] encoded CSR 2020/12/04 14:33:00 [INFO] signed certificate with serial number 86899219278041222746661164070003623992607015229 2020/12/04 14:33:00 [WARNING] This certificate lacks a "hosts" field. This makes it unsuitable for websites. For more information see the Baseline Requirements for the Issuance and Management of Publicly-Trusted Certificates, v.1.1.6, from the CA/Browser Forum (https://cabforum.org); specifically, section 10.2.3 ("Information Requirements"). [root@nccztsjb-node-17 data]# ls -l etcd* -rw-r--r-- 1 root root 993 Dec 4 14:33 etcd.csr -rw-r--r-- 1 root root 201 Dec 4 14:30 etcd-csr.json -rw------- 1 root root 1679 Dec 4 14:33 etcd-key.pem -rw-r--r-- 1 root root 1383 Dec 4 14:33 etcd.pem
etcd.csr爲etcd的證書請求文件,etcd-key.pem爲etcd的私鑰,etcd.pem爲etcd的證書。至此,etcd的證書籤發完成。此證書能夠做爲etcd的服務端證書來使用。服務器