arm架构部署nexus配置ssl&containerd

背景

合作伙伴私有云的机器架构是arm的,使用registry做为镜像仓库,可以满足基础功能,权限管理等功能无法实现。借鉴现有的架构部署nexus来满足权限管理等需求

思路

翻看dockerhub上没看到有编译好的arm架构的nexus,从github找到源码仓库的dockerfile在arm架构的机器上重新构建arm架构的镜像实现

实施

首先要解决掉机器的网络问题,需要拉取registry.access.redhat.com的镜像,和从download.sonatype.com下载tag包,下载包可以本地下载,改动dockerfile复制进去,

系统信息

bash 复制代码
root@nexus:/opt/nexus# cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
root@nexus:/opt/nexus# uname -a 
Linux nexus 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:10 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux
# containerd版本
root@k8s-master01:~# containerd --version 
containerd github.com/containerd/containerd v1.7.20 8fc6bcff51318944179630522a095cc9dbf9f353
# k8s集群版本
root@k8s-master01:~# kubectl version 
Client Version: v1.30.3
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.0

构建镜像

bash 复制代码
git clone https://github.com/sonatype/docker-nexus3.git

略微修改dockerfile的下载源码包,跳过md5校验。

bash 复制代码
# Download nexus & setup directories
RUN curl -x socks5://xxx:7891 -L ${NEXUS_DOWNLOAD_URL} --output nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
    && tar -xvf nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
    && mv nexus-${NEXUS_VERSION} $NEXUS_HOME \
    && chown -R nexus:nexus ${SONATYPE_WORK} \
    && mv ${SONATYPE_WORK}/nexus3 ${NEXUS_DATA} \
    && ln -s ${NEXUS_DATA} ${SONATYPE_WORK}/nexus3

执行构建

bash 复制代码
docker build --rm=true --tag=sonatype/nexus3-arm 
# 验证
root@nfs:/opt/nexus/docker-nexus3# docker images |grep nexus
sonatype/nexus3-arm                                       latest        fc37defdcdbc   7 weeks ago     913MB
# 导出,拷贝到目标节点上运行
docker save -o nexus3-arm.tar sonatype/nexus3-arm:latest
scp nexus3-arm.tar root@10.17.3.21:/root

启动容器命令

bash 复制代码
docker run -itd --net=host  --name=nexus3 --user root -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 --privileged=true --restart=always   --ulimit nofile=655350 --ulimit memlock=-1 --memory=7G --memory-swap=-1 --cpuset-cpus='0-3'  -e INSTALL4J_ADD_VM_PARAMS="-Xms2g -Xmx2g -XX:MaxDirectMemorySize=3g" -v /etc/localtime:/etc/localtime         -v /data/nexusdata:/nexus-data sonatype/nexus3-arm:latest

配置ssl

在运行中的nexus容器中执行

bash 复制代码
NEXUS_DOMAIN=registry.xxx.local     ##更改为你自己的nexus的IP
NEXUS_IP_ADDRESS=192.168.199.12   ##更改为你自己的nexus的IP
# 生成key
# -keystore 文件名
# L 城市 Shanghai Shenzhen都可以 
# ST 城市 Shanghai Shenzhen都可以
# SAN 就是要签发给哪个域名或IP可以使用 
# -validity 签发的证书的有效期
keytool -genkeypair -keystore keystore.jks -alias nexus -keyalg RSA -keysize 2048 -dname "CN=registry.xxx.local, OU=Nexus, O=Nexus, L=ChengShi, ST=ChengShi, C=CN" -ext "SAN=dns:registry.xxx.local,ip:10.17.3.21" -validity 3650
Enter keystore password:  # 输入用于加密keystore.jks文件的密码
Re-enter new password: 
Enter key password for <nexus>
	(RETURN if same as keystore password):  

# 生成cer
[root@nexus ~]# keytool -export -alias nexus -keystore keystore.jks -file keystore.cer -storepass 123456
Certificate stored in file <keystore.cer>

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.jks -deststoretype pkcs12".

从容器中把生成的jks和cer文件拷贝出来

bash 复制代码
docker cp 46f16d452a65:/opt/sonatype/nexus/etc/ssl/keystore.jks /opt/nexus/nexus-key/
root docker cp 46f16d452a65:/opt/sonatype/nexus/etc/ssl/keystore.cer /opt/nexus/nexus-key/

查看证书的内容

bash 复制代码
root@nexus:/opt/nexus/nexus-key# openssl x509 -inform der -in keystore.cer -text -noout
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 21382x204 (0x7f72xc)
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: C = CN, ST = xx, L = xx, O = Nexus, OU = Nexus, CN = registry.xx.local
        Validity
            Not Before: Sep 11 07:09:57 2024 GMT
            Not After : Sep  9 07:09:57 2034 GMT
        Subject: C = CN, ST = xx, L = xx, O = Nexus, OU = Nexus, CN = registry.xx.local
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (2048 bit)
                Modulus:
                    1e:2d
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Alternative Name: 
                DNS:registry.xx.local, IP Address:10.17.3.21
            X509v3 Subject Key Identifier: 
                C5:75:F4:A7:E:62:D1:5F:C9:D7
    Signature Algorithm: sha256WithRSAEncryption
         1c:bb:f3:17:47:13:d8:21:21:05:99:cf:ab:5d:43:ae:8e:83:
         92:99:eb:e8:7d:c7:00:7d:44:fb:68:d1:99:6b:bb:84:79:2a:
         6d:fc:51:60

