nexus在linux上搭建


Maven 倉庫的分類:(maven的倉庫只有兩大類)

1.本地倉庫 

2.遠程倉庫,在遠程倉庫中又分成了3種:

2.1 中央倉庫 

2.2 私服 

2.3 其它公共庫

有個maven私服可以很方便地管理我們的jar包和發布構建到遠程倉庫,本文就介紹了如何在linux下一步步使用nexus搭建maven私服。

私服是架設在局域網的一種特殊的遠程倉庫,目的是代理遠程倉庫及部署第三方構件。有了私服之后,當 Maven 需要下載構件時,直接請求私服,私服上存在則下載到本地倉庫;否則,私服請求外部的遠程倉庫,將構件下載到私服,再提供給本地倉庫下載。

 

 

首先安裝好jdk 、maven

我這里安裝的JDK 、maven版本信息如下:

 

[html]  view plain copy
  1. [root@localhost bin]# java -version  
  2. java version "1.7.0_79"  
  3. Java(TM) SE Runtime Environment (build 1.7.0_79-b15)  
  4. Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)  
  5. [root@localhost bin]# mvn -v  
  6. Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)  
  7. Maven home: /home/data/maven  
  8. Java version: 1.7.0_79, vendor: Oracle Corporation  
  9. Java home: /home/xuan/soft/jdk1.7.0_79/jre  
  10. Default locale: en_US, platform encoding: UTF-8  
  11. OS name: "linux", version: "3.10.0-327.el7.x86_64", arch: "amd64", family: "unix"  

 

這里附上,環境配置:

 

[html]  view plain copy
  1. #java  
  2. export JAVA_HOME=/home/data/java  
  3. export PATH=$JAVA_HOME/bin:$PATH  
  4. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
  5.   
  6. #maven  
  7. export MAVEN_HOME=/home/data/maven  
  8. export MAVEN_HOME  
  9. export PATH=${PATH}:${MAVEN_HOME}/bin  
  10.   
  11. #nexus  
  12. export RUN_AS_USER=root  



 


下載安裝


nexus下載地址:http://www.sonatype.org/nexus/go

解壓后會在同級目錄中,出現兩個文件夾:nexus-oss-webapp-1.8.0和sonatype-work,前者包含了nexus的運行環境和應用程序,后者包含了你自己的配置和數據。

 

nexus-2.12.0-01-bundle.tar.gz

 

[html]  view plain copy
  1. tar -zxvf nexus-2.12.1-01-bundle.tar.gz -C /home/xuan/soft/nexus  
  2. [root@localhost soft]# tar -zxvf nexus-2.12.1-01-bundle.tar.gz  
  3. nexus-2.12.1-01/  
  4. nexus-2.12.1-01/nexus/  


為了方便更新和切換版本,創建鏈接,更新或者切換版本只需更新鏈接即可:

 

 

[html]  view plain copy
  1. tar -zxvf nexus-2.12.1-01-bundle.tar.gz -C /home/xuan/soft/nexus  
  2.   
  3.   
  4. [root@localhost nexus]# pwd  
  5. /home/xuan/soft/nexus  
  6. [root@localhost nexus]# ls  
  7. nexus-2.12.1-01  sonatype-work  
  8. [root@localhost nexus]#   
  9.   
  10. ln -s /home/xuan/soft/nexus /home/data/nexus  



 

 

啟動nexus

 

[html]  view plain copy
  1. [root@localhost bin]# pwd  
  2. /home/data/nexus/nexus-2.12.1-01/bin  
  3. [root@localhost bin]# ./nexus  
  4. Usage: ./nexus { console | start | stop | restart | status | dump }  


[html]  view plain copy
  1. $ ./nexus start  
  2. Starting Nexus OSS...  
  3. Started Nexus OSS.  


啟動成功:

 



查看控制台:

 

[html]  view plain copy
  1. [root@localhost bin]# ./nexus console  
  2. ****************************************  
  3. WARNING - NOT RECOMMENDED TO RUN AS ROOT  
  4. ****************************************  
  5. Running Nexus OSS...  
  6. Nexus OSS is already running.  

 



查看nexus日志:

[html]  view plain copy
  1. [root@localhost logs]# pwd  
  2. /home/data/nexus/nexus-2.12.1-01/logs  
  3. [root@localhost logs]# tail -f ./wrapper.log  
  4. jvm 1    | 2016-05-20 06:50:10,655-0700 INFO  [qtp1294005448-58] anonymous org.apache.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {s}->https://sonatype-download.global.ssl.fastly.net:443: Connection reset  



配置nexus


訪問網址:http://yourhostname:8081/nexus

訪問網址:http://192.168.140.128:8081/nexus

右上角以admin登陸,默認用戶名/密碼:admin/admin123。

 

安裝過程中可能遇到的錯誤:

1、進入啟動目錄,啟動時不成功  提示

****************************************
WARNING – NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.


