1.簡介
近期公司需要搭建jenkins自動化構建部署,需要搭建nexus私服環境,以便項目組的成員開發效率,以及打包發佈,這樣既節省了網絡帶寬也會加速項目搭建的進程, 當然前提條件就是你的私服中擁有項目所需的所有構件。
2.NEXUS下載(最新版3.1)
3.安裝
解壓nexus-3.1.0-04-win64.zip,
得到以下目錄
1.nexus-3.1.0-04 nexus程序
2.sonatype-work nexus工作目錄
(數據,備份nexus的時候可以備份這個文件夾)
nexus默認端口是8081
可以在nexus-3.1.0-04\etc\nexus-default.properties修改
配置系統環境變量
右擊我的電腦-屬性-高級-環境變量-系統變量區域(點擊新增)
4.啓動
cd nexus-3.1.0-04\bin目錄下
常用命令
1.nexus.exe /install 安裝nexus爲系統服務
2.nexus.exe /uninstall 卸載nexus爲系統服務
3.nexus.exe /start 啓動nexus服務
4.nexus.exe /stop 停止nexus服務
啓動後訪問: http://127.0.0.1:8081/ 即可
新版沒用了項目名/nexus
默認登錄: admin/admin123
登錄之後纔可以配置nexus私服
5.maven以及配置使用
no 廢話,直接上配置
1. 先在maven目錄/conf/setting.xml的servers添加配置:
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
- 工程中配置,發佈/私服工廠
<!-- 配置私服工廠 -->
<repositories>
<repository>
<id>nexus</id>
<url>http://ip:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://ip:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- 配置發佈到私服 -->
<distributionManagement>
<repository>
<id>nexus</id>
<name>Nexus Release Repository</name>
<url>http://ip:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Nexus Snapshot Repository</name>
<url>http://ip:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
補充技巧
1.發佈自定義jar到Nexus3
nexus 3.1版本去除了本地上傳發布自定義jar
解決方案:
使用命令行進行本地jar上傳
語法:
mvn deploy:deploy-file
-DgroupId=<group-id>\
-DartifactId=<artifact-id>\
-Dversion=<version>\
-Dpackaging=<type-of-packaging>\
-Dfile=<path-to-file>\
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml>\
-Durl=<url-of-the-repository-to-deploy>
例子:
mvn deploy:deploy-file -DgroupId=com.ojdbc7
-DartifactId=ojdbc7 -Dversion=1.0 -Dfile=ojdbc7.jar
-DrepositoryId=nexus -Durl=http://ip:prot/repository/maven-releases/
DrepositoryId=nexus指的是setting配置的驗證的id
2.離線索引
由於使用代理之前需要先下索引,從國外下載的話非常的慢。可以翻牆或者可以使用常用的下載工具,下載後再上傳到nexus服務器即可。
從http://repo.maven.apache.org/maven2/.index/ 找到需要下載的索引文件。
如:http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.gz
還有
http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.properties
將其上傳到nexus服務器存儲數據的倉庫中,對應web管理界面上就是Repository/Blob Stores/倉庫名。
在我的服務器上地址是在/var/opt/nexus-data/blobs/倉庫名。
在倉庫名目錄下創建.index目錄,然後將下載的文件copy到該目錄中,之後很快就同步好了,同步完成狀態可通過查看web管理界面倉庫狀態欄,當出現Online - Remote Aviailable時就表示已同步完成了。