1、下載nexus:http://www.sonatype.org/nexus/golinux
可選擇tgz和zip格式,以及war,選擇tgz或zip時不一樣版本可能在啓動時存在必定問題,可能是由於jdk版本問題,若沒法啓動請選擇2.5或更早的版本web
注:nexus 2.6版本以後再也不支持jdk1.6apache
2、安裝nexus瀏覽器
若下載war,則將其放置tomcat下的webapp目錄中,更名爲nexus,運行tomcat服務,便可訪問http://localhost:8081/nexus 默認用戶名:admin;密碼admin123tomcat
若下載tgz或者zip,將其解壓至usr/local/目錄下(也可本身指定目錄),在root/Download目錄下:app
cp nexus-2.2-01-bundle.zip /usr/localeclipse
unzip nexus-2.2-01-bundle.zipwebapp
或者maven
cp nexus-2.2-01-bundle.tar.gz /usr/localide
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的安裝做一簡單介紹:
下載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有許多默認倉庫: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.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包目錄便可;