keytool nexus3.x docker 仓库 https 跨节点 docker pull/push

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 /usr/local/   且 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=/usr/local/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方式的访问:

    背景

    像Nexus Repository Manager 3这样的私人Docker注册中心将需要用户进行身份验证才能发布泊坞窗图像。

    为了使用身份验证,Docker守护程序实施强制注册表连接使用HTTPS。

    默认情况下,Nexus 3未配置HTTPS连接器,因为配置它需要手动生成和配置SSL证书。

    出于测试目的,管理员可能希望为Nexus HTTPS连接器使用自签名TLS证书。

    尽管自签名证书可以加密HTTP通信并快速生成,但由于证书身份尚未由第三方证书颁发机构(CA)进行签名/验证,所以通常认为它们不可信。

    为了解决Docker Daemon问题,考虑到Nexus HTTPS的不可信赖性,守护进程会有一个名为--insecure-registry的选项 。通过将Nexus主机名和端口标记为不安全,docker守护程序不会验证安全连接的可信性。其目的是为了避免使用不可信证书时通常会发生的错误。

    但是,--  insecure-registry 标志具有许多不需要的副作用,并且可能会导致不会遇到的晦涩错误。

    由于定义不明确, Sonatype不能推荐使用Docker  --insecure-registry 标志  

    如何生成可以由Docker守护程序信任的自签名证书

    而不是通过使用--insecure-registry来告诉docker守护进程不验证自签名证书,更好的做法是告诉它明确信任自签名证书。

    Docker提供了描述使用openssl生成CA和服务器自签名证书的文档但是,这些说明可能会导致Docker仍不会信任自签名证书的错误消息。另外Openssl在所有系统上都没有实现。

    下面列出的步骤是使用Java keytool以平台中立的方式为Nexus生成自签名服务器证书的另一种可靠方法。这些步骤可用于配置Docker以显式信任与Nexus Repository Manager的连接。

    Step 1: Generate a self-signed server certificate for Nexus using keytool

    First determine the host name and externally accessible IP address of Nexus that Docker will use. The host name and IP address will be embedded in the self-signed certificate so that host name certificate verification will not fail.

    On the Nexus host, go to <AppDir>/etc/ssl directory. Generate a public private key pair for Nexus to use for any HTTPS connector.

    In the command below:

    • Replace ${NEXUS_DOMAIN} with the DNS name of your Nexus host. The host name must be resolvable from the host running the Docker daemon.
    • Replace ${NEXUS_IP_ADDRESS} with the IP address of your Nexus host. The IP address must be routable to Nexus from the host running Docker daemon.
    keytool -genkeypair -keystore keystore.jks -storepass password -keypass password -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"

    You should end up with a file named keystore.jks in the local directory. The CN value specifies what is known as a wildcard certificate which will match any sub-domain.

    Step 2: Configure Nexus to use the self-signed server certificate

    For 3.0.x, follow the prerequisites of enabling SSL in Nexus.

    For 3.1 or newer, see Inbound SSL - Configuring to Serve Content via HTTPS

    In particular, make sure the SSLContextFactory is configured to point to the generated keystore file from step 1. Make sure these setting exist in jetty-https.xml: 

    Repository Manager 3.0.x Example: (<AppDir>/etc/jetty-https.xml)

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

    Repository Manager 3.1.0 and Newer Example: (<AppDir>/etc/jetty/jetty-https.xml)

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

    Restart Nexus to pick up any configuration changes.

    Step 3: Configure Docker Daemon to trust the certificate

    Use Oracle java `keytool` to retrieve and print the Nexus server certificate for the Nexus instance running at ${NEXUS_DOMAIN}:${SSL_PORT} :

    keytool -printcert -sslserver ${NEXUS_DOMAIN}:${SSL_PORT} -rfc

    这个命令将打印由包围的编码的证书-----BEGIN CERTIFICATE----------END CERTIFICATE-----线。

    如果您拥有对运行Docker守护程序的主机的超级用户访问权限,则最好的选择是在系统级别信任Nexus服务器证书。复制打印的证书并将其粘贴到文件位置,如下所述。

    Docker 对基于unix的系统如何信任证书提出了一般建议,我们建议遵循他们的建议

    第二种选择是仅将Docker配置为以每个主机:端口为基础信任证书。Docker对于可以复制证书的位置提供了特定的建议,以便每台主机可以自动信任这些证书。 缺点是对于每个Docker注册表主机:端口的访问,必须添加一个新的证书文件。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值