搭建環(huán)境
- 平臺(tái):阿里云
- 系統(tǒng):CentOS 7
- 應(yīng)用:Nexus 2.x
Nexus 私服的安裝
Nexus 下載
Nexus 安裝
1. 遠(yuǎn)程登錄阿里云服務(wù)器
2. 將下載好的壓縮文件上傳到服務(wù)器的 /opt 目錄下
3. 在 /usr/local 目錄下創(chuàng)建 nexus 目錄
mkdir /usr/local/nexus
4. 把壓縮文件解壓到 /usr/local/nexus 目錄下
tar -zxvf /opt/nexus-2.14.11-01-bundle.tar.gz -C /usr/local/nexus
解壓完后在 /usr/local/nexus 目錄下會(huì)有兩個(gè)文件夾:nexus-2.14.11-01、sonatype-work。
5. 查看 Nexus 默認(rèn)配置信息
vim /usr/local/nexus/nexus-2.14.11-01/conf/nexus.properties

Nexus配置信息.png
6. 開放8081端口
- 阿里云:控制臺(tái)> 云服務(wù)器ECS> 實(shí)例> 安全組> 配置規(guī)則> 添加安全組規(guī)范
7. 修改 Nexus 運(yùn)行用戶
vim /usr/local/nexus/nexus-2.14.11-01/bin/nexus

修改用戶.png
不推薦用 root 用戶
8. 測(cè)試
- 啟動(dòng)私服

啟動(dòng)私服.png
- 查看狀態(tài)

查看狀態(tài).png
-
關(guān)閉私服
關(guān)閉私服.png
9. 訪問(wèn)頁(yè)面安裝完成

登錄成功.png
Nexus 頁(yè)面管理
1. 頁(yè)面登錄
賬號(hào):用戶名
密碼:用戶名 + 123
例:默認(rèn)賬戶:admin 密碼:admin123
2. 查看倉(cāng)庫(kù)
Views/Repositories
? Repositories

倉(cāng)庫(kù).png
3. 代理倉(cāng)庫(kù)配置

代理倉(cāng)庫(kù)配置.png
其他代理倉(cāng)庫(kù)操作相同
Nexus 私服的應(yīng)用
1. 修改 settings.xml 文件
-
在
<servers>里添加<server> <id>nexus-releases</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>nexus-snapshots</id> <username>deployment</username> <password>deployment123</password> </server>一個(gè)是發(fā)布一個(gè)是快照,用的都是默認(rèn)的部署賬號(hào)。
-
在
<profiles>里添加<profile> <id>nexusMaven</id> <activation> <activeByDeffault>false </activeByDeffault> <jdk>1.8</jdk> </activation> <repositories> <repository> <id>nexus</id> <url>http://自己服務(wù)器IP地址:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshost> <enabled>true</enabled> </snapshost> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://自己服務(wù)器IP地址:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshost> <enabled>true</enabled> </snapshost> </pluginRepository> </pluginRepositories> </profile>id中的名字可以隨便起,不一樣即可。- 添加
<activeProfiles>
<activeProfiles> <activeProfile>nexusMaven</activeProfile> </activeProfiles><activeProfile>里面填的是上面<profile>標(biāo)簽里的<id>標(biāo)簽屬性值 - 添加
2. 創(chuàng)建 Maven 項(xiàng)目
3. 配置 Mavenue 項(xiàng)目的 pom.xml 文件
-
倉(cāng)庫(kù)分配管理
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Releases Repository</name> <url>http://自己服務(wù)器IP地址:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus snapshots Repository</name> <url>http://自己服務(wù)器IP地址:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>這里面2個(gè)
<id>標(biāo)簽里的值和之前settings.xml里<servers>標(biāo)簽里的配置一樣。做到這一步就已經(jīng)能夠從私服下載了。
-
配置上傳源代碼
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin>沒(méi)有這一步也可上傳,但都是
.class文件。加上這一步就可以上傳源碼了。
4. 看效果
- 下載

私服下載.png
- 上傳

發(fā)布版本.png

發(fā)布成功.png

成功頁(yè)面.png
因?yàn)樯蟼鞯氖且粋€(gè)WEB項(xiàng)目所以沒(méi)有源碼。
至此基于 Nexus 搭建的 Maven 私服算是初步完成了。
