Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)


nexus 简单理解就是管理maven的一个jar包,依赖管理的一个私服仓库软件;其他功能再次不多做介绍,自己可以度娘,上车

小编今天安装的Nexus版本:  nexus-2.12.0-01-bundle.tar.gz

一:nexus 安装环境

1、 Nexus安装环境CentOS 7  

        Centos7的下载安装配置请参考: https://blog.csdn.net/taoziBug/article/details/80262652

2、 Nexus 依赖与jdk,推荐使用jdk1.8; 

        关于jdk1.8的下载安装参考  :   https://blog.csdn.net/taoziBug/article/details/80264874

3、 Nexus 官方下载 :   https://www.sonatype.com/download-oss-sonatype

        之前小编在服务器端安装时,OSS 3.X   服务器1G内存会报错,大概意思就是内存不足,小编保守估计需要2G内存以上的服务器          1G内存的安装  OSS 2.X 版本的就没有问题

        所以小编在安装是  选用 nexus-2.12.0-01-bundle.tar.gz,服务器硬件条件满足的可以尝试一下

        

二:安装Nexus


        安装目录在  /usr/local/nexus/ ;

            1.在 /usr/local/  创建nexus文件夹

            mkdir nexus;

            2.进入 /usr/local/nexus/文件夹下

            cd /usr/local/nexus/

            Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

            3.利用xftp5,将安装包   nexus-2.12.0-01-bundle.tar.gz  传入到  /usr/local/nexus/目录下

            Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

              4. 解压nexus-2.12.0-01-bundle.tar.gz/usr/local/nexus

                  tar -axvf  nexus-2.12.0-01-bundle.tar.gz

            Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

            解压后会产生两个文件夹 sonatype-work、nexus-2.14.8-01(主程序),

            两个文件夹必须在同一个目录下(xftp5查看效果)

            Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

            5.1进入到   /usr/local/nexus/nexus-2.14.8-01/bin 目录下

             cd /usr/local/nexus/nexus-2.14.8-01/bin 

                    Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

            5.2.编辑文件,nexus,    修改RUN-AS-USER=root,保存退出  (i  esc  shift+:  wq  回车)

            vim nexus

        Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

         修改RUN-AS-USER=root,保存退出  (i  esc  shift+:  wq  回车)

        Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

        

6.    运行/usr/local/nexus/nexus-2.12.0-01/bin/nexus;

        进入bin目录,执行命令 ./nexus start

        如果报一下错误:是因为没有配置环境变量

  Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

        
    解决方法:
    A.临时生效
    export RUN_AS_USER=root,然后重新卡其 nexus,ok,完美运行

    B.加入系统变量,编辑配置文件 profile
    
    vi /etc/profile 加入export RUN_AS_USER=root
    
立即生效配置文件:
source /etc/profile,重新开启nexus,完美运行
7. 本机计算机  浏览器打开http://{IP}:8081/nexus/; 

默认用户名/密码:admin/admin123

    如果报以下错误,可能是服务器端防火墙没有关闭,或者没有打开8081端口权限

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

解决方案

      查看防火墙运行状态

       firewall-cmd    --state

    Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

    1.打开防火墙8081端口权限 (感兴趣的同学可以去查询在系统文件中设置多个端口的开放)

        1.1临时开放    

            firewall-cmd --remove-service=ftp --permanent 

    Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

        1.2永久开放

            firewall-cmd --add-port=80/tcp --permanent

    Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

    

    2.直接关闭防火墙(小编推荐

    systemctl  stop   firewalld.service

    3. 禁止开机启动启动防火墙

    systemctl   disable   firewalld.service

    Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

    重新在浏览器运行 http://{IP}:8081/nexus/完美,安装成功,点击右上角 log In,进行登陆,账户:admin 密码:admin123 点击logIn 按钮登陆

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

三: 手动更新索引

1.删除/usr/local/nexus/sonatype-work/nexus/indexer/central-ctx下的文件

    cd /usr/local/nexus/sonatype-work/nexus/indexer/central-ctx

    ll 查看此文件夹中的文件

    rm -rf 文件名 删除central-ctx下的所有文件

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

2.利用 xftp5  将indexer-cli-5.1.0.jar、nexus-maven-repository-index.gz、nexus-maven-repository-index.properties三个文件考到central-ctx目录下,

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

2.执行命令java -jar indexer-cli-5.1.0.jar -u nexus-maven-repository-index.gz;(过程很慢大概需要几分钟)

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

3.执行完毕后,此文件夹目录下会产生许多文件;

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

4.重新启动nexus,然后重新访问nexus页面,查看Browse Index中已经存在了jar依赖包,完美收官

cd /usr/local/nexus/nexus-2.12.0-01/bin

./nexus stop 关闭nexus

./nexus start 开启nexus

再次在页面访问:查看Browse Index树形目录

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

      四:页面 ,Nexus程序自动导入索引、开启远程索引

    新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123。

点击左边Administration菜单下面的Repositories,找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。如下图

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)


    然后在Apache Snapshots,Codehaus Snapshots和Maven Central这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)


可以进入Scheduled Tasks查看任务的执行情况,当执行完成时,远程仓库的索引就已经建立完毕了。 
Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

    这样设置以后, Nexus会自动从远程*仓库下载索引文件, 为了检验索引文件自动下载是否生效,可以却换到Browse Index

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)


    在左边菜单栏里面有个Artifact Search, 在输入框里面输入你想要搜索的构件名字,比如:maven, 那么查询结果如下:

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

 五、创建Nexus代理仓库

    点击菜单栏上的Add按钮后选择Proxy Repository,看到如下所示配置界面:

Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)

六:settings.xml的配置

<?xml version="1.0" encoding="UTF-8"?><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>E:\DMAVEN_REPOSITORY</localRepository> <servers> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> <server>          <id>tomcat</id>          <username>admin</username>          <password>admin</password>      </server> </servers> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <name>Local Repository</name> <url>http://ip:8081/nexus/content/groups/public/</url> </mirror> </mirrors> <profiles> <profile> <id>central</id> <repositories> <repository> <id>central</id> <name>central</name> <url>http://ip:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://ip:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>central</activeProfile> </activeProfiles></settings>

七:Maven项目pom.xml

  1. <distributionManagement>    
  2.          <!-- 两个ID必须与 setting.xml中的<server><id>nexus-releases</id></server>保持一致-->    
  3.           <repository>    
  4.               <id>nexus-releases</id>    
  5.               <name>Nexus Release Repository</name>    
  6.              <url>http://ip/nexus/content/repositories/releases</url>    
  7.           </repository>    
  8.          <snapshotRepository>    
  9.               <id>nexus-snapshots</id>    
  10.             <name>Nexus Snapshot Repository</name>    
  11.              <url>http://ip/nexus/content/repositories/snapshots</url>    
  12.          </snapshotRepository>    
  13.   </distributionManagement></pre><pre class="html" name="code"> </pre><pre class="html" name="code">
  14. </span>  
<!--8、mvn:deploy命令上传包,会发现下载路径必不是*库的路径,而是nexus里面的仓库组路径。这个说明配置环境成功。-->