Linux下安装配置Nexus

    xiaoxiao2021-04-17  39

    、安装运行nexus

    1、下载nexushttp://www.sonatype.org/nexus/go

    选择tgzzip格式以及war,选择tgzzip不同版本可能启动时存在一定问题,可能因为jdk版本问题若无法启动请选择2.5更早的版本

    注:nexus 2.6版本之后不再支持jdk1.6

    2、安装nexus

    若下载war,则将其放置tomcat下的webapp目录中,改名nexus,运行tomcat服务,即可访问http://localhost:8081/nexus  默认用户名:admin;密码admin123

    若下载tgz或者zip将其解压至usr/local/目录下(也可自己指定目录),root/Download目录下:

    cp nexus-2.2-01-bundle.zip /usr/local

    unzip nexus-2.2-01-bundle.zip

    或者

    cp nexus-2.2-01-bundle.tar.gz /usr/local

    tar xvzf nexus-2.2-01-bundle.tar.gz

    为了方便更新和切换版本,创建链接,更新或者切换版本只需更新链接即可:

    ln -s nexus-2.2-01 nexus

    3运行nexus

    没有安装为service的情况下运行nexus

    若为较新版本

    cd /usr/local/nexus

    ./bin/nexus start

    启动成功nexus监听8081端口,在日志可进行查看

    tail -f logs/wrapper.log

    较早的版本需要进入平台目录下进行启动(较新版本也可以进行启动

    cd /usr/local/nexus/

    ./bin/jsw/linux-x84-64/nexus start

    浏览器中输入http://localhost:8081/nexus即可进入

    4安装nexusservice

    root用户身份,设置为系统服务 

      cd /etc/init.d 

    cp /usr/local/nexus/bin /nexus ./nexus 

    chmod 755 /etc/init.d/nexus

    Red Hat, Fedora, and CentOS增加nexus服务

    $ cd /etc/init.d

    增加nexus服务

    $ chkconfig --add nexus

    添加运行级别345

    $ chkconfig --levels 345 nexus on

    启动nexus

    $ service nexus start

    验证关系成功启动

    $ tail -f /usr/local/nexus/logs/wrapper.log

    编辑/etc/init.d/nexus的文本

    NEXUS_HOME="/usr/local/nexus"

    PIDDIR="${NEXUS_HOME}"  

    RUN_AS_USER "nexus"   此处用户名可随意选择,最好不要是root

    ①如果使用root创建其它用户,则改为root(不建议使用root

    ②如果使用该设置,需要:

    •  nexus 用户存在

    useradd  nexus

    • 更改nexus 安装目录的OwnerGroupnexus

    chown nexus nexus nexus

    启动服务 

    service nexus start

    二、配置maven使用nexus

    这里先对Maven的安装作一简单介绍:

    下载maven安装包,apache-maven-3.1.0-bin.tar.gz,并解压

    cp apache-maven-3.1.1-bin.tar.gz /usr/local/

    tar –zxvf apache-maven-3.1.1-bin.tar.gz

    ln –s apache-maven-3.1.1 maven

    编辑/etc/profile文件,添加如下代码

    export MAVEN_HOME=/opt/apache-maven-3.2.1

    export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

    运行以下命令检查maven安装:

      显示路径

    echo $MAVEN_HOME

      显示信息即成功

    mvn -v

    接下来要使用Nexus,则需要配置Maven去检查Nexus而非公共的仓库。

    创建~/.m2/settings.xml(初始状态文件不存在)编辑内容:

    <settings>

      <profiles>

        <profile>

          <id>nexus</id>

          <repositories>

            <repository>

              <id>central-snapshots</id>

              <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>

              <releases><enabled>false</enabled></releases>

              <snapshots><enabled>true</enabled></snapshots>

            </repository>

            <repository>

              <id>central-releases</id>

    <!-- url原为http://central,指向http://repos.d.xxx.com/nexus/content/groups/public   其中xxx一般为公司名--->

              <url>http://localhost:8081/nexus/content/groups/public</url>

    <!-- 表示可以从此仓库下载release版本 -->

    <releases><enabled>true</enabled></releases>

    <!-- 表示不可以从此仓库下载snapshot版本 -->

    <snapshots><enabled>false</enabled></snapshots>

            </repository>

          </repositories>

    <!--  插件仓库 -->

          <pluginRepositories>

            <pluginRepository>

              <id>central-snapshots</id>

              <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>

              <releases><enabled>false</enabled></releases>

              <snapshots><enabled>true</enabled></snapshots>

            </pluginRepository>

            <pluginRepository>

              <id>central-releases</id>

              <url>http://localhost:8081/nexus/content/groups/public</url>

              <releases><enabled>true</enabled></releases>

              <snapshots><enabled>false</enabled></snapshots>

            </pluginRepository>

          </pluginRepositories>

    <servers>  

      <server> 

    <!--配置所有的releases版本构件部署Nexusreleases仓库中--> 

        <id>nexus-releases</id>  

        <username>admin</username>  

        <password>admin123</password>  

      </server>  

      <server>  

    <!--配置所有的snapshot版本构件部署到NexusSnapshots仓库中--> 

        <id>nexus-snapshots</id>  

        <username>admin</username>  

        <password>admin123</password>  

      </server>    

    </servers>  

      </profile>

    <!--  配置activeProfiles后,此处添加snapshots,可以使snapshots被搜索到。-->

      </profiles>

    <!--添加id,激活profile-->

      <activeProfiles>

        <activeProfile>nexus</activeProfile>

      </activeProfiles>

    </settings>

    nexus配置成所有仓库的镜像之后,maven会从本地的nexus安装查阅,而非去外面查阅中央maven仓库。如果对nexus有一个构件请求,本地的nexus安装会提供这个构件;如果Nexus没有这个构件,nexus会从远程仓库获取这个构件,然后添加至远程仓库的本地镜像。

    三、配置nexus仓库

    Nexus有许多默认仓库:CentralReleasesSnapshots,和3rd Party

    1.配置central仓库

     Nexus内置了Maven中央代理仓库Central选择仓库列表中的 Central如图3.1

    3.1

    点击Configuration进行配置

    Repository Policyrelease不会代理远程仓库的snapshot构件snapshot版本构件不稳定且不受控制,使用这样的构件含有潜在的风险

    “Remote Storage Location”为远程仓库地址,http://repo.maven.org/maven2/ 

    “Download Remote Indexes”是否下载远程索引文件,默认为False,(中央仓库有大量的构件,其索引文件也很大,容易消耗大量的 中央仓库带宽)。将其设置为True(其他代理仓库也需要改成True,然后点击Save。在Nexus下载的中央仓库索引文件之后,我们就可以在本地搜索中央仓库的所有构件。

    2.Releases用于部署自己的release构件,Snapshots用于自己的snapshot构件3rd Party用于部署第三方构件,修改ConfigurationDeployment PolicyAllow Redeploy,则可以在Artifact Upload中上传本地文件。

     

    新增代理仓库

    1.新增代理仓库。如图3.2

    3.2 nexus新增代理仓库

     

    2.添加信息具体。如图3.3

     

    3.3 添加仓库信息

    3.添加仓库至组

    添加仓库到公共nexus仓库组。如图3.4

            Ordered Group Repositories:已在使用中的仓库。检索顺序与排序一致

        Available Repositories:已有未被使用

    如图3.4

    四、用户使用

    1.在开发环境中替换/rhome/用户名/.m2 目录下的文件settings.xml(新环境中可能没有此文件)

    2.修改maven安装目录下/conf/settings.xml文件。修改成干净的文件

    <localRepository>/workspace/repository</localRepository>此标签可以修改本地仓库路径,也可以在eclipseUser Settings中设置。

    3.在【工程名】下面执行 mvn  clean  install,即从私服里面下载pom文件里的 jar 包;

    4.eclipse开发工具中  clean 【工程名】,刷新jar包目录即可;

    转载请注明原文地址: https://ju.6miu.com/read-674098.html

    最新回复(0)