1. 程式人生 > >Maven私服倉庫管理之Nexus 3.x

Maven私服倉庫管理之Nexus 3.x

Nexus是一個強大的倉庫管理器,極大地簡化了內部倉庫的維護和外部倉庫的訪問。

2016年4月6日Nexus 3.0版本釋出,相較2.x版本有了很大的改變:

  1. 對低層程式碼進行了大規模重構,提升效能,增加可擴充套件性以及改善使用者體驗。

  2. 升級介面,極大的簡化了使用者介面的操作和管理。

  3. 提供新的安裝包,讓部署更加簡單。

  4. 增加對Docker, NeGet, npm, Bower的支援。

  5. 提供新的管理介面,以及增強對自動任務的管理。

安裝

環境要求

  • Windows / Linux / Mac

  • Java JDK 8+

  • Apache Maven 3.0+

安裝步驟

示例基於Ubuntu 16.04 LTS環境,安裝前檢查JDK:

nexus@ubuntu:~$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

1. 建立管理使用者

該步驟不是必須的,但為了更好的管理和維護,建議建立一個管理使用者。

# 使用root許可權建立一個使用者
root@ubuntu:~# adduser nexus

## 給nexus使用者新增sudo許可權

# 1. 給root寫的許可權
root@ubuntu:~# chmod u+w /etc/sudoers # 2. 編輯/etc/sudoers,在root下新增nexus使用者許可權 nexus ALL=(ALL) ALL # 3. 儲存後撤回寫的許可權 root@ubuntu:~# chmod u-w /etc/sudoers

2. 下載安裝包

root@ubuntu:~# su nexus
nexus@ubuntu:~$ wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.0.1-01-unix.tar.gz
nexus@ubuntu:~$ ls
nexus-3.0
.1-01-unix.tar.gz

3. 解壓和安裝

nexus@ubuntu:~$ tar -zxvf nexus-3.0.1-01-unix.tar.gz

# 檢視安裝目錄
nexus@ubuntu:~$ ls nexus-3.0.1-01/
bin  data  deploy  etc  lib  LICENSE.txt  NOTICE.txt  public  system

# bin: 啟動指令碼和啟動時的配置檔案
# data: 資料儲存目錄
# etc: 配置檔案
# lib: Apache Karaf的二進位制包
# public: 公共資源
# system: 系統依賴的元件和外掛

# 指定JDK版本(可選)
nexus@ubuntu:~$ vim nexus-3.0.1-01/bin/nexus
INSTALL4J_JAVA_HOME_OVERRIDE="/usr/lib/jvm/java-8-oracle"

# 修改使用的使用者(不建議使用root使用者)
nexus@ubuntu:~/nexus-3.0.1-01$ vim bin/nexus.rc
run_as_user="nexus"

4. 執行

[email protected]:~$ ./nexus-3.0.1-01/bin/nexus start
# 可選的命令:{start|stop|run|run-redirect|status|restart|force-reload}

5. 驗證安裝

配置

以下配置均為可選,更詳細的配置請檢視官方文件

1. JVM配置(可選)

Nexus 3.0 的預設配置:

[email protected]:~$ cat nexus-3.0.1-01/bin/nexus.vmoptions

-Xms1200M
-Xmx1200M
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc
-Djava.util.logging.config.file=etc/java.util.logging.properties
-Dkaraf.data=data
-Djava.io.tmpdir=data/tmp
-Dkaraf.startLocalConsole=false

修改JVM配置:

  1. 請根據系統實際情況配置

  2. 其他的JVM引數也可以新增到這裡

-Xms1500M
-Xmx2G

2. 配置埠號(可選,推薦為預設埠號:8081)

nexus@ubuntu:~$ vim nexus-3.0.1-01/etc/org.sonatype.nexus.cfg
application-port=9081

3. 配置資料儲存目錄(可選)

nexus@ubuntu:~$ vim nexus-3.0.1-01/bin/nexus.vmoptions

# 預設儲存目錄
-Dkaraf.data=data
-Djava.io.tmpdir=data/tmp

4. 配置代理(可選)

Apache httpd.

ProxyRequests Off
ProxyPreserveHost On

