Welcome 微信登录

首页 / 操作系统 / Linux / Linux下安装配置Nexus

一、安装和运行nexus1、下载nexus:http://www.sonatype.org/nexus/go可选择tgz和zip格式,以及war,选择tgz或zip时不同版本可能在启动时存在一定问题,可能是因为jdk版本问题,若无法启动请选择2.5或更早的版本注:nexus 2.6版本之后不再支持jdk1.62、安装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/localunzip nexus-2.2-01-bundle.zip或者cp nexus-2.2-01-bundle.tar.gz /usr/localtar xvzf nexus-2.2-01-bundle.tar.gz为了方便更新和切换版本,创建链接,更新或者切换版本只需更新链接即可:ln -s nexus-2.2-01 nexus3、运行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.dcp /usr/local/nexus/bin /nexus ./nexuschmod 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为nexuschown 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.gzln –s apache-maven-3.1.1 maven编辑/etc/profile文件,添加如下代码export MAVEN_HOME=/opt/apache-maven-3.2.1export 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 Party1.配置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.htmUbuntu 下 搭建Nexus Maven私服中央仓库  http://www.linuxidc.com/Linux/2016-08/133936.htmLinux下使用Nexus搭建Maven私服详解 http://www.linuxidc.com/Linux/2016-08/134630.htmLinux下使用Nexus搭建Maven私服 http://www.linuxidc.com/Linux/2016-08/134617.htm本文永久更新链接地址