解决openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory错误
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
Can't load /root/.rnd into RNG
cd /root
openssl rand -writerand .rnd
使用openssl 制作证书密钥 /root/tls/tls.sh
#!/bin/bash
mkdir -p /root/tls
#DOMAIN_HOST=`ifconfig eth0 | grep "inet" | awk '{ print $2}' | sed -n '1p;1q'`
DOMAIN_HOST='39.105.52.23' #选择域名方案最好
HOST=$DOMAIN_HOST
# 自定义信息
PASSWORD="a123456"
COUNTRY=CN
PROVINCE=hn
CITY=zz
ORGANIZATION=gamerole
GROUP=az
NAME=lv
SUBJ="/C=$COUNTRY/ST=$PROVINCE/L=$CITY/O=$ORGANIZATION/OU=$GROUP/CN=$HOST"
# 自定义信息
#============================================================================================
#此形式是自己给自己签发证书,自己就是CA机构,也可以交给第三方机构去签发
# 生成根证书RSA私钥,password作为私钥密码(身份证)
openssl genrsa -passout pass:$PASSWORD -aes256 -out pem/ca-key.pem 4096
# 2.用根证书RSA私钥生成自签名的根证书(营业执照)
openssl req -new -x509 -days 365 -passin pass:$PASSWORD -key pem/ca-key.pem -sha256 -subj $SUBJ -out pem/ca.pem
#============================================================================================
#给服务器签发证书
# 1.服务端生成自己的私钥
openssl genrsa -out pem/server-key.pem 4096
# 2.服务端生成证书(里面包含公钥与服务端信息)
openssl req -new -sha256 -key pem/server-key.pem -out pem/server.csr -subj "/CN=$DOMAIN_HOST"
# 3.通过什么形式与我进行连接,可设置多个IP地扯用逗号分隔
echo subjectAltName=IP:$DOMAIN_HOST > /tmp/extfile.cnf
# 4.权威机构对证书进行进行盖章生效
openssl x509 -passin pass:$PASSWORD -req -days 365 -sha256 -in pem/server.csr -CA pem/ca.pem -CAkey pem/ca-key.pem -CAcreateserial -out pem/server-cert.pem -extfile /tmp/extfile.cnf
#============================================================================================
#给客户端签发证书
openssl genrsa -out pem/key.pem 4096
openssl req -subj '/CN=client' -new -key pem/key.pem -out pem/client.csr
echo extendedKeyUsage = clientAuth > /tmp/extfile.cnf
openssl x509 -passin pass:$PASSWORD -req -days 365 -sha256 -in pem/client.csr -CA pem/ca.pem -CAkey pem/ca-key.pem -CAcreateserial -out pem/cert.pem -extfile /tmp/extfile.cnf
#============================================================================================
# 清理文件
rm -rf pem/ca-key.pem
rm -rf pem/{server,client}.csr
rm -rf pem/ca.srl
# 最终文件
# ca.pem == CA机构证书
# cert.pem == 客户端证书
# key.pem == 客户私钥
# server-cert.pem == 服务端证书
# server-key.pem == 服务端私钥
chmod +x tls.sh
bash tls.sh
配置Docker支持TSL链接
vim /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H=0.0.0.0:2376 --tlsverify --tlscacert=/root/tls/pem/ca.pem --tlscert=/root/tls/pem/server-cert.pem --tlskey=/root/tls/pem/server-key.pem
systemctl daemon-reload
systemctl restart docker
客户端测试连接
docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem -H=39.105.52.23:2376 version
idea 配置docker
将三个文件复制到idea配置ca文件夹下
# ca.pem == CA机构证书
# cert.pem == 客户端证书
# key.pem == 客户私钥
image.png
配置docker访问
mkdir -pv ~/.docker
#cp -v {cert,key,ca}.pem ~/.docker
export DOCKER_HOST=tcp://39.105.52.23:2376 DOCKER_TLS_VERIFY=1
//永久生效 添加到 /etc/profile 文件中,之后更新环境变量
source /etc/profile
网友评论