安装前提,需要jdk1.8
Nexus开源版下载地址: https://www.sonatype.com/download-oss-sonatype
我这里下载的是nexus-3.30.0-01-unix.tar.gz
mkdir -p /data/nexus
tar -zxvf nexus-3.30.0-01-unix.tar.gz
cd nexus-3.30.0-01/bin路径下,vi nexus添加环境变量
INSTALL4J_JAVA_HOME_OVERRIDE=/data/jdk/jdk1.8.0_271
修改启动用户
[root@yfm07 bin]# cat /data/nexus/nexus-3.30.0-01/bin/nexus.rc
run_as_user="root"
修改端口号
vi /data/nexus/nexus-3.30.0-01/etc/nexus-default.properties
修改内存限制或者日志存储配置
vi /data/nexus/nexus-3.30.0-01/bin/nexus.vmoptions
守护进程启动nexus
/data/nexus/nexus-3.30.0-01/bin/nexus start
前台进程启动nexus
/data/nexus/nexus-3.30.0-01/bin/nexus run
关闭
/data/nexus/nexus-3.30.0-01/bin/nexus stop
查看状态
/data/nexus/nexus-3.30.0-01/bin/nexus status
访问地址http://192.168.199.107:8081/
查看默认admin密码
[root@yfm07 bin]# cat /data/nexus/sonatype-work/nexus3/admin.password
9acab18e-3bf4-480d-a68e-95206e005235
登录后会要求修改密码 admin/123456
创建bolb存储
nexus默认给我建好了一些仓库,其中包括3类:代理proxy,仓库组group和宿主host。全部删掉,代理用来指向远程仓库的,如中央仓库,但毕竟国内的阿里云仓库比国外要快许多,所以我们自己建一个新的代理仓库,http://maven.aliyun.com/nexus/content/groups/public
接着我们创建宿主仓库,宿主仓库跟我们的项目相关,用于上传我们打出来的包,分发布Release和快照Snapshot两种,所以我们就建两个宿主仓库,过程同上
运行重复发布,因此Delpoyment policy 我们选择Allow redeploy
最后我们再创建一个仓库组,仓库组就像数据库的视图一样,能把多个仓库聚合起来用,记得把aliyun放在maven-central上面,这样才能优先找阿里云的构件
禁止匿名访问
Anonymous Access -》Allow anonymous users to access the server去掉勾选
nexus3.19的默认用户有两种:admin(能配置仓库、查询和上传构件)和anonymous(只能查构件), 我们新增一个角色deploy用于构建查询和上传,剥离admin的仓库管理能力
再回去用户那里新增一个deploy用户,deploy/123456
setting.xml 文件配置
<servers>
<server>
<id>nexus-releases</id>
<username>deploy</username>
<password>123456</password>
</server>
<server>
<id>nexus-snapshot</id>
<username>deploy</username>
<password>123456</password>
</server>
<server>
<id>nexus-mirror</id>
<username>deploy</username>
<password>123456</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-mirror</id>
<mirrorOf>*</mirrorOf>
<name>nexus repository</name>
<url>http://192.168.199.107:8081/repository/nexus-group/</url>
</mirror>
</mirrors>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-mirror</id>
<url>http://192.168.199.107:8081/repository/nexus-group/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- 配置方法二
<repository>
<id>nexus-releases</id>
<url>http://192.168.199.107:8081/repository/nexus-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshot</id>
<url>http://192.168.199.107:8081/repository/nexus-snapshot/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
-->
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-mirror</id>
<url>http://192.168.199.107:8081/repository/group/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<!-- 配置方法二
<pluginRepository>
<id>nexus-releases</id>
<url>http://192.168.199.107:8081/repository/nexus-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshot</id>
<url>http://192.168.199.107:8081/repository/nexus-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
-->
</profile>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
pom.xml配置
<repositories>
<repository>
<id>nexus-mirror</id>
<url>http://192.168.199.107:8081/repository/nexus-group/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<!--配置方法二
<repository>
<id>nexus-releases</id>
<url>http://192.168.199.107:8081/repository/nexus-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshot</id>
<url>http://192.168.199.107:8081/repository/nexus-snapshot/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
-->
</repositories>
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>nexus-releases</name>
<url>http://192.168.199.107:8081/repository/nexus-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshot</id>
<name>nexus-snapshot</name>
<url>http://192.168.199.107:8081/repository/nexus-snapshot/</url>
</snapshotRepository>
</distributionManagement>