Linux 下搭建 Sonatype Nexus Maven 私服

一、为什么需要搭建mave私服

      如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下 载构件无疑加大了仓库的负载和浪费了外网带宽,如果网速慢的话,还会影响项目的进程。很多情况下项目的开发都是在内网进行的,连接不到maven仓库怎么 办呢?开发的公共构件怎么让其它项目使用?这个时候我们不得不为自己的团队搭建属于自己的maven私服,这样既节省了网络带宽也会加速项目搭建的进程, 当然前提条件就是你的私服中拥有项目所需的所有构件。

二、Nexus下载

       下载地址:http://www.sonatype.org/nexus/go

      这里使用的是nexus-2.11.2-03的版本

三、解压下载的Nexus

     使用tar命令进行解压 tar -zxvf nexus-2.11.2-03-bundle.tar.gz,解压进入到nexus-2.11.3-03中使用使用命令ls,进行查看目录结构。

     bin:二进制执行目录

     conf:配置目录

     lib:包目录

     logs:日志目录

     nexus:web应用目录

     tmp:临时文件目录

 

四、配置当前访问的端口和用户

   1.进入到/nexus-2.11.2-03/bin目录下。使用vi命令开打nexus. "vi nexus",增加RUN_AS_USER =ROOT 显示如图:   

2.配置端口,进入到/nexus-2.11.2-03/bin目录下,使用VI打开nexus.properties文件。如图

nexus 是使用jetty容器进行启动的。默认的端口为8081.若端口没有被暂用的情况下默认使用8081

五、设置防火墙

     如果有启用防火墙的情况下需要供其他用户进行访问的情况下,配置防火墙。

    1.对iptables进行编辑,使用vi 命令进行打开。“vi etc/sysconfig/iptables”

    2.对iptables 插入 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT 

   

    3.使用命令重启防火墙. service iptables restart

五、启动nexus

    进入到nexus的bin目录下。使用sh命令进行启动。s

[root@instance-9j07wgiz nexus-2.11.2-03]# cd bin/
[root@instance-9j07wgiz bin]# ls
jsw  nexus  nexus.bat
[root@instance-9j07wgiz bin]# pwd
/u01/nexus/nexus-2.11.2-03/bin
[root@instance-9j07wgiz bin]# sh nexus start

 

 六、在项目中的pom进行修改仓库。

1、配置jar包仓库

<repositories>  
        <repository>  
            <id>nexus</id>  
            <name>nexus</name>  
            <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </repository>  
    </repositories>  

 

2、插件配置使用私有maven库

<pluginRepositories>  
        <pluginRepository>  
            <id>nexus</id>  
            <name>nexus</name>  
            <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </pluginRepository>  
    </pluginRepositories>  

 

 

 

 

 

 

posted @ 2016-05-24 10:40  calvin_Dai  阅读(3619)  评论(0编辑  收藏  举报