CentOS系統中安裝Nexus並導入已有的構件庫


Nexus是Maven倉庫管理器,用於搭建一個本地倉庫服務器,這樣做的主要的好處就是節約網絡資源,速度快,開發團隊中所有的Maven可以共享這個本地倉庫,下載一遍共享使用。另外一個優點就是他為你的組織提供一個搭建構件的地方。本文將介紹如何在CentOS系統中安裝配置Nexus,並介紹如何導入已有的構件倉庫。

1、 軟件

a) 下載Nexus 地址:http://www.sonatype.org/downloads/nexus-2.1.2-bundle.tar.gz
b) 如無特殊說明,本文檔操作用戶為nexus
c) nexus默認的管理員用戶名密碼是:admin/admin123

2、 安裝

a) 解壓

1 $ tar zxvf nexus-2.1.2-bundle.tar.gz

b) 移動到其他目錄

1 $ mv nexus-2.1.2 /home/nexus/nexus

c) 設置為系統自啟動服務(使用root用戶)

1 # cd /etc/init.d/
2 # cp /home/nexus/nexus/bin/jsw/linux-x86-64/nexus nexus

 

編輯/etc/init.d/nexus文件,添加以下變量定義:

1 NEXUS_HOME=/home/nexus/nexus 2 PLATFORM=linux-x86-64
3 PLATFORM_DIR="${NEXUS_HOME}/bin/jsw/${PLATFORM}"

 


修改以下變量:

1 WRAPPER_CMD="${PLATFORM_DIR}/wrapper"
2 WRAPPER_CONF="${PLATFORM_DIR}/../conf/wrapper.conf"
3 PIDDIR="${NEXUS_HOME}"

修改如下變量,設置啟動用戶為nexus:

1 RUN_AS_USER=nexus

執行命令添加nexus自啟動服務

1 # chkconfig –add nexus
2 # chkconfig –levels 345 nexus on

執行如下命令啟動、停止nexus服務

1 # service nexus start
2 # service nexus stop

 

d) 檢查是否啟動成功

在本機瀏覽器中訪問URL: http://localhost:8081/nexus
會出現Nexus的歡迎頁面
注:如果想遠程通過瀏覽器訪問,則在遠程瀏覽器中輸入http://<ip>:8081/nexus
<ip> 可通過在本地機器上輸入命令 ifconfig 查看
如果未能訪問到nexus的歡迎頁面,需要查看本機的防火牆設置,是否打開了端口8081

e) 修改配置

配置文件位置nexus/conf/nexus.properties,配置示例如下:

 1 # Sonatype Nexus
 2 # ==============
 3 # This is the most basic configuration of Nexus.
 4 
 5 # Jetty section
 6 application-port=8081
 7 application-host=0.0.0.0
 8 nexus-webapp=${bundleBasedir}/nexus  9 nexus-webapp-context-path=/nexus 10 
11 # Nexus section
12 nexus-work=${bundleBasedir}/../sonatype-work/nexus 13 runtime=${bundleBasedir}/nexus/WEB-INF 14 pr.encryptor.publicKeyPath=/apr/public-key.txt

主要配置參數:

application-port:nexus啟動端口
nexus-work:指定構件庫的存儲位置

3、 導入已有的構件庫

nexus的構件倉庫都保存在sonatype-work目錄中,該目錄的位置由nexus/conf/nexus.properties配置文件指定。
將已有的sonatype-work目錄替換安裝后的nexus的sonatype-work目錄。
修改sonatype-work/nexus/conf目錄下的nexus.xml文件,修改<localStorage>節點下面的<url>子節點為真實路徑即可,如central庫的配置:

 1 <repository>
 2       <id>central</id>
 3       <name>Central</name>
 4       <providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole>
 5       <providerHint>maven2</providerHint>
 6       <localStatus>IN_SERVICE</localStatus>
 7       <notFoundCacheActive>true</notFoundCacheActive>
 8       <notFoundCacheTTL>1440</notFoundCacheTTL>
 9       <userManaged>true</userManaged>
10       <exposed>true</exposed>
11       <browseable>true</browseable>
12       <writePolicy>READ_ONLY</writePolicy>
13       <indexable>true</indexable>
14       <searchable>true</searchable>
15       <localStorage>
16         <provider>file</provider>
17         <url>file:/home/nexus/sonatype-work/nexus/storage/central</url>
18       </localStorage>
19       <remoteStorage>
20         <provider>apacheHttpClient3x</provider>
21         <url>http://repo1.maven.org/maven2/</url>
22         <mirrors>
23           <mirror>
24             <id>http://repo.springsource.org/repo/</id>
25             <url>http://repo.springsource.org/repo/</url>
26           </mirror>
27           <mirror>
28             <id>http://gradle.artifactoryonline.com/gradle/libs</id>
29             <url>http://gradle.artifactoryonline.com/gradle/libs</url>
30           </mirror>
31           <mirror>
32             <id>http://repo.opengeo.org</id>
33             <url>http://repo.opengeo.org</url>
34           </mirror>
35           <mirror>
36             <id>http://repo.maven.apache.org/maven2</id>
37             <url>http://repo.maven.apache.org/maven2</url>
38           </mirror>
39           <mirror>
40             <id>http://search.maven.org</id>
41             <url>http://search.maven.org</url>
42           </mirror>
43           <mirror>
44             <id>http://repo1.maven.org/maven2/</id>
45             <url>http://repo1.maven.org/maven2/</url>
46           </mirror>
47           <mirror>
48             <id>http://download.osgeo.org/webdav/geotools/</id>
49             <url>http://download.osgeo.org/webdav/geotools/</url>
50           </mirror>
51         </mirrors>
52       </remoteStorage>
53       <externalConfiguration>
54         <proxyMode>ALLOW</proxyMode>
55         <artifactMaxAge>-1</artifactMaxAge>
56         <itemMaxAge>1440</itemMaxAge>
57         <cleanseRepositoryMetadata>false</cleanseRepositoryMetadata>
58         <downloadRemoteIndex>true</downloadRemoteIndex>
59         <checksumPolicy>WARN</checksumPolicy>
60         <repositoryPolicy>RELEASE</repositoryPolicy>
61         <autoBlockActive>true</autoBlockActive>
62         <fileTypeValidation>true</fileTypeValidation>
63         <metadataMaxAge>1440</metadataMaxAge>
64       </externalConfiguration>
66 </repository>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM