nexus keytool docker

本文详细介绍 Nexus 仓库管理器的安装与配置流程,包括 Nexus OSS 和 Pro 版本的区别、环境变量设置、服务安装及 HTTPS 访问配置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.cnblogs.com/wzy5223/p/5410990.html
  1. nexus仓库管理器,分为两个版本,Nexus Repository Manager OSS 和 Nexus Repository Manager Pro。前者可以免费使用,相比后者,功能缺少一些。下载地址:https://www.sonatype.com/download-oss-sonatype,参考文档:https://help.sonatype.com/display/NXRM3
  2. 安装:cp nexus-3.8.0-02-unix.tar.gz /opt/   且 tar -xvf nexus-3.8.0-02-unix.tar.gz 且 ln -sf nexus-3.8.0-02 nexus 
  3. 设置环境变量:vim /etc/profile,在最后加上下面这一句,:wq保存退出export NEXUS_HOME=/opt/nexus-3.8.0-02,source /etc/profile 刷新刚设置的环境变量,使之生效
  4. 创建 nexus 用户
    $ sudo useradd nexus -M -s /sbin/nologin

  5. 授权
    $ sudo chown -R nexus:nexus /opt/nexus
    $ sudo chown -R nexus:nexus /opt/sonatype-work/


  6. 打开 /opt/nexus/bin/nexus.rc 文件, 去掉 run_as_user 变量的注释
    $ sudo vi /opt/nexus/bin/nexus.rc
    run_as_user="nexus"

  7. 安装服务(本例以 systemd 为例)
    创建服务文件

    $ sudo vi /etc/systemd/system/nexus.service

    添加如下内容

    [Unit]
    Description=nexus service
    After=network.target
    [Service]
    Type=forking
    LimitNOFILE=65536
    ExecStart=/opt/nexus/bin/nexus start
    ExecStop=/opt/nexus/bin/nexus stop
    User=nexus
    Restart=on-abort
    [Install]
    WantedBy=multi-user.target

    其中LimitNOFILE=65536用于调整文件描述符数量。

  8. 安装并启动服务
    $ sudo systemctl daemon-reload
    $ sudo systemctl enable nexus
    $ sudo systemctl start nexus

  9. 访问测试
    访问地址: http://ip:8081/
    访问凭证(默认的用户名和密码):

    username: admin
    password: admin123

    14.更改 nexus 的 context path
    如需修改路径,编辑 /opt/sonatype-work/nexus3/etc/nexus.properties 文件即可
    $ sudo vi /opt/nexus/nexus/etc/nexus.properties
    nexus-context-path=/nexus
    重启服务

    $ sudo systemctl restart nexus
    访问测试
    地址 http://ip:8081/nexus


  10. https方式的访问:
    1.cd /opt/nexus/etc/ssl;keytool -genkeypair -keystore keystore.jks -storepass 123456 -keypass 123456 -alias jetty -keyalg RSA -keysize 2048 -validity 5000 -dname "CN=*.k8s-master.com, OU=jettech, O=jettech, L=jettech, ST=IT, C=CN" -ext "SAN=DNS:k8s-master,IP:10.30.30.127" -ext "BC=ca:true" 私钥对
    2.从私钥对中取出ca证书:keytool -printcert -sslserver 10.30.30.127:8443 -rfc >nexus.crt
    3.  其他节点,客户端使用方:浏览器导入nexus.crt证书。
        docker中使用:vim /etc/sysconfig/docker,加上OPTIONS= “--insecure-registry 10.30.30.127:4443“,cd /etc/docker/certs.d且(这步骤可以不写好像也通过mkdir  10.30.30.127:4443,cp nexus.crt /etc/docker/certs.d/10.30.30.127:4443)






Nexus 3.0 可以创建三种docker仓库:

1. docker (proxy)      代理和缓存远程仓库 ,只能pull

2. docker (hosted)    托管仓库 ,私有仓库,可以push和pull

3. docker (group)      将多个proxy和hosted仓库添加到一个组,只访问一个组地址即可,只能pull

4.  开启监听ssl协议端口

  1. 复制代码
    cat > etc/org.sonatype.nexus.cfg <<EOF
    # Jetty section
    application-port-ssl=8443
    application-port=8081
    application-host=0.0.0.0
    nexus-args=${karaf.etc}/jetty.xml,${karaf.etc}/jetty-http.xml,${karaf.etc}/jetty-requestlog.xml,${karaf.etc}/jetty-https.xml,${karaf.etc}/jetty-http-redirect-to-https.xml
    nexus-context-path=/
    
    # Nexus section
    nexus-edition=nexus-oss-edition
    nexus-features=\
     nexus-oss-feature
    EOF
    复制代码

    2. 生成证书秘钥

    复制代码
    NEXUS_DOMAIN=nexus 没有可以随便写
    NEXUS_IP_ADDRESS=192.168.31.135 你的IP
    
    mkdir etc/ssl
    cd
    etc/ssl
    keytool -genkeypair -keystore keystore.jks -storepass nexus3 -keypass nexus3 -alias jetty -keyalg RSA -keysize 2048 -validity 5000 -dname "CN=*.${NEXUS_DOMAIN}, OU=Example, O=Sonatype, L=Unspecified, ST=Unspecified, C=US" -ext "SAN=DNS:${NEXUS_DOMAIN},IP:${NEXUS_IP_ADDRESS}" -ext "BC=ca:true"
    复制代码

    3. 修改etc/jetty-https.xml ,红色字体

        <Set name="KeyStorePath"><Property name="karaf.etc"/>/ssl/keystore.jks</Set>
        <Set name="KeyStorePassword">nexus3</Set>
        <Set name="KeyManagerPassword">nexus3</Set>
        <Set name="TrustStorePath"><Property name="karaf.etc"/>/ssl/keystore.jks</Set>
        <Set name="TrustStorePassword">nexus3</Set>

    5. 在运行docker的机器上信任nexus的证书, ubuntu系统

    keytool -printcert -sslserver ${NEXUS_IP_ADDRESS}:8443 -rfc >nexus.crt
    sudo mv nexus.crt /usr/local/share/ca-certificates/nexus.crt
    sudo update-ca-certificates

    6. 重启docker

    sudo service docker restart
    http://www.cnblogs.com/wzy5223/p/5414965.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值