生成CA证书
1.创建私钥:
openssl genrsa -out ca-key.pem 1024
2.创建证书请求:
openssl req -new -out ca-req.csr -key ca-key.pem
common name粘贴: MacBook-Air.local
密码输入时直接回车
3.自签署证书:
openssl x509 -req -in ca-req.csr -out ca-cert.pem -signkey ca-key.pem -days 3650
不能大于2032年,否则有些芯片连接不了。
生成server证书
1.创建私钥:
openssl genrsa -out server-key.pem 1024
2.创建证书请求:
openssl req -new -out server-req.csr -key server-key.pem
common name粘贴: MacBook-Air.local
注意:创建server时,当前这个项必须填写你服务器得IPCommon Name (eg, YOUR name) []:
如果本地测试填写localhost即可
3.自签署证书:
openssl x509 -req -in server-req.csr -out server-cert.pem -signkey server-key.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -days 3650
生成client证书
1.创建私钥:
openssl genrsa -out client-key.pem 1024
2.创建证书请求:
openssl req -new -out client-req.csr -key client-key.pem
3.自签署证书:
openssl x509 -req -in client-req.csr -out client-cert.pem -signkey client-key.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -days 3650
证书生成完毕:
再修改相应配置名字:
FengdeMacBook-Pro:gfca1 fengguo$ mv ca-cert.pem cacert.pem
FengdeMacBook-Pro:gfca1 fengguo$ mv server-cert.pem cert.pem
FengdeMacBook-Pro:gfca1 fengguo$ mv server-key.pem key.pem
放入服务器。
scp -r ./* root@47.99.212.137:/root/mqtt/emq3-4/emqx/etc/certs
重启emq服务。
查看日期。
openssl s_client -connect 47.99.212.137:1884 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > gf.crt
openssl x509 -noout -text -in gf.crt
======
证书文件概念扫盲:
https://blog.csdn.net/feng98ren/article/details/83832483
--------------------
参考了:https://blog.csdn.net/u013558069/article/details/80268918
评论已关闭!