Docker安装nexus 私有jar仓库
- 参考文章 https://www.jianshu.com/p/77af52a75ad8
- docker>nexus>Persistent Data https://hub.docker.com/r/sonatype/nexus3
下载镜像
docker pull sonatype/nexus3:3.20.0
目录结构
[root@centos01 nexus]# pwd
/data/nexus
[root@centos01 nexus]# tree
.
└── data
mkdir /data/nexus/data
##一定要执行下面这个添加权限的命令,不然启动报错
chown -R 200 /data/nexus/data
快速安装
docker run -d -p 8081:8081 --name group_nexus_1 sonatype/nexus3:3.20.0
完整安装
docker run -d \
-p 8081:8081 \
-p 8082:8082 \
-p 8083:8083 \
-p 8084:8084 \
-p 8085:8085 \
-v /data/nexus/data:/nexus-data \
-v /etc/localtime:/etc/localtime:ro \
--privileged=true \
--name group_nexus_1 sonatype/nexus3:3.20.0
浏览器访问
-
http://192.168.0.20:8081/
-
默认用户: admin,密码存放在/data/nexus/data/admin.password中,登录后重置密码为admin123
-
上传jar: http://192.168.0.20:8081/#browse/upload
-
仓库地址: http://192.168.0.20:8081/#browse/browse 页面点击copy按钮
Nexus 使用篇
- 参考文章 https://blog.csdn.net/qq_27384769/article/details/79383349
- 参考文章 https://blog.csdn.net/bowei026/article/details/82667839
添加maven hosted仓库
- 1、打开 http://192.168.0.20:8081/#admin/repository/repositories
- 2、点击 Create repository 按钮 >选择maven2(hosted)
简单介绍以下3种repository的类型:
A、hosted 本地仓库通常我们会部署自己的构件到这一类型的仓库。比如公司的第二仓库
B、proxy 代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库
C、group 仓库组, 用来合并多个hosted/proxy仓库, 当你的项目希望在多个repository使用资源时就不需要多次引用了,只需要引用一个group即可。只能部署到hosted库中
- 3、仓库基本信息
Name: 仓库名称
Maven2 > Version pollcy: Release/Snapshot/Mixed
Hosted > Deployment pollcy: Allow redeploy
Version pollcy的三种类型说明:(巨大坑,注意)
A、Release 发布版本,<version>2.2.2.RELEASE</version>,不支持SNAPSHOT版本
B、Snapshot 快照版本 <version>2.2.3.SNAPSHOT</version>,不支持RELEASE版本
C、Mixed 混合类型
-
4、保存save
-
仓库地址1 http://192.168.0.20:8081/#admin/repository/repositories 页面中点击copy按钮
-
仓库地址2 http://192.168.0.20:8081/#browse/browse 页面中点击copy按钮
添加maven proxy仓库
- 1、打开 http://192.168.0.20:8081/#admin/repository/repositories
- 2、点击 Create repository 按钮 >选择maven2(proxy)
- 3、填写基本信息
Name: 仓库名称
Proxy > Remote storage: 代理的地址,例如http://maven.aliyun.com/nexus/content/groups/public/
- 4、保存save
仓库加入group组中
- 1、打开 http://192.168.0.20:8081/#admin/repository/repositories
- 2、点击 maven-public : group 仓库
- 3、Group > Member repositories,将左边的 Available 成员,移入 Members 中
- 4、保存save
新建nexus账号
- 1、打开 http://192.168.0.20:8081/#admin/security/users
- 2、点击 Create local user按钮
- 3、填写账号基本信息
- 4、Roles,赋予角色
- 5、保存save
maven仓库上传jar
- maven仓库网页上传jar http://192.168.0.20:8081/#browse/upload
Maven篇
配置私有maven jar私服
- maven/conf/settings.xml
- 示例
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<!-- 配置镜像服务器/私服 -->
<mirror>
<id>pri nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.0.20:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<servers>
<!-- 配置远程仓库认证信息 -->
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
</settings>
<id>nexus</id> :自定义id,只要mirror.id与server.id对应就行
- 阿里云镜像服务器
<!-- 阿里云maven镜像服务器 -->
<!--
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
-->
配置远程仓库
- maven/conf/settings.xml 配置方式一
<!-- nexus 远程仓库 private-service-->
<profiles>
<profile>
<id>testDemo</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://192.168.0.20:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<!--
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
-->
</repository>
</repositories>
</profile>
</profiles>
- pom.xml配置方式二
<repositories>
<repository>
<id>testDemo</id>
<url>http://192.168.0.20:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<!--
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
-->
</repository>
</repositories>
- pom.xml配置方式三-精简版-(推荐)
<repository>
<id>testDemo</id>
<url>http://192.168.0.20:8081/repository/maven-public/</url>
</repository>
- 配置说明
updatePolicy:
A、always 每次都去远程仓库查看是否更新
B、daily 每天第一次的时候查看是否有更新
C、interval 允许设置一个分钟为单位的间隔时间,在这个间隔时间内只会去远程仓库中查询一次
D、never 从不更新
idea中将jar包上传到nexus服务器的配置(推荐)
-
指定上传的目标仓库 test : hosted仓库
-
pom.xml
<distributionManagement>
<repository>
<id>nexus</id>
<name>maven-releases</name>
<url>http://192.168.0.20:8081/repository/test/</url>
</repository>
</distributionManagement>
- 执行上传命令
mvn clean deploy
使用命令将jar上传到nexus服务器的配置
mvn deploy:deploy-file \
-DgroupId=org.zss \
-DartifactId=ps3 \
-Dversion=1.1 \
-Dpackaging=jar \
-Dfile=ps-3-1.0-SNAPSHOT.jar \
-Durl=http://localhost:8081/nexus/content/repositories/tt \
-DrepositoryId=testDemo
参数说明:
deploy:deploy-file 表示发布独立的文件
groupId、artifactId、version 可根据需求设定
url是nexus服务器中目标仓库的路径
repositoryId与server.id必须一致