歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下安裝配置Nexus

Linux下安裝配置Nexus

日期:2017/2/28 13:49:01   编辑: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

Copyright © Linux教程網 All Rights Reserved