<VirtualHost: *:80>
  ServerName www.example.com
  ServerAdmin [email protected]
  ProxyPass /nexus http://localhost:8081/
  ProxyPassReverse / http://localhost:8081/
  ErrorLog logs/nexus/error.log
  CustomLog logs/nexus/access.log common
</VirtualHost>

nginx.

http {
  proxy_send_timeout 120;
  roxy_read_timeout 300;
  proxy_buffering off;
  keepalive_timeout 5 5;
  tcp_nodelay on;

  server {
    listen *:80;
    server_name www.example.com;

    # allow large uploads of files - refer to nginx documentation
    client_max_body_size 1G

    # optimize downloading files larger than 1G - refer to nginx doc before adjusting
    # proxy_max_temp_file_size 2G

    location /nexus {
       proxy_pass http://localhost:8081/nexus;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For
       $proxy_add_x_forwarded_for;
    }
  }
}

5. 配置SSL(可選)

Apache httpd. Ensure Apache httpd is loading mod_ssl.

Listen 443
ProxyRequests Off
ProxyPreserveHost On

<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile "example.pem"
  SSLCertificateKeyFile "example.key"
  ServerName repo.example.com
  ServerAdmin [email protected]
  ProxyPass / http://localhost:8081/
  ProxyPassReverse / http://localhost:8081/
  RequestHeader set X-Forwarded-Proto "https"
  ErrorLog logs/repo.example.com/nexus/error.log
  CustomLog logs/repo.example.com/nexus/access.log common
</VirtualHost>

nginx. Make sure nginx is compiled using the --with-http_ssl_module option.

http {
  proxy_send_timeout 120;
  proxy_read_timeout 300;
  proxy_buffering off;
  keepalive_timeout 5 5;
  tcp_nodelay on;
  
  server {
    listen *:443;
    server_name repo.example.com;

    # allow large uploads of files - refer to nginx documentation
    client_max_body_size 1G

    # optimize downloading files larger than 1G - refer to nginx doc before adjusting
    #proxy_max_temp_file_size 2G

    ssl on
    ssl_certificate example.pem;
    ssl_certificate_key example.key;

    location / {
      proxy_pass http://localhost:8081/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For ←-

      $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto "https";
    }
  }
}

倉庫介紹

1. 代理倉庫(Proxy Repository)

顧名思義是代理第三方倉庫的,如:

  • maven-central

  • nuget.org-proxy

版本策略(Version Policy):

  • Release: 正式版本

  • Snapshot: 快照版本

  • Mixed: 混合模式

佈局策略(Layout Policy):

  • Strict:嚴格

  • Permissive:寬鬆

2. 宿主倉庫(Hosted Repository)

儲存本地上傳的元件和資源的,如:

  • maven-releases

  • maven-snapshots

  • nuget-hosted

部署策略(Deployment Policy):

  • Allow Redeploy:允許重新部署

  • Disable Redeploy:禁止重新部署

  • Read-Only:只讀

3. 倉庫組(Repository Group)

通常包含了多個代理倉庫和宿主倉庫,在專案中只要引入倉庫組就可以下載到代理倉庫和宿主倉庫中的包,如:

  • maven-public

  • nuget-group

使用者介面的操作和管理相對簡單,請參考官方文件

與Maven整合

1. Servers 配置認證資訊

在Maven settings.xml中新增Nexus認證資訊:

<server>
  <id>nexus-releases</id>
  <username>admin</username>
  <password>admin123</password>
</server>

<server>
  <id>nexus-snapshots</id>
  <username>admin</username>
  <password>admin123</password>
</server>
  • nexus-releases: 用於釋出Release版本

  • nexus-snapshots: 用於釋出Snapshot版本

Release版本與Snapshot版本的區分:

Release: 4.3.0
Snapshot: 4.3.0-SNAPSHOT
  • 在專案POM.xml中設定的版本號新增SNAPSHOT標識的都會發布為SNAPSHOT版本,沒有SNAPSHOT標識的都會發布為Release版本。

  • SNAPSHOT版本會自動加一個時間作為標識,如:4.3.0-SNAPSHOT釋出後為變成4.3.0-SNAPSHOT-20160712.114532-1.jar

2. 配置自動化部署構件

在POM.xml中新增以下程式碼:

