本文是針對 Sonatype Nexus Repository OSS Windows 綠色版的安裝指引封断。
注:Nexus Repository OSS 只支持 64 位的 Windows 操作系統(tǒng)牺氨,32 位的不支持影晓。
官方最新版下載地址為:https://www.sonatype.com/nexus-repository-oss。
歷史版本下載地址為:https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3
當前(2020-02-02)最新版為 3.20.1-01奸晴,Windows 版的直接下載地址為:https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.20.1-01-win64.zip
官網下載速度在國內非常的慢魁兼,已下載緩存到網盤: https://pan.baidu.com/s/1QeW-RH5YtV8MV3gkDqYKVg 提取碼: v2mi
氯迂。
一)nexus 安裝步驟
-
解壓下載的
nexus-3.20.1-01-win64.zip
到目錄D:\path\to\nexus\
屯碴,得到如下目錄結構:D:\path\to\nexus\ |--nexus-3.20.1-01 | |--bin\ | | |--contrib\... | | |--nexus.exe | | |--nexus.vmoptions | |--deploy\... | |--etc\... | |--jre\... | |--lib\... | |--public\... | |--system\... | |--... |--sonatype-work\ | |--nexus3\ | | |--log\ | | |--orient\ | | | |--plugins\ | | | | |--studio.zip | | |--tmp\ | | |--clean_cache
目錄
D:\path\to\nexus\
需根據自身需要設置為實際的磁盤目錄描睦,下同。 -
在與
nexus-3.20.1-01
同級目錄下創(chuàng)建軟鏈接nexus-latest
并鏈接到此目錄以方便日后的升級> cd D:\path\to\nexus\ > mklink /D nexus-latest nexus-3.20.1-01 為 nexus-latest <<===>> nexus-3.20.1-01 創(chuàng)建的符號鏈接
mklink 命令需要在以管理員身份打開的 CMD 中才支持导而。
-
將
D:\path\to\nexus\nexus-latest\bin
添加到系統(tǒng)環(huán)境變量Path
內這樣才能保證在命令行中直接使用 nexus 命令。
-
執(zhí)行
nexus /start
啟動 nexus 服務> nexus /start Starting nexus
執(zhí)行
nexus /?
命令可查看可用的命令清單:> nexus /? Usage: D:\path\to\nexus\nexus-latest\bin\nexus {start|stop|run|run-redirect|status|restart|force-reload}
啟動后訪問 http://localhost:8081 打開 nexus 主頁:
nexus-main-page.png點擊右上角的
Sign in
可以 admin 賬號登陸進行相關配置隔崎,首次點擊Sign in
今艺,會提示管理員 admin 賬號的初始密碼已自動生成在文件sonatype-work/nexus3/admin.password
內,以此密碼登陸后會繼續(xù)彈出對話框要求修改為新的密碼:
nexus-change-password.png之后會再彈出一個對話框設置是否允許匿名瀏覽爵卒、下載倉庫中的包:(建議勾選)
nexus-enable-anonymous-access.png -
添加第三方 maven 倉庫的代理配置到 nexus
以管理員賬號 admin 登陸 nexus虚缎,打開 Repositories 配置界面,
默認情況下 nexus 僅配置了 maven 中心倉庫的代理 maven-central钓株。
maven-public 為所有代理倉庫的自定義匯集实牡,用于控制 nexus 按特定順序分別從配置的第三方倉庫中下載依賴包。
按照個人習慣轴合,我一共配置了如下幾個第三方 maven 倉庫的代理配置:- maven-central > https://repo1.maven.org/maven2/ - 內置配置创坞,國內使用速度慢
- maven-jcenter > https://jcenter.bintray.com - 國內使用速度慢
- maven-aliyun > https://maven.aliyun.com/nexus/content/groups/public/ - 國內使用速度快
- maven-spring-milestone > https://repo.spring.io/milestone - spring的里程碑版本專用
- maven-activiti > https://maven.alfresco.com/nexus/content/repositories/activiti/ - 早期的 activiti 5.9 專用
nexus-repositories.pngnexus-maven-public.png詳細可參考官方配置文檔 《Repository Management》
-
【可選配置】如果要安裝為系統(tǒng)服務,以管理員身份執(zhí)行
nexus /install
即可受葛。卸載服務則執(zhí)行
nexus /uninstall
-
【可選配置】自定義 nexus 相關配置參數(特殊情況才需要修改题涨,一般不建議修改):
創(chuàng)建文件D:\path\to\nexus\sonatype-work\nexus3\etc\nexus.properties
,添加如下配置:# 自定義 web 訪問端口 application-port=8081 # 自定義 Web 上下文路徑 (以 / 開頭总滩,不要以 / 結尾) nexus-context-path=/
參考
D:\path\to\nexus\nexus-latest\etc\nexus-default.properties
文件內的配置參數進行配置即可纲堵。如果要遷移數據目錄
sonatype-work\nexus3
到其它地方,需要修改文件nexus-latest\bin\nexus.vmoptions
闰渔,這個不建議修改席函。注:配置文件修改后必須重新啟動 nexus 服務才能生效:
> nexus /restart
-
【可選配置】升級 nexus
- 執(zhí)行
nexus /stop
命令停止當前已啟動的 nexus 服務:> nexus /stop Shutting down nexus Stopped.
- 下載最新版的 nexus 包,解壓后僅保留
nexus-3.{new-version}
目錄冈涧,并移動到D:\path\to\nexus\
目錄下茂附,然后重新創(chuàng)建軟鏈接 nexus-latest蝌以,指向新版本的 nexus 目錄即可:> cd D:\path\to\nexus\ > md nexus-latest > mklink /D nexus-latest nexus-3.{new-version}
- 執(zhí)行
nexus /start
重新啟動 nexus 服務。
以上升級方法適用于從 nexus-3.1.0+ 升級到 nexus3 的最新版本何之,官方文檔為《Upgrading Nexus Repository Manager 3.1.0 and Newer》
- 執(zhí)行
較低版本 nexus3 的默認管理員賬號是 admin
跟畅,密碼是 admin123
(如 nexus-3.14),如果從較低版本升級到當前最新版(如 nexus-3.20)溶推,使用 admin 賬號首次登陸后徊件,系統(tǒng)會提示你更新密碼一次及設置是否允許匿名瀏覽、下載倉庫中的包蒜危。類似于上面步驟 4 的相關截圖虱痕。
二)maven 相關配置
- 配置 maven 使用 nexus 代理所有依賴的下載:
修改 maven 的用戶配置文件~/.m2/settings.xml
:<settings> <mirrors> <mirror> <!--This sends everything else to maven-public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <!-- http://[ip]:[port][/nexus-context-path]/repository/[public-repository-name] --> <url>http://localhost:8081/repository/maven-public</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!-- Enable snapshots for the built in central repo to direct all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
詳細可參考官方指引文檔 《Proxying Maven and npm Quick Start》
- 【可選配置】配置將 maven 項目打包發(fā)布到此 nexus 私服:
- 修改
~/.m2/settings.xml
文件,添加如下配置:<settings> ... <servers> <!-- account and password for deploy to nexus --> <server> <id>lan</id> <username>admin</username> <password>admin123</password> </server> </servers> <profiles> <profile> <id>lan</id> <properties> <lan-release-url>http://localhost:8081/repository/maven-releases</lan-release-url> <lan-snapshot-url>http://localhost:8081/repository/maven-snapshots</lan-snapshot-url> </properties> </profile> </profiles> </settings>
- 修改 maven 項目的
pom.xml
文件辐赞,添加如下配置:<project> <profiles> <!-- configuration for deploy to nexus repository --> <profile> <id>lan</id> <distributionManagement> <repository> <id>lan</id> <url>${lan-release-url}</url> </repository> <snapshotRepository> <id>lan</id> <url>${lan-snapshot-url}</url> </snapshotRepository> </distributionManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> </plugin> </plugins> </build> </profile> </profiles> </project>
命令行執(zhí)行
mvn clean deploy -P lan
即可將項目打包發(fā)布到 nexus 私服部翘。
- 修改