生成证书
可运行下列命令:
# 默认密码为 password,如果 keytool 不能使用,请配置 JDK 或安装 java:yum -y install java-1.8.0-openjdk
# 颁布证书给域名
keytool -genkeypair -keystore keystore.jks
-storepass password -alias example.com \
-keyalg RSA -keysize 2048 -validity 5000
-keypass password \
-dname 'CN=*.example.com, OU=Sonatype,
O=Sonatype, L=Unspecified, ST=Unspecified, C=US' \
-ext
'SAN=DNS:nexus.example.com,DNS:clm.example.com,DNS:repo.example.com,DNS:www.example.com'
# 颁布证书给IP
#keytool -genkeypair -keystore keystore.jks
-storepass password -alias 192.168.0.37 \
-keyalg RSA -keysize 2048 -validity 5000
-keypass password \
-dname 'CN=192.168.0.37, OU=Sonatype,
O=Sonatype, L=Unspecified, ST=Unspecified, C=US' \
-ext
'SAN=IP:192.168.0.37'
# 转换证书,可选
# 密码设置为:password
keytool
-importkeystore -srckeystore keystore.jks -destkeystore keystore.jks
-deststoretype pkcs12
将 .jks 证书放在 ./nexus-data/conf
文件夹中,推荐命名为:keystore.jks
mkdir
-p ./nexus-data/conf;chown -R 200:200 ./nexus-data/
创建并启动nexus
创建docker-compose.yml文件
version:
'3'
services:
nexus:
image: sonatype/nexus3:3.71.0
hostname: nexus
container_name: nexus
restart: always
ports:
- "8081:8081" #web控制台http端口,密码在/nexus-data/admin.password
- "8443:8443" #web控制台https端口
- "8001:8001" #自定义docker私库http端口
- "5000:5000" #自定义docker私库https端口
volumes:
- /etc/localtime:/etc/localtime:ro
- ./nexus-data:/nexus-data
-
./nexus-data/conf/jetty-https.xml:/opt/sonatype/nexus/etc/jetty/jetty-https.xml
docker-compose
up -d
启动会比较慢,需要一段时间才能启动成功
docker
cp nexus:/opt/sonatype/nexus/etc/jetty/jetty-https.xml
./nexus-data/conf/jetty-https.xml
访问:https://IP:8081
或者 http://example.com:8081
密码在/nexus-data/admin.password
其中 /opt/nexus/nexus-data 为本地Nexus 储存数据的目录
配置证书
vim
/opt/nexus/nexus-data/etc/nexus.properties
# 配置 https 的端口
application-port-ssl=8443
# 设置 Nexus 启动参数的配置文件,其中 ${jetty.etc}/jetty-https.xml 为新增
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jetty-requestlog.xml
# 设置证书的位置
ssl.etc=${karaf.data}/conf
修改配置文件,填写 SSL 证书的文件名与秘钥
如果证书放在 /opt/nexus/nexus-data/conf 中,文件名为 keystore.jks 就不需要更改证书的配置了。如果证书的密码为 password,也不用修改了。
# 修改上述指定容器内部的
/opt/sonatype/nexus/etc/jetty/jetty-https.xml 文件
由于本文是映射的,可以直接修改./nexus-data/conf/jetty-https.xml中的密码
否者,采用如下方法修改运行中容器的配置
# 设置你的nexus容器的名字
nexus_container_name=nexus
vim $(docker inspect $(docker ps -a|grep
$nexus_container_name |awk '{print $1}') |
sed 's/,/\n/g' | grep "MergedDir" | sed 's/:/\n/g' | sed '1d'
| sed 's/"//g')/opt/sonatype/nexus/etc/jetty/jetty-https.xml
将 keystore.jks 修改为你的证书名称
将 password 修改为你的证书密码
重启 nexus 容器
docker
restart nexus
# 注意,此处的 8443 仅为 nexus 的端口
访问:https://IP:8443
或者其它域名出现
ERR_INVALID_HTTP_RESPONSE
表示证书配置成功了,但访问无效
访问https://example.com:8443
能保证成功访问就表示证书完全成功了
虽然现在未配置docker私库,但是可以先测试证书是否被docker信任
docker pull
nexus.example.com:8443/library/maven:3.6.3-jdk-8
出现下列内容说明证书未被信任
Error response from daemon: Get
"https://nexus.example.com:8443/v2/": x509: certificate signed by
unknown authority
GitLab https 配置 中的证书申请(内涵颁布给域名、IP,证书类型为:.crt、.key**)
本文上方的生成域名的类型为:.jks
# 如果出现 -bash:
openssl: command not found,请安装 openssl:yum -y install openssl
docker客户端证书
# 填写你的域名,要求Linux系统能访问该域名
domain_name=nexus.example.com
# 填写你配置Docker私库的域名使用的端口,该端口现在可能还无法访问,给docker私库准备的
docker_port=8000
# Nexus https 端口
port=8443
mkdir -p /etc/docker/certs.d/$domain_name:$port
cd /etc/docker/certs.d/$domain_name:$port
pwd
# 下载证书到指定文件夹进行信任
openssl s_client -showcerts -connect
$domain_name:$port -servername $domain_name < /dev/null 2>/dev/null |
openssl x509 -outform PEM > /etc/docker/certs.d/$domain_name:$port/ca.crt
# 验证
echo | openssl s_client -CAfile
/etc/docker/certs.d/$domain_name:$port/ca.crt -connect $domain_name:$port
-servername $domain_name
# docker 信任Docker私库的证书
cp -r
/etc/docker/certs.d/$domain_name:$port
/etc/docker/certs.d/$domain_name:$docker_port
# 重启 docker
systemctl restart docker
虽然现在未配置docker私库,但是可以先测试证书是否被docker信任
# 注意,此处的 8443 仅为 nexus 的端口
docker pull
nexus.example.com:8443/library/maven:3.6.3-jdk-8
出现下列内容说明证书已被信任
[root@x99 nexus.example.com:8443]# docker
pull nexus.example.com:8443/library/maven:3.6.3-jdk-8
Error response from daemon: error parsing
HTTP 404 response body: invalid character '<' looking for beginning of
value: "\n<!DOCTYPE html>\n<html
lang=\"en\">\n<head>\n
创建镜像库
登录后会有引导窗口,跟着知道重新配置密码,开启匿名访问即可。
7.点击设置图标进入管理页面
16. 拉取镜像
docker pull <docker地址>/<镜像名>:<镜像tag>
http方式需要配置
docker pull
image.gyoao.com:8001/nginx:1.25.0-alpine
需要修改客户端配置
sed -i
'/registry-mirrors/a\"insecure-registries":
["image.gyoao.com:80"],' /etc/docker/daemon.json;systemctl reload
docker
https方式,无需配置客户端,只需要服务器支持证书
docker pull
image.gyoao.com:5000/nginx:1.25.0-alpine
原文链接:https://blog.csdn.net/gengkui9897/article/details/127353727 |