重新配置dockerfile

bash 复制代码
# Download nexus & setup directories
RUN curl -x socks5://xxx:7891 -L ${NEXUS_DOWNLOAD_URL} --output nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
    && tar -xvf nexus-${NEXUS_VERSION}-${JAVA_VERSION}-unix.tar.gz \
    && mv nexus-${NEXUS_VERSION} $NEXUS_HOME \
    && chown -R nexus:nexus ${SONATYPE_WORK} \
    && mv ${SONATYPE_WORK}/nexus3 ${NEXUS_DATA} \
    && ln -s ${NEXUS_DATA} ${SONATYPE_WORK}/nexus3

# Removing java memory settings from nexus.vmoptions since now we use INSTALL4J_ADD_VM_PARAMS
RUN sed -i '/^-Xms/d;/^-Xmx/d;/^-XX:MaxDirectMemorySize/d' $NEXUS_HOME/bin/nexus.vmoptions
# 新增内容
COPY keystore.cer ${NEXUS_HOME}/etc/ssl/
COPY keystore.jks ${NEXUS_HOME}/etc/ssl/

RUN echo "#!/bin/bash" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
    && echo "cd /opt/sonatype/nexus" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
    && echo "exec ./bin/nexus run" >> ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
    && chmod a+x ${SONATYPE_DIR}/start-nexus-repository-manager.sh \
    && sed -e '/^nexus-context/ s:$:${NEXUS_CONTEXT}:' -i ${NEXUS_HOME}/etc/nexus-default.properties \
    && sed -i '/application-port=8081/i application-port-ssl=443' ${NEXUS_HOME}/etc/nexus-default.properties \ # 监听端口
    && sed -i '32c\    <Set name="KeyStorePassword">123456</Set>' ${NEXUS_HOME}/etc/jetty/jetty-https.xml \ # 密钥
    && sed -i '33c\    <Set name="KeyManagerPassword">123456</Set>' ${NEXUS_HOME}/etc/jetty/jetty-https.xml \ 
    && sed -i '35c\    <Set name="TrustStorePassword">123456</Set>' ${NEXUS_HOME}/etc/jetty/jetty-https.xml

构建

bash 复制代码
docker build --rm=true --tag=sonatype/nexus3-arm:v1.3-ssl .

配置系统信任nexus私有证书

cer转换为pem文件,再把证书导入到节点上,

bash 复制代码
root@k8s-master01:/usr/local/share/ca-certificates# openssl x509 -inform DER -in /usr/local/share/ca-certificates/keystore.cer -out /usr/local/share/ca-certificates/keystore.pem
# 更新
root@k8s-master01:/usr/local/share/ca-certificates# update-ca-certificates

配置containerd信任nexus私有证书

containerd版本,系统环境信息在上面

bash 复制代码
containerd_nexus_conf() {
    mkdir -pv /etc/containerd/certs.d/registry.xx.local
    cat > /etc/containerd/certs.d/registry.xx.local/hosts.toml <<-EOF
server = "registry.xx.local"
[host."registry.xx.local"]
  capabilities = ["pull", "resolve", "push"]
  skip_verify = true
EOF
    sed -i '/\[plugins\."io\.containerd\.grpc\.v1\.cri"\.registry\]/,/config_path = ""/s|config_path = ""|config_path = "/etc/containerd/certs.d"|g' /etc/containerd/config.toml
    systemctl daemon-reload && systemctl restart containerd;sleep 2
    containerd_status=$(systemctl is-active containerd)
    if [ "$containerd_status" == "active" ]; then
        echo_green "containerd conf nexus success."
    else :
        echo_red "containerd conf nexus failed."
        exit 3
    fi
}

reference

https://www.cnblogs.com/Smbands/p/14430775.html

https://github.com/containerd/containerd/blob/main/docs/hosts.md

相关推荐
哔哥哔特商务网9 小时前
一文探究48V新型电气架构下的汽车连接器
架构·汽车
007php0079 小时前
GoZero 上传文件File到阿里云 OSS 报错及优化方案
服务器·开发语言·数据库·python·阿里云·架构·golang
码上有前11 小时前
解析后端框架学习:从单体应用到微服务架构的进阶之路
学习·微服务·架构
韦德斯15 小时前
嵌入式Linux的RTC读写操作应用
linux·运维·c语言·arm开发·实时音视频
byte轻骑兵16 小时前
嵌入式 ARM Linux 系统构成全解:从硬件到应用层层剖析
linux·arm开发·arm·嵌入式开发
货拉拉技术17 小时前
多元消息融合分发平台
javascript·后端·架构
冷心笑看丽美人18 小时前
Spring 框架七大模块(Java EE 学习笔记03)
学习·spring·架构·java-ee
思尔芯S2C19 小时前
面向未来的智能视觉参考设计与汽车架构,思尔芯提供基于Arm技术的创新方案
arm开发·架构·汽车·iot·fpga原型验证·prototyping·智慧视觉
老码沉思录1 天前
Android开发实战班 -应用架构 - MVVM 架构模式
android·架构
晴子呀1 天前
微服务系列概览
微服务·云原生·架构