标签搜索

目 录CONTENT

文章目录

配置nexus的ssl证书,实现docker的https推送私库镜像

陈铭
2021-06-04 / 0 评论 / 0 点赞 / 590 阅读 / 837 字 / 正在检测是否收录...

nexus配置ssl证书

生成密钥和证书

我们可以用java自带的密钥证书生成工具进行自签名证书和密钥的生成

keytool -genkeypair -keystore keystore.jks -storepass ${PASSWD}  -keypass ${PASSWD} -alias nexus -keyalg RSA -keysize 2048 -validity 5000 -dname "CN=${NEXUS_DOMAIN}, OU=Nexus, O=Nexus, L=Beijing, ST=Beijing, C=CN" -ext "SAN=IP:${NEXUS_IP_ADDRESS}" -ext "BC=ca:true"

其中, $是生成密钥的密码,$和$是nexus私库服务器的ip,-keystore keystore.jks表示在当前路径下生成jks密钥文件,-alias nexus 为密钥起别名。

执行完毕后,我们就得到了keystore.jks文件,这个是密钥,要放在nexus安装目录下的etc/ssl下。用这个密钥我们来生成自签名证书

keytool -export -alias nexus -keystore keystore.jks -file keystore.cer -storepass ${PASSWD}

这里的-alias nexus最好与上面的命令一致,执行后会生成keystore.cer文件,该证书后面要给docker用的。

配置nexus.properties

密钥和自签名证书创建后,就要给nexus开启https了。配置nexus安装目录下etc/nexus.properties

application-port-ssl=8443
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml,${jetty.etc}/jetty-https.xml
ssl.etc=${karaf.data}/etc/ssl
nexus-context-path=/
 
# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

里面最重要的就是加上application-port-ssl=8443,即配置https的端口;nexus-args加上$/jetty-https.xml,nexus开启https;如果不想要有http连接,可以删除掉$/jetty-http.xml。

配置jetty-https.xml

配置nexus安装目录下/etc/jetty/jetty-https.xml

    <Set name="certAlias">nexus</Set>
    <Set name="KeyStorePath">nexus安装目录下etc/ssl/keystore.jks</Set>
    <Set name="KeyStorePassword">${PASSWD}</Set>
    <Set name="KeyManagerPassword">${PASSWD}</Set>
    <Set name="TrustStorePath">nexus安装目录下etc/ssl/keystore.jks</Set>
    <Set name="TrustStorePassword">${PASSWD}</Set>

其中certAlias就是生成密钥和证书时用的别名

重启nexus

在nexus安装目录下bin,执行

./nexus restart

开启docker的https功能

可视化界面中的管理员后台:Security - Realms,把 Docker Realm 激活

docker配置

安装ssl证书

将 keystore.cer 复制到 docker服务器的/etc/pki/ca-trust/source/anchors 目录下,并执行

update-ca-trust extract

配置镜像

配置etc/docker/daemon.json

{"registry-mirrors": ["https://nexus_ip:docker库配置的https端口"]}

如果你有多个docker库(group、hosted、proxy),都可以加到registry-mirrors中
重启docker

systemctl daemon-reload
systemctl restart docker

推送测试

登录私库(只有group和hosted库可以登录)

docker login nexus_ip:docker库https端口

规范命名镜像,不规范会推送错误,例如:

docker tag centos:lastest nexus_ip:docker库https端口/centos:lastest
docker push nexus_ip:docker库https端口/centos:lastest

docker怎么用http拉取镜像(补充)

配置daemon.json

如果我们不仅需要https,也要http,可以在daemon.json加上

"insecure-registries": ["nexus_ip:docker_group库http端口","nexus_ip:docker_hosted库http端口"]

我们只能配置上group和hosted库,因为http指的是login时免去https验证,也只有group和hosted库能够登录

推送测试

同上。先要规范命名,在推送

0

评论区