<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
    <name>Nexus Release Repository</name>  
    <url>http://127.0.0.1:8081/repository/maven-releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>  
  </snapshotRepository>  
</distributionManagement> 

注意事項:

  • ID名稱必須要與settings.xml中Servers配置的ID名稱保持一致。

  • 專案版本號中有SNAPSHOT標識的,會發布到Nexus Snapshots Repository, 否則釋出到Nexus Release Repository,並根據ID去匹配授權賬號。

3. 部署到Nexus倉庫

mvn deploy

4. 上傳第三方JAR包

Nexus 3.0不支援頁面上傳,可使用maven命令:

# 如第三方JAR包:aliyun-sdk-oss-2.2.3.jar
mvn deploy:deploy-file 
  -DgroupId=com.aliyun.oss 
  -DartifactId=aliyun-sdk-oss 
  -Dversion=2.2.3 
  -Dpackaging=jar 
  -Dfile=D:\aliyun-sdk-oss-2.2.3.jar 
  -Durl=http://127.0.0.1:8081/repository/maven-3rd/ 
  -DrepositoryId=nexus-releases

注意事項:

  • 建議在上傳第三方JAR包時,建立單獨的第三方JAR包管理倉庫,便於管理有維護。(maven-3rd)

  • -DrepositoryId=nexus-releases 對應的是settings.xml中Servers配置的ID名稱。(授權)

5. 使用代理中央倉庫

<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus</id>
        <name>Nexus Plugin Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>

注意事項:

  • 在開發中如果有嚴格的管理要求,可將SNAPSHOT和RELEASE單獨配置。

  • 有外掛依賴時配置外掛倉庫,預設會使用Maven中央倉庫。

相關推薦

Maven倉庫管理Nexus 3.x

Nexus是一個強大的倉庫管理器,極大地簡化了內部倉庫的維護和外部倉庫的訪問。 2016年4月6日Nexus 3.0版本釋出,相較2.x版本有了很大的改變: 對低層程式碼進行了大規模重構,提升效能,增加可擴充套件性以及改善使用者體驗。 升級介面,極大的簡化了使用者介

maven--的搭建(Nexus的使用)和注意的問題

maven--私服的搭建(Nexus的使用)和注意的問題 私服是什麼 私服,私有伺服器,是公司內部Maven專案經常需要的東東,不總結一下,不足以體現出重視。Nexus是常用的私用Maven伺服器,一般是公司內部使用。下載地址是http://www.sonatype.org/ne

maven--的搭建(Nexus的使用)

While starting Nexus I was getting following error, this was on a machine that was running at 1GB of memory. Error occurred during initialization of VM

如何安裝Nexus Repository Manager OSS 3.x,如何搭建管理Maven,win10、win7通用安裝詳解,附:錯誤解決方案。

        今天搭建一個Maven私服花了不少功夫,查閱了很多安裝的帖子以及百度了很多錯誤解決方案,然後將所有的帖子精華部分,附上我的經驗來帶給大家一個特別詳細的安裝方案,所以該文章大部分可以說是總結別人帖子。話不多說,開始安裝: 1.下載 &nb

使用 Sonatype Nexus 3 搭建 Maven 、本地私有 Maven 倉庫,Gradle 打包 jar 、arr 後自動上傳到 Nexus Maven 倉庫配置

1 下載 Nexus 3 官網截圖 注:Nexus 3 版本的執行需要 jdk1.8 解壓 得到 2 個資料夾 // Nexus 執行時所需要的檔案,如啟動指令碼 nexus-3.9.0-01 // Nexus生成的配置檔案,

CentOS7搭建MavenNexus倉庫

roo file use port centos *** https 裝包 jdk 1.下載nexus 打開一下鏈接: https://www.sonatype.com/nexus-repository-oss 下載安裝包。 2.解壓安裝包 tar zxvf nexus

1107_Linux系統下如何安裝Nexus(使用Nexus搭建Maven)-2.Nexus倉庫設定,手動更新索引,自動更新索引

