搭建Nexus代替maven中央库

maven中央库的鸡肋肯定不用多说了,国内也有一些企业或者团队搭建了私服供大家使用,例如阿里云等;

但也有不少人问我自己搭建私服的事,想法很简单,只是代替从中央库直接下载架包,又不想使用别人的。从网上看了很多教程,总是比较冗余,很多都把自己上传项目或者架包的一起写了,对于新手来说很容易串了。

因此我也写一篇吧,仅仅只是代替中央库下包的过程,其他需求后面看用的人多了再写吧:

先理下大纲:

1:安装JDK(本文跳过)

2:安装MAVEN(本文跳过)

3:安装Nexus

4:配置客户端

5:检验

6:Nexus的管理见另一篇文章 管理maven私服(Nexus)

3、安装Nexus

3-1:下载: https://help.sonatype.com/repomanager3/download

3-2:解压,解压后有两个文件夹:nexus-3.14.0(nexus根目录)和sonatype-work(架包仓库)

3-3:配置环境变量应该不用多说,如下图

以上几句应该不用多说,最后一句 export RUN_AS_USER=root 的作用是解决Nexus避免root启动的问题;

3-4:配置启动脚本(不需要启动脚本的可进入/home/nexus/nexus-3.14.0/bin执行./nexus start|stop……)

vim /etc/init.d/nexus

#!/bin/bash    
#chkconfig:2345 20 90    
#description:nexus    
#processname:nexus
export JAVA_HOME=/home/nexus/jdk1.8.0_172
export MAVEN_HOME=/home/nexus/apache-maven-3.5.4
nexus_dir=/home/nexus/nexus-3.14.0
case $1 in    
        start) $nexus_dir/bin/nexus start;;    
        stop) $nexus_dir/bin/nexus stop;;    
        status) $nexus_dir/bin/nexus status;;    
        restart) $nexus_dir/bin/nexus restart;;    
		dump ) $nexus_dir/bin/nexus dump ;; 
        console ) $nexus_dir/bin/nexus console ;;  		
        *) echo "require console | start | stop | restart | status | dump " ;;    
esac

chmod a+x /etc/init.d/nexus && chkconfig --add nexus && chkconfig nexus on && service nexus start 

          此处需要特别说明下:启动后不会立刻就会有端口显示(启动成功),需要过一会儿再查看

4-4:获取链接地址:

任意浏览器访问:http://ip:8081,然后在右上角登录:默认帐号:admin 密码:admin123 

上图框中即为所需要的地址;

       需要改端口的话,在根目录下的etc中的 nexus-default.properties去改

4、配置客户端

 配置客户端有全局和单项目两种:

全局需要在maven的settings.xml配置如下;不需要配置项目的pom.xml:

<profiles>
    <profile>
        <id>nexus-public</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <name>nexus</name>
                <url>http://………………/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
    </profile>
</profiles> <!-- 此节点是原本就存在的,不是新增的,只是增加了里面的内容,切记 -->
<!-- 激活 -->
<activeProfiles>
    <activeProfile>nexus-public</activeProfile>
</activeProfiles>

配置settings.xml中,上面配置即可生效,但是我个人喜欢多一分控制,因此我常常会多加一层mirror,如下(这一步是可选的)

<mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <name>nexus-public</name>
    <url>http://ip:port/repository/maven-public/</url>
</mirror> 

单项目如下,在项目的pom.xml相应的位置加上以下;不需要配置maven的settings.xml:

  ………………
  <version>3.2</version>
  <packaging>war</packaging>

  <repositories>
    <repository>
        <id>nexus</id>
        <name>nexus</name>
        <url>http://………………/groups/public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
	</repositories>
	<pluginRepositories>
	    <pluginRepository>
	        <id>nexus</id>
	        <name>nexus</name>
	        <url>http://………………/groups/public/</url>
	        <releases>
	            <enabled>true</enabled>
	        </releases>
	        <snapshots>
	            <enabled>true</enabled>
	        </snapshots>
	    </pluginRepository>
	</pluginRepositories>

	<properties>
………………

 

5、检验

检验方式分两步:检查客户端下载路径和服务端的sonatype-work大小

5-1:检查客户端下载路径的方式就太多了,就不一一介绍了;

5-2-1:进入sonatype-work检查大小:du -sh .  (初始时差不多在260M左右,随着客户端下载jar越多,仓库越大)

5-2-2:登录nexus检查:http://ip:端口/#browse/search/maven    查看仓库中的jar包

到此完结了,有什么问题可以留言提问!

其他说明:因为nexus启动需要差不多800M的内存,如果服务器内存小的话,可以使用swap,相关教程见我另一篇文章:Linux(Centos)配置swap

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值