你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下安装配置Nexus

[日期:2016-09-10] 来源:Linux社区  作者:Linux [字体: ]

一、安装和运行nexus

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

可选择tgz和zip格式,以及war,选择tgz或zip时不同版本可能在启动时存在一定问题,可能是因为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、安装nexus为service

以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

添加运行级别3、4、5

$ 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 安装目录的Owner和Group为nexus

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版本构件部署Nexus的releases仓库中-->

    <id>nexus-releases</id> 

    <username>admin</username> 

    <password>admin123</password> 

  </server> 

  <server> 

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

    <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有许多默认仓库:Central,Releases,Snapshots,和3rd Party

1.配置central仓库

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

图3.1

点击Configuration进行配置:

Repository Policy为release,则不会代理远程仓库的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用于部署第三方构件,修改Configuration下Deployment Policy为Allow Redeploy,则可以在Artifact Upload中上传本地文件。

新增代理仓库

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

图3.2 nexus新增代理仓库

2.添加信息具体。

 

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>此标签可以修改本地仓库路径,也可以在eclipse中User Settings中设置。

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

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

Maven使用入门 http://www.linuxidc.com/Linux/2012-11/74354.htm

Ubuntu 下 搭建Nexus Maven私服中央仓库  http://www.linuxidc.com/Linux/2016-08/133936.htm

Linux下使用Nexus搭建Maven私服详解 http://www.linuxidc.com/Linux/2016-08/134630.htm

Linux下使用Nexus搭建Maven私服 http://www.linuxidc.com/Linux/2016-08/134617.htm

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-09/135083.htm

linux
相关资讯       Nexus配置  Linux下安装Nexus 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款