Linux系統下如何安裝Nexus(使用Nexus搭建Maven私服)-2.Nexus倉庫設定,手動更新索引,自動更新索引 2018年08月27日 17:30:53 weixin_42828741 閱讀數:64 還未安裝的可閱讀以下文章: Linux系統下如何安裝Nexus(使用Nexus搭

利用nexus構建maven、docker、npm、gradle倉庫

前言 在小型公司發展歷程中,開發對倉庫的依賴不斷提高,java web需要maven倉庫、android需要gradle倉庫、運維需要docker倉庫…… 是時候搞一套倉庫私服了。 初識nexus nexus是目前市場上,支援倉庫種類最多,使用者群體最

Maven管理nexus定期刪除snapshots!

1.專案做了10個月的時候,maven私服突然掛掉了,進入機器一看,發現空間已滿。因為平時經常deploy,snapshot版本越來越多。有個資料夾特別大,/app/maven/nexus/sonatype-work/nexus3/blobs/default/content,

Windows環境使用Nexus-3.x搭建Maven

[前言] 本文主要講解在Wiindows環境下搭建最新出的Nexus 3.x私服。 1、搭建私服的必要性 一般情況下,各個公司的開發團隊為了提高開發效率,都會使用專案構建工具進行開發。常見的構建工具有Ant、Grandle和Maven等。而使用構建工具,一般情況下都需要管理

maven nexus-3.14.0-04在CentOS7搭建

Nexus介紹:     Nexus 是Maven倉庫管理器,如果你使用Maven,你可以從Maven中央倉庫 下載所需要的構件(artifact),     但這通常不是一個好的做法,你應該在本地架設一個Maven倉庫伺服器,在代理遠端倉

Maven學習-使用Nexus(3.*)搭建Maven

1:下載maven     wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz 2:解壓安裝     tar zxf apache-

maven上傳jar到nexus倉庫

1通過網頁上傳 這種方法只是上傳了jar包。通過maven引用當前jar,不能取得jar的依賴 from pom的方式,選擇pom檔案,以及jar。通過maven引入jar時,會自動載

maven 搭建nexus 3.0.1,安裝,使用

一 安裝 注意: 檢視其它nexus-3.0.0-03-win64 安轉文件,提示需要安裝jdk1.8,但是本人安裝的是jdk1.7,安裝執行,沒發現有什麼問題; 二,功能介紹    1.Search , 查詢私服中有哪些包, 在Search 級中可以使用模糊搜尋,

maven:用nexus搭建企業級私有倉庫

2. 將下載檔案拷貝到一個指定的資料夾,如:D:\maven_home\co_repository,然後解壓縮,得到資料夾結構: 說明:nexus-2.11.0-02包含nexus程式,sonatype-work是nexus倉庫儲存jar包的預設路徑。 3.設定環境變數,新增nexus的工作路徑,在

離線更新nexus搭建的Maven中央倉庫索引

            nexus可以線上更新中央倉庫索引,但是更新速度慢,而且很有可能下載的索引不全。下面介紹一種離線更新中央倉庫索引的方式,速度快並且可靠。 1、訪問http://repo.maven.apache.org/maven2/.index/下載中心倉庫最新版

【原創】Docker 搭建Mavennexus 3.17初始密碼登入不上問題/admin登陸不上問題

【原創-轉載請說明出處】 博主最近在虛擬機器中搭建Maven私服,遇到了一個關鍵問題就是nexus 3.17版本後初始密碼不是admin/admin123。 對於nexus不熟悉的我弄了很長時間!!!心裡一萬頭艹ma飛過!!!各種查資料度娘搜尋出來的都是老版本修改密碼步驟!!!, 後來博主FanQian

Windows下使用Nexus搭建Maven(安裝)

支持 blog 試用 prop 解壓 結束 factor repos name 一、下載Nexus 下載OSS最新版:https://www.sonatype.com/download-oss-sonatype 老版本:https://support.sonatype.

Windows 下Nexus搭建Maven

4.3 快照 激活 nap cti sha 基本 新增 項目 轉自:http://blog.csdn.net/fanyuna/article/details/40145827 1、 為什麽使用Nexus 如果沒有私服,我們所需的所有構件都需要通過mave

nexus搭建mavenjar包上傳和下載

ive 校驗 public 我們 賬號 依賴 detail 接下來 triangle nexus搭建maven私服及私服jar包上傳和下載 標簽: nexus管理maven庫snapshot 2017-06-28 13:02 844人閱讀 評論(0) 收