使用nexus快速搭建maven中央仓库
搭建私服,可以是我们每次mvn package
等命令下载的数据包缓存到私服上,便于以后的下载
安装
同样需要jdk环境
yum -y install java-devel
去官网下载源码
https://www.sonatype.com/download-nexus-repo-oss
下载二进制文件
tar xf nexus-3.13.0-01-unix.tar.gz
会生成nexus-3.13.0-01和sonatype-work文件夹
mv nexus-3.13.0-01 sonatype-work /usr/local
cd /usr/local
ln -s nexus-3.13.0-01 nexus
配置
配置配置文件,设置启动用户为root
vim /usr/local/nexus/bin/nexus.rc
启动
nexus默认监听8081端口
/usr/local/nexus/bin/nexus run 启动并输出信息
/usr/local/nexus/bin/nexus start 启动
/usr/local/nexus/bin/nexus stop 关闭
/usr/local/nexus/bin/nexus status 查看状态
我们可以使用netstat -ntpl
查看启动状态
nexus是否开启8081端口监听
浏览器配置
我的机器ip为10.0.0.13,所以进入使用10.0.0.13:8081
用户名默认为admin,密码admin123
配置阿里云代理服务器
选择设置-》repositories-》create repository
依次选择maven2(proxy)
配置镜像地址
只需要填name和remote storage(镜像地址)即可
阿里云nexus镜像地址http://maven.aliyun.com/nexus/content/groups/public
填写完事后保存
将镜像添加进maven-public
添加进maven-public组后,以后所有获取数据包时都会查询阿里云镜像是否有该包
测试
给项目配置maven仓库;
修改maven下面的settings文件夹
配置mirror
<mirrors>
<mirror>
<id>nexus-myself</id>
<!--*指的是访问任何仓库都使用我们的私服-->
<mirrorOf>*</mirrorOf>
<name>Nexus myself</name>
<url>http://10.0.0.13:8081/repository/maven-public/</url>
</mirror>
</mirrors>
</mirrors>
配置profiles
配置私有仓库和插件地址
<profiles>
<profile>
<id>my-nexus</id>
<repositories>
<!-- 私有库地址-->
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://10.0.0.13:8081/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<!--插件库地址-->
<pluginRepository>
<id>nexus</id>
<url>http://10.0.0.13:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
紧接着上面,激活上面配置
<activeProfiles>
<activeProfile>my-nexus</activeProfile>
</activeProfiles>
再次使用maven
maven clean package
清除来数据包,再次打包时,即使用我们的中央仓库