基于linux搭建nexus仓库,并配置docker私服
1.部署命
docker run -d --restart always --user root -p 8081:8081 -p 8443:8443 -p 8001-8006:8001-8006 -v /opt/nexus-data:/nexus-data --name nexus sonatype/nexus3
端口说明:
8081:nexus应用http端口
8443: nexus应用https端口
8001:docker(hosted)私有仓库的http端口,可以pull和push
8002:docker(hosted)私有仓库的https端口,可以pull和push
8003:docker(proxy)代理远程仓库的http端口,只能pull
8004:docker(proxy)代理远程仓库的https端口,只能pull
8005:docker(group)私有仓库和代理的组的http端口,只能pull
8006:docker(group)私有仓库和代理的组的https端口,只能pull
注意:步骤2和步骤3,任选一个
2.基于自签名证书配置docker私服
2.1 生成证书,脚本如下
#!/bin/bash # 这里的ip换为nexus运行机器的ip echo subjectAltName = IP:192.168.0.103 > extfile.cnf # 生成ca openssl genrsa -out ca.key 2048 openssl req -x509 -new -nodes -key ca.key -days 5000 -out ca.crt # 生成server证书 openssl genrsa -out server.key 2048 openssl req -new -key server.key -subj "/CN=10.110.25.191" -out server.csr openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out server.crt -days 5000 # 将证书导出成pkcs格式 # 这里需要输入密码 用password,如果不用这个,需要修改镜像里的${jetty.etc}/jetty-https.xml。 openssl pkcs12 -export -out keystore.pkcs12 -inkey server.key -in server.crt keytool -v -importkeystore -srckeystore keystore.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.jks -deststoretype JKS -storepass password -srcstorepass password
docker cp keystore.jks nexus:/opt/sonatype/nexus/etc/ssl/keystore.jks
2.2.修改nexus的配置文件
vim /opt/nexus-data/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 nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml,${jetty.etc}/jetty-https.xml nexus-context-path=/${NEXUS_CONTEXT} # Nexus section nexus-edition=nexus-pro-edition nexus-features=\ nexus-pro-feature nexus.hazelcast.discovery.isEnabled=true
2.3.修改证书配置文件
docker cp nexus:/opt/sonatype/nexus/etc/jetty/jetty-https.xml . vim jetty-https.xml
需要修改以下几个属性
<Set name="KeyStorePath"><Property name="ssl.etc"/>/keystore.jks</Set> <Set name="KeyStorePassword">password</Set> <Set name="KeyManagerPassword">password</Set> <Set name="TrustStorePath"><Property name="ssl.etc"/>/keystore.jks</Set> <Set name="TrustStorePassword">password</Set>
2.4 设置realms
在realms中把 docker bearer token realm 选为 active
2.5 重启nexus
docker restart nexus
3. 使用nginx代理(只需要配置nginx证书,可以使用自签名证书或者签证icp发布的证书)