本文是針對 Sonatype Nexus Repository OSS MacOS 綠色版的安裝指引乍钻。
官方最新版下載地址為:https://www.sonatype.com/nexus-repository-oss。
歷史版本下載地址為:https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3
當(dāng)前(2020-02-02)最新版為 3.20.1-01铭腕,MacOS 版的直接下載地址為:https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.20.1-01-mac.tgz
官網(wǎng)下載速度在國內(nèi)非常的慢银择,已下載緩存到網(wǎng)盤: https://pan.baidu.com/s/1QeW-RH5YtV8MV3gkDqYKVg 提取碼: v2mi
。
一)nexus 安裝步驟
-
解壓下載的
nexus-3.20.1-01-mac.tgz
到目錄/path/to/nexus/
累舷,得到如下目錄結(jié)構(gòu):/path/to/nexus/ |--nexus-3.20.1-01 | |--bin/ | | |--contrib/ | | |--nexus | | |--nexus.rc | | |--nexus.vmoptions | |--deploy/... | |--etc/... | |--lib/... | |--public/... | |--system/... | |--... |--sonatype-work/ | |--nexus3/ | | |--log/ | | |--orient/ | | | |--plugins/ | | | | |--studio.zip | | |--tmp/ | | |--clean_cache
目錄
/path/to/nexus/
需根據(jù)自身需要設(shè)置為實(shí)際的磁盤目錄浩考,下同。 -
在與
nexus-3.20.1-01
同級目錄下創(chuàng)建軟鏈接nexus-latest
并鏈接到此目錄以方便日后的升級$ ln -s /path/to/nexus/nexus-3.20.1-01 /path/to/nexus/nexus-latest
-
將
/path/to/nexus/nexus-latest/bin
添加到系統(tǒng)環(huán)境變量PATH
內(nèi)# 執(zhí)行如下命令修改 ~/.profile 文件 $ vi ~/.profile # 往 ~/.profile 文件添加如下兩行 export NEXUS_HOME=/path/to/nexus/nexus-latest PATH=$PATH:$NEXUS_HOME/bin # 執(zhí)行如下命令使添加到 ~/.profile 文件的配置生效 $ source ~/.profile
-
執(zhí)行
nexus start
啟動 nexus 服務(wù)$ nexus start Starting nexus
執(zhí)行
nexus help
命令可查看可用的命令清單:$ nexus help Usage: /path/to/nexus/nexus-latest/bin/nexus {start|stop|run|run-redirect|status|restart|force-reload}
啟動后訪問 http://localhost:8081 打開 nexus 主頁:
nexus-main-page.png點(diǎn)擊右上角的
Sign in
可以 admin 賬號登陸進(jìn)行相關(guān)配置被盈,首次點(diǎn)擊Sign in
析孽,會提示管理員 admin 賬號的初始密碼已自動生成在文件sonatype-work/nexus3/admin.password
內(nèi),以此密碼登陸后會繼續(xù)彈出對話框要求修改為新的密碼:
nexus-change-password.png之后會再彈出一個對話框設(shè)置是否允許匿名瀏覽只怎、下載倉庫中的包:(建議勾選)
nexus-enable-anonymous-access.png -
添加第三方 maven 倉庫的代理配置到 nexus
以管理員賬號 admin 登陸 nexus袜瞬,打開 Repositories 配置界面,
默認(rèn)情況下 nexus 僅配置了 maven 中心倉庫的代理 maven-central身堡。
maven-public 為所有代理倉庫的自定義匯集邓尤,用于控制 nexus 按特定順序分別從配置的第三方倉庫中下載依賴包。
按照個人習(xí)慣贴谎,我一共配置了如下幾個第三方 maven 倉庫的代理配置:- maven-central > https://repo1.maven.org/maven2/ - 內(nèi)置配置汞扎,國內(nèi)使用速度慢
- maven-jcenter > https://jcenter.bintray.com - 國內(nèi)使用速度慢
- maven-aliyun > https://maven.aliyun.com/nexus/content/groups/public/ - 國內(nèi)使用速度快
- 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詳細(xì)可參考官方配置文檔 《Repository Management》
-
【可選配置】自定義 nexus 相關(guān)配置參數(shù)(特殊情況才需要修改,一般不建議修改):
創(chuàng)建文件/path/to/nexus/sonatype-work/nexus3/etc/nexus.properties
赴精,添加如下配置:# 自定義 web 訪問端口 application-port=8081 # 自定義 Web 上下文路徑 (以 / 開頭佩捞,不要以 / 結(jié)尾) nexus-context-path=/
參考
/path/to/nexus/nexus-latest/etc/nexus-default.properties
文件內(nèi)的配置參數(shù)進(jìn)行配置即可。如果要遷移數(shù)據(jù)目錄
sonatype-work/nexus3
到其它地方蕾哟,需要修改文件nexus-latest/bin/nexus.vmoptions
一忱,這個不建議修改。注:配置文件修改后必須重新啟動 nexus 服務(wù)才能生效:
$ nexus restart
-
【可選配置】升級 nexus
- 執(zhí)行
nexus stop
命令停止當(dāng)前已啟動的 nexus 服務(wù)$ nexus stop Shutting down nexus Stopped.
- 下載最新版的 nexus 包谭确,解壓后僅保留
nexus-3.{new-version}
目錄帘营,并移動到/path/to/nexus/
目錄下,然后重新創(chuàng)建軟鏈接 nexus-latest逐哈,指向新版本的 nexus 目錄即可:$ cd /path/to/nexus $ rm nexus-latest $ ln -s /path/to/nexus/nexus-3.{new-version} /path/to/nexus/nexus-latest
- 執(zhí)行
nexus start
重新啟動 nexus 服務(wù)芬迄。
以上升級方法適用于從 nexus-3.1.0+ 升級到 nexus3 的最新版本,官方文檔為《Upgrading Nexus Repository Manager 3.1.0 and Newer》
- 執(zhí)行
較低版本 nexus3 的默認(rèn)管理員賬號是 admin
昂秃,密碼是 admin123
(如 nexus-3.14)禀梳,如果從較低版本升級到當(dāng)前最新版(如 nexus-3.20)杜窄,使用 admin 賬號首次登陸后,系統(tǒng)會提示你更新密碼一次及設(shè)置是否允許匿名瀏覽算途、下載倉庫中的包塞耕。類似于上面步驟 4 的相關(guān)截圖。
二)maven 相關(guān)配置
- 配置 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>
詳細(xì)可參考官方指引文檔 《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 私服扫外。
- 修改