nexus 使用
nexus 搭建maven私服oss版2.14.2-01-bundle,环境为centos_x64_6.5.
下载
# wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.2-01-bundle.tar.gz
安装
# tar -zxvf nexus-2.14.2-01-bundle.tar.gz
启动
总不是那么一帆风顺的,习惯就好
# cd nexus-2.14.2-01/bin
# ./nexus --help
Usage: ./nexus { console | start | stop | restart | status | dump }
启动nexus
#./nexus console
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
提示要使用root启动需要先设置RUN_AS_USER=root环境变量
# export RUN_AS_USER=root
# ./nexus console
如果出现UnknownHostException
Caused by: java.net.UnknownHostException:pretent.vm.lux132: unknown error
解决方法
# vi /etc/hosts
加入一行
127.0.0.1 pretent.vm.lux132
保存再次启动ok
后台服务启动
# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
看样子启动来了,在8081端口,打开浏览器输入:http://192.168.34.132:8081/nexus/(我的虚机ip),能看到搜索界面恭喜你安装成功了。
默认登陆用户名和密码为admin和admin123。
配置
bin/jsw/wrapper.conf 用来配置nexus管理程序的容器,包括jvm内存配置、日志等配置。
conif/nexus.properties用来配置管理程序端口以及相关目录等。
发布依赖到nexus
项目pom.xml
<distributionManagement>
<repository>
<id>user-release</id>
<name>User Project Release</name>
<url>http://192.168.34.132:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>user-snapshots</id>
<name>User Project SNAPSHOTS</name>
<url>http://192.168.34.132:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
这样deploy会报401没有权限
需要配置~/.m2/setttings.xml,在servers配置
<server>
<id>user-release</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>user-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
这里server里的id要和pom的repository的id一致。
从nexus下载依赖
项目pom.xml需要配置仓库地址
<!-- 依赖仓库 -->
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://192.168.34.132:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 插件 -->
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Team Nexus Repository</name>
<url>http://192.168.34.132:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
这样这个项目就可以从nexus上下载依赖了,如果想让所以项目都可以使用这个nexus私服下载依赖可以配置~/.m2/setttings.xml
<profile>
<!-- 依赖 -->
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<name>central</name>
<url>http://192.168.34.132:8081/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 插件 -->
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://192.168.34.132:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<!-- activeProfiles -->
<activeProfile>nexus</activeProfile>