大概意思就是要在環境配置export RUN_AS_USER=root,臨時配置

也可以在vi /etc/profile 文件末尾里添加export RUN_AS_USER=root  永久配置


2、訪問不了虛擬機的,需要關閉防火牆
centos從7開始默認用的是firewalld,這個是基於iptables的,雖然有iptables的核心,但是iptables的服務是沒安裝的。

所以你只要停止firewalld服務即可:
sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service


如果你要改用iptables的話,需要安裝iptables服務:
sudo yum install iptables-services
sudo systemctl enable iptables && sudo systemctl enable ip6tables
sudo systemctl start iptables && sudo systemctl start ip6tables

 

下一步進行Maven 與私服的測試:

~/.m2/settings.xml

在maven的setting.xml文件增加使用nexus私服配置:

maven 私服地址 http://192.168.1.102:8081/nexus/content/groups/public/

maven 中央倉庫地址:http://repo1.maven.org/maven2  (沒有私服鏡像可以中央倉庫的)

 

[html]  view plain copy
  1. <settings>  
  2.   <mirrors>   
  3.   
  4.     <mirror>  
  5.       <!--This sends everything else to /public -->  
  6.       <id>nexus</id>  
  7.       <mirrorOf>*</mirrorOf>  
  8.       <url>http://192.168.1.102:8081/nexus/content/groups/public/</url>  
  9.     </mirror>  
  10.   </mirrors>  
  11.   <profiles>   
  12.   
  13.     <profile>  
  14.       <id>nexus</id>  
  15.       <!--Enable snapshots for the built in central repo to direct -->  
  16.       <!--all requests to nexus via the mirror -->  
  17.       <repositories>  
  18.         <repository>  
  19.           <id>central</id>  
  20.           <url>http://central</url>  
  21.           <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>  
  22.           <snapshots><enabled>true</enabled></snapshots>  
  23.         </repository>  
  24.         <repository>  
  25.             <id>spring-release</id>  
  26.             <name>Spring Maven Release Repository</name>  
  27.             <url>http://repo.springsource.org/libs-release</url>  
  28.             <snapshots>  
  29.                 <enabled>false</enabled>  
  30.             </snapshots>  
  31.         </repository>  
  32.       </repositories>  
  33.      <pluginRepositories>  
  34.         <pluginRepository>  
  35.           <id>central</id>  
  36.           <url>http://central</url>  
  37.           <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>  
  38.           <snapshots><enabled>true</enabled></snapshots>  
  39.         </pluginRepository>  
  40.       </pluginRepositories>  
  41.     </profile>  
  42.   </profiles>  
  43.   <activeProfiles>  
  44.     <!--make the profile active all the time -->  
  45.     <activeProfile>nexus</activeProfile>  
  46.   </activeProfiles>  
  47.   
  48.   <!-- deploy artifacts to repository. -->  
  49.   <servers>  
  50.     <server>  
  51.       <id>releases</id>  
  52.       <username>admin</username>  
  53.       <password>admin123</password>  
  54.     </server>  
  55.     <server>  
  56.       <id>snapshots</id>  
  57.       <username>admin</username>  
  58.       <password>admin123</password>  
  59.     </server>  
  60.   </servers>  
  61.   
  62. </settings>  


測試效果圖:

 

1、在項目的pom.xml文件  加入maven依賴測試

2、私服上的依賴

3、項目本地的依賴

 

參考文檔:

http://tianweili.github.io/blog/2015/03/17/linux-nexus-maven-private-server/

maven 使用私服的參考文檔:

http://blog.csdn.net/liujiahan629629/article/details/39272321

本地上傳依賴到nexus服務器的兩種方式:

1、通過網頁上傳
2、通過maven的方式depoly

在項目的pom.xml 加入如下配置 (這里不做詳細介紹,可以參考上面的資料)

 

[html]  view plain copy
  1. <distributionManagement>  
  2.   <repository>  
  3.       <id>releases</id>  
  4.       <name>Nexus Release Repository</name>  
  5.       <url>http://192.168.1.102:8081/nexus/content/repositories/releases/</url>  
  6.   </repository>  
  7.   <snapshotRepository>  
  8.       <id>snapshots</id>  
  9.       <name>Nexus Snapshot Repository</name>  
  10.       <url>http://192.168.1.102:8081/nexus/content/repositories/snapshots/</url>  
  11.   </snapshotRepository>  
  12. </distributionManagement>  


 

運行命令:mvn package deploy 它會根據項目的pom.xml文件的配置如下  在私服生成些war包 (暫不知道在那些場景應用)

<groupId>com.xuan</groupId>

<artifactId>spring</artifactId>

<packaging>war</packaging>

<version>0.0.1-SNAPSHOT</version>

<name>springmvc_hibernate</name>

在私服生成 

/com/xuan/spring/xxxxx.pom

/com/xuan/springxxxxx.war



免責聲明!

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



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