Maven私服搭建
-----------------------siwuxie095
? ?
? ?
? ?
? ?
? ?
? ?
? ?
? ?
? ?
Maven 私服搭建
? ?
? ?
1、私服是指私有服務器,是架設在局域網的一種特殊的遠程倉庫,
目的是代理遠程倉庫以及部署第三方構件
? ?
有了私服之后,當 Maven 需要下載構件時,直接請求私服,私服
上存在則下載到本地倉庫;否則私服請求外部的遠程倉庫,將構件
下載到私服,再提供給本地倉庫下載
? ?
? ?
? ?
? ?
? ?
? ?
2、常用的 Maven 倉庫管理軟件(也稱 倉庫管理器):
? ?
(1)Apache Archiva
? ?
(2)JFrog Artifactory
? ?
(3)Sonatype Nexus(建議)
? ?
? ?
? ?
? ?
3、Sonatype Nexus 共有兩個版本:
? ?
(1)Nexus Repository Pro,即 專業版(付費)
? ?
(2)Nexus Repository OSS,即 開源版(免費)
? ?
? ?
? ?
? ?
4、這里選擇 Nexus Repository OSS,下載鏈接:
? ?
https://www.sonatype.com/download-oss-sonatype
? ?
其實 Nexus Repository OSS 的安裝包也有兩個版本:
? ?
(1)包含 Jetty 容器的 bundle 包
? ?
(2)不包含 Web 容器的 war 包
? ?
但截止目前(2017/9/23),官方已不再支持 war 包,
最后一個版本的 war 包的下載鏈接:
? ?
http://www.sonatype.org/downloads/nexus-latest.war
? ?
? ?
? ?
? ?
5、這里下載 Nexus 2.x 版本,將下載后的 nexus-2.14.5-02
-bundle.zip 解壓一覽:
? ?
? ?
? ?
「解壓路徑:D:\Nexus,解壓 即 安裝」
? ?
(1)nexus-2.14.5-02
? ?
該目錄包含 Nexus 運行所需要的文件,如:啟動腳本、依賴
的 jar 包
? ?
? ?
(2)sonatype-work
? ?
該目錄包含 Nexus 生成的配置文件、日志文件、倉庫文件等
? ?
? ?
? ?
? ?
6、配置 Nexus 的環境變量
? ?
(1)新建系統變量 NEXUS_HOME
? ?
變量名:NEXUS_HOME,變量值:D:\Nexus\nexus-2.14.5-02
? ?
? ?
? ?
? ?
(2)編輯系統變量 Path
? ?
變量名:Path,變量值:%NEXUS_HOME%\bin
? ?
? ?
? ?
? ?
? ?
7、將 Nexus 安裝成為 Windows 服務
? ?
(1)法一:通過自帶的腳本進行安裝
? ?
1)進入 D:\Nexus\nexus-2.14.5-02\bin\jsw 目錄,找到
對應的系統版本
? ?
? ?
? ?
2)運行 intall-nexus.bat 即可
? ?
? ?
? ?
3)自帶腳本介紹
? ?
| console-nexus.bat | 獨立啟動 Nexus 服務 |
| intall-nexus.bat | 安裝 Nexus 服務 |
| start-nexus.bat | 啟動 Nexus 服務 |
| stop-nexus.bat | 停止 Nexus 服務 |
| uninstall-nexus.bat | 卸載 Nexus 服務 |
? ?
注:獨立啟動 Nexus 服務,即:只是暫時啟動,一旦
命令行窗口關閉,服務將停止,不會駐留在 Windows
服務中
? ?
? ?
? ?
(2)法二:通過手動輸入命令進行安裝
? ?
1)打開命令行窗口,直接輸入命令 nexus install
? ?
? ?
? ?
2)常用命令介紹
? ?
| nexus console | 獨立啟動 Nexus 服務 |
| nexus start | 啟動 Nexus 服務 |
| nexus stop | 停止 Nexus 服務 |
| nexus restart | 重啟 Nexus 服務 |
| nexus install | 安裝 Nexus 服務 |
| nexus uninstall | 卸載 Nexus 服務 |
? ?
? ?
? ?
? ?
? ?
7、將 Nexus 服務設置為手動
? ?
? ?
? ?
啟動和停止 Nexus 服務有兩種命令:
? ?
(1)nexus start 和 nexus stop
? ?
(2)net start nexus 和 net stop nexus
? ?
? ?
? ?
? ?
8、打開瀏覽器,訪問:http://localhost:8081/nexus/,即可
看到 Nexus 的歡迎頁面
? ?
? ?
? ?
注:Jetty 容器的默認端口是 8081,如果本機有其它程序占用了
該端口,可以到 D:\Nexus\nexus-2.14.5-02\conf 路徑下找到
nexus.properties,修改 application-port 的值即可
? ?
? ?
? ?
? ?
9、點擊右上角 Log In,默認用戶名:admin,默認密碼:admin123
? ?
? ?
? ?
? ?
? ?
10、點擊左側導航欄的 Repositories,查看 Nexus 內置的倉庫
? ?
? ?
? ?
不難看出:
? ?
(1)倉庫按類型(Type)分共有四種
? ?
| group | 倉庫組 |
| hosted | 宿主 |
| proxy | 代理 |
| virtual | 虛擬 |
? ?
? ?
(2)倉庫按格式(Format)分共有兩種
? ?
| maven2 | - |
| maven1 | 由于太老,不再使用 |
? ?
? ?
(3)倉庫按策略(Policy)分共有兩種
? ?
| Release | 發布版本,即 正式版本 |
| Snapshot | 快照版本,即 測試版本 |
? ?
? ?
總而言之:
? ?
| Public Repositories | 倉庫組 | 用來將下述所有倉庫聚合并通過一致的地址提供服務 |
| Releases | 宿主倉庫 | 用來部署組織(或 公司)內部的發布版本構件 |
| Snapshots | 宿主倉庫 | 用來部署組織(或 公司)內部的快照版本構件 |
| 3rd party | 宿主倉庫 | 用來部署無法從公共倉庫獲得的第三方發布版本構件 |
| Apache Snapshots | 代理倉庫 | 用來代理 Apache Maven 倉庫的快照版本構件 |
| Central | 代理倉庫 | 用來代理中央倉庫的發布版本構件 |
| Central M1 shadow | 虛擬倉庫 | 用來提供中央倉庫中 maven1 格式的發布版本構件 |
? ?
? ?
? ?
? ?
11、一般情況下,只需要使用如下倉庫:
? ?
| Public Repositories | 倉庫組 | http://localhost:8081/nexus/content/groups/public/ |
| Releases | 宿主倉庫 | http://localhost:8081/nexus/content/repositories/releases/ |
| Snapshots | 宿主倉庫 | http://localhost:8081/nexus/content/repositories/snapshots/ |
| 3rd party | 宿主倉庫 | http://localhost:8081/nexus/content/repositories/thirdparty/ |
| Central | 代理倉庫 | http://localhost:8081/nexus/content/repositories/central/ |
? ?
? ?
? ?
? ?
? ?
? ?
12、添加代理倉庫,如:添加 Sonatype 的公共倉庫
? ?
(1)點擊 Add->Proxy Repository
? ?
? ?
? ?
? ?
(2)填寫相關信息,主要如下:
? ?
| Repository ID | sonatype-releases |
| Repository Name | Sonatype Releases |
| Provider | Maven2 |
| Repository Policy | Release |
| Remote Storage Location | https://repository.sonatype.org/content/groups/public/ |
? ?
? ?
? ?
? ?
? ?
? ?
13、將 Sonatype Releases 代理倉庫添加到倉庫組
? ?
選擇倉庫組 Public Repositories,點擊 Configuration,通過中間
的按鈕,將 Sonatype Releases 從 Available Repositories 移動到
Ordered Group Repositories
? ?
? ?
? ?
注意:倉庫組中的倉庫順序直接決定了構件的下載順序
? ?
建議:把代理倉庫放在后面
? ?
? ?
? ?
? ?
14、開啟遠程索引:為了更好的使用 Nexus 私服的搜索,需要
將所有代理倉庫的遠程索引下載下來
? ?
(1)依次選擇代理倉庫,點擊 Configuration,將 Download
Remote Indexes 設置為 true
? ?
? ?
? ?
? ?
(2)依次選擇代理倉庫,右鍵->Repair Index
? ?
? ?
? ?
注:
? ?
Repair Index 和 Update Index 的區別:
? ?
前者是從頭開始重建所有索引,后者則是對增量索引進行更新
? ?
? ?
參考鏈接:
? ?
https://support.sonatype.com/hc/en-us/articles/213465468-What-do-all-of-the-search-index-related-scheduled-tasks-do-and-when-should-I-schedule-them
? ?
? ?
? ?
? ?
15、有了索引,就可以在左側導航欄的搜索框處進行搜索了
? ?
? ?
? ?
? ?
? ?
?
參考鏈接:
? ?
參考鏈接1,參考鏈接2,參考鏈接3
? ?
? ?
? ?
? ?
? ?
? ?
? ?
? ?
? ?
? ?
【made by siwuxie095】
轉載于:https://www.cnblogs.com/siwuxie095/p/7587971.html
總結
- 上一篇: Java基础——注解
- 下一篇: Android ---------高德卫