当前位置: 首页> 房产> 家装 > 生产环境必备:Docker 搭建 Nexus 全流程与批量上传 Jar 包实战

生产环境必备:Docker 搭建 Nexus 全流程与批量上传 Jar 包实战

时间:2025/7/14 7:43:59来源:https://blog.csdn.net/dutianze/article/details/142338004 浏览次数:2次

目录

1.创建docker-compose文件

2.域名代理无域名需求可跳过 

2.1创建nginx的compose  (映射端口更具实例进行改进)

2.2创建nginx.conf

3.访问nexus

 4.创建储存库以及批量上传jar包

4.1批量上传jar包

4.2创建两个sh脚本 

 4.3执行脚本

 4.4成功验证


“如果您在解决类似问题时也遇到了困难,希望我的
经验分享
对您有所帮助。如果您有任何疑问或者想分享您的经历,欢迎在评论区留言,我们可以一起探讨解决方案。祝您在编程路上顺利前行,不断突破技术的难关,感谢您的阅读!” 


 

1.创建docker-compose文件

version: '3'services:nexus:image: sonatype/nexus3:latestports:- 8081:8081volumes:- /data/nexus:/nexus-datacontainer_name: nexusnetworks:- harboruser: "0:0"restart: alwayshealthcheck:test: ["CMD", "curl", "-f", "http://localhost:8081"]interval: 30stimeout: 10sretries: 3networks:harbor: {}

2.域名代理无域名需求可跳过 

2.1创建nginx的compose  (映射端口更具实例进行改进)

version: '3'services:nginx:image: goharbor/harbor-portal:v2.2.0container_name: harbor-portalrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETGID- SETUID- NET_BIND_SERVICEvolumes:- type: bindsource:./common/config/portal/nginx.conftarget: /etc/nginx/nginx.confnetworks:- harbordns_search:.depends_on:- loglogging:driver: "syslog"options:syslog-address: "tcp://127.0.0.1:1514"tag: "portal"log:# 假设这里是日志服务的配置,可以根据实际情况进行调整image: some-logging-imagecontainer_name: logging-servicerestart: always# 其他可能的配置...networks:harbor:# 可以根据需要设置网络参数,如果不需要特殊设置,可以不添加任何内容

2.2创建nginx.conf

https可去掉我的环境特殊用来跳转用

xxxxx根据实际情况球盖

  upstream nexus-upstream {server xxxxxxxx:8081;}server {listen 8080;listen [::]:8080;server_name xxxxxxxxxxxx;client_max_body_size 100M;location / {proxy_pass http://nexus-upstream;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}}#https无需求删除以下字段即可server {listen 8443;server_name xxxxxxxxxxxxx;rewrite ^(.*)$ http://xxxxxxxxx$1 break;ssl_certificate /etc/cert/server.crt;ssl_certificate_key /etc/cert/server.key;}
}

3.访问nexus

IP:8081

账号admin

密码

查看。 

 4.创建储存库以及批量上传jar包

 根据自己需求选择(此选项介绍)

一、“maven2” 部分 “maven2” 通常表示遵循 Maven 2 版本的仓库规范和结构。Maven 是一个项目管理和构建工具,Nexus 可以作为 Maven 仓库的代理和托管服务器。

二、“hosted” 部分 “hosted” 类型的仓库是指由用户自己托管在 Nexus 服务器上的仓库。这种仓库主要用于存放组织内部开发的软件构件、第三方无法获取的私有库等。 例如,一个组织可以将自己开发的 Java 项目的 JAR 包、WAR 包等构件上传到这个 hosted 类型的 Maven 2 仓库中,以供内部的 Maven 项目使用。其他类型的仓库还有代理仓库(用于代理外部公共仓库,如 Maven Central)和 group 仓库(用于组合多个其他类型的仓库以方便统一访问)。 如何在 Nexus 中创建和配置 hosted 类型的 Maven 2 仓库? hosted 类型的 Maven 2 仓库有哪些优点和缺点? Nexus 中还有哪些其他类型的仓库?

根据自己需求修改

4.1批量上传jar包

将打包的tar包传到宿主机上解压

gshx是jar包目录结构

4.2创建两个sh脚本 

vim mavenimport.sh 
#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is       important
# Get command line params
while getopts ":r:u:p:" opt; docase $opt inr) REPO_URL="$OPTARG";;u) USERNAME="$OPTARG";;p) PASSWORD="$OPTARG";;
esac
donefind . -type f -not -path './mavenimport\.sh*' -not -path './upload.sh' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
 vim upload.sh 
#!/bin/bash
## -u nexus用户名 -p nexus密码 -r 远程仓库地址。
sh mavenimport.sh -u admin -p 123456 -r http://xxxxxxx.com/repository/gshx_Rslease/

仓库地址 URL获取方式(复制进去就可以了)

 4.3执行脚本

 ./upload.sh 

 

 4.4成功验证

 

 

 

关键字:生产环境必备:Docker 搭建 Nexus 全流程与批量上传 Jar 包实战

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: