nexus repository oss 是免费的通用格式文件的存储库。

1.Docker安装

1.1 创建目录并授权

  1. mkdir -p nexus3/sonatype-work/nexus3
  2. chmod -R 777 nexus3

1.2 创建docker-compose.yml并将文件放在根目录

  1. version: '3.8'
  2. networks:
  3. nexus3:
  4. driver: bridge
  5. services:
  6. nexus3:
  7. image: sonatype/nexus3:3.37.3
  8. container_name: nexus3
  9. restart: always
  10. environment:
  11. - "INSTALL4J_ADD_VM_PARAMS=-Xms1500m -Xmx1500m"
  12. volumes:
  13. - ./sonatype-work/nexus3:/nexus-data
  14. ports:
  15. - 8081:8081
  16. networks:
  17. - nexus3

注:首次启动需要加载超多配置,启动时间很长,请耐心等待,切记不要退出,否则再次启动时会出现各种诡异的问题。

2.Centos安装

2.1 下载安装包

  1. https://www.sonatype.com/products/repository-oss-download

2.2 编辑配置文件

配置文件/nexus-3.xx.xx/etc/nexus-default.properties,默认开始http,可选开启https

  1. ## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
  2. ##
  3. # Jetty section
  4. nexus-context-path=/
  5. application-host=0.0.0.0
  6. # http端口
  7. #application-port=8081
  8. # http访问
  9. #nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
  10. # https端口
  11. application-port-ssl=8081
  12. # https访问
  13. nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jetty-requestlog.xml
  14. # Nexus section
  15. nexus-edition=nexus-pro-edition
  16. nexus-features=\
  17. nexus-pro-feature

2.3 https配置(可选)

2.3.1 生成ssl证书

使用 nexus-ssl-generate-keystore.sh 生成ssl证书,将shell放在/nexus-3.xx.xx/根目录下。
nexus-ssl-generate-keystore.sh 脚本内容如下:

  1. NEXUS_DOMAIN='Nexus'
  2. if [[ -z $1 ]]; then
  3. echo 'please input your ip_address!'
  4. exit
  5. fi
  6. NEXUS_IP_ADDRESS=$1
  7. PASSWORD='password'
  8. keytool -genkeypair -keystore keystore.jks -storepass ${PASSWORD} -keypass ${PASSWORD} -alias nexus -keyalg RSA -keysize 2048 -validity 5000 -dname "CN=${NEXUS_DOMAIN}, OU=Nexus, O=Nexus, L=Beijing, ST=Beijing, C=CN" -ext "SAN=IP:${NEXUS_IP_ADDRESS}" -ext "BC=ca:true"
  9. mv keystore.jks etc/ssl/
  10. #keytool -export -alias nexus -keystore keystore.jks -file keystore.cer -storepass ${PASSWORD}
  11. #mv keystore.cer etc/ssl/

2.3.2 shell脚本使用方式

  1. sh nexus-ssl-generate-keystore.sh {ip}

示例:

  1. sh nexus-ssl-generate-keystore.sh 192.168.3.77

2.3.3 https证书

生成后的https证书存放位置:/nexus-3.xx.xx/etc/ssl/keystore.jks

2.4 启动

启动脚本:/nexus-3.xx.xx/bin/nexus
启动命令:./nexus {start | stop | run | run-redirect | status | restart | force-reload }

2.5 访问

http[s]://ip:port

3.nginx 域名映射

3.1 nginx配置maven私服

  1. upstream nexus3.com {
  2. server 127.0.0.1:8081;
  3. }
  4. server {
  5. access_log /var/logs/nexus3.access.log main;
  6. error_log /var/logs/nexus3.error.log error;
  7. listen 443 ssl;
  8. server_name your domain; # 配置域名
  9. charset utf-8;
  10. ssl_certificate /path/ssl证书.pem; # 域名对应的ssl证书
  11. ssl_certificate_key /path/ssl证书.key; # 域名对应的ssl证书
  12. ssl_session_cache shared:SSL:1m;
  13. ssl_session_timeout 5m;
  14. #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  15. # 阿里云加固建议
  16. ssl_protocols TLSv1.2;
  17. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  18. ssl_prefer_server_ciphers on;
  19. # 阿里云加固建议
  20. server_tokens off;
  21. location / {
  22. proxy_connect_timeout 60;
  23. proxy_send_timeout 60;
  24. proxy_read_timeout 60;
  25. proxy_pass https://nexus3.com/;
  26. proxy_set_header Host $host;
  27. proxy_set_header X-Real-IP $remote_addr;
  28. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  29. }
  30. }

4.开发环境集成Maven私服

4.1 开发环境maven配置

4.1.1 maven版本统一使用3.5.4

下载地址:https://dlcdn.apache.org/maven/maven-3/3.5.4/binaries/

4.1.2 配置maven环境变量

参考文档:https://www.runoob.com/maven/maven-setup.html

4.1.3 配置settings.xml,需要替换以下几个节点

4.1.3.1 maven依赖存放位置

  1. <localRepository>/Users/username/repository</localRepository>

4.1.3.2 maven打包上传时需要验证管理员账号和密码

  1. <server>
  2. <id>private-maven-snapshots</id>
  3. <username>username</username>
  4. <password>password</password>
  5. </server>
  6. <server>
  7. <id>private-maven-releases</id>
  8. <username>username</username>
  9. <password>password</password>
  10. </server>

4.1.3.3 镜像替换,第1个为自己私服主用,第2个为阿里云私服备用

  1. <mirror>
  2. <id>privatenexus</id>
  3. <name>privatenexus</name>
  4. <mirrorOf>central</mirrorOf>
  5. <url>https://your domain/repository/maven-public/</url>
  6. </mirror>
  7. <mirror>
  8. <id>aliyun</id>
  9. <name>aliyun</name>
  10. <mirrorOf>central</mirrorOf>
  11. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  12. </mirror>

4.2 maven项目开发配置

在pom.xml中增加以下配置
注:snapshotRepository和repository,这2个节点下的id要与4.1.3.2的server节点下的id一致,才可以使用deploy命令打包上传

  1. <!-- 下载快照 -->
  2. <repositories>
  3. <repository>
  4. <id>private-maven-public</id>
  5. <name>private-maven-public</name>
  6. <url>https://your domain/repository/maven-public/</url>
  7. <snapshots>
  8. <enabled>true</enabled>
  9. </snapshots>
  10. <releases>
  11. <enabled>true</enabled>
  12. </releases>
  13. </repository>
  14. </repositories>
  15. <!-- 打包上传 -->
  16. <distributionManagement>
  17. <snapshotRepository>
  18. <id>private-maven-snapshots</id>
  19. <name>private-maven-snapshots</name>
  20. <url>https://your domain/repository/maven-snapshots/</url>
  21. </snapshotRepository>
  22. <repository>
  23. <id>private-maven-releases</id>
  24. <name>private-maven-releases</name>
  25. <url>https://your domain/repository/maven-releases/</url>
  26. </repository>
  27. </distributionManagement>

4.3 手动上传jar包到Maven私服

参考下方截图,请使用有管理员权限的账号登录。红框中的选项一定要勾选,否则在项目中引用不了。
image.png