一、nexus3安裝
首先我們需要準備一個CentOS服務器,並且具備root權限。
1、下載nexus3安裝包
wget https://download.sonatype.com/nexus/3/nexus-3.35.0-03-unix.tar.gz
2、解壓安裝包
tar -zxvf nexus-3.35.0-03-unix.tar.gz -C /opt/
3、修改nexus配置文件
cd /opt/nexus-3.35.0-03/etc/
vim nexus.properties
# 修改以下配置項
# 端口
application-port=8081
nexus-edition=nexus-pro-edition
nexus-edition-subscription-status-url=https://support.sonatype.com/subscription/rest/v1/status
nexus-url=https://your-nexus-domain:8081/
# 保存退出
:wq
4、啟動nexus
cd /opt/nexus-3.35.0-03/bin/
./nexus start
5、訪問nexus
在瀏覽器中輸入http://服務器ip地址:8081,即可訪問到nexus
二、nexus3倉庫管理
1、創建maven倉庫
在nexus中創建maven倉庫,用於存放我們自己的應用程序jar包
步驟如下:
在nexus界面中點擊左側“Repositories”,然後點擊右上角“Create repository”按鈕,選擇“Maven2(hosted)”
填寫相應的信息,最後點擊“Create repository”按鈕即可
2、上傳jar包到倉庫
在nexus界面中點擊左側“Components”,然後點擊右上角“Upload component”按鈕,選擇要上傳的jar包即可
3、使用nexus管理自己的maven倉庫
在項目的pom.xml中增加以下配置,讓maven使用nexus中的倉庫
<repositories>
<repository>
<id>nexus</id>
<url>http://server:8081/repository/maven-public/</url>
</repository>
</repositories>
三、nexus3安全管理
1、設置管理員賬號密碼
在nexus界面中點擊左側“Security”,然後點擊右側“Users”
選擇“admin”,在編輯頁面中修改密碼即可
2、創建用戶組
在nexus界面中點擊左側“Security”,然後點擊右側“Roles”
選擇“Create Role”,填寫相應的信息,然後添加需要該組權限的用戶
3、設置maven倉庫訪問權限
在nexus界面中點擊左側“Repositories”,選擇相應的倉庫
在下方“Repository target”窗口中選擇“Security”選項卡
增加需要訪問該倉庫的用戶組即可
四、nexus3倉庫代理
1、創建代理倉庫
在nexus界面中點擊左側“Repositories”,點擊右上角“Create Repository”,選擇“Maven2(proxy)”
填寫相應信息,選擇需要代理的遠程倉庫
2、使用代理倉庫
在項目的pom.xml中增加以下配置,讓maven使用代理倉庫
<repositories>
<repository>
<id>nexus</id>
<url>http://server:8081/repository/maven-public/</url>
</repository>
</repositories>
在nexus界面中選擇左側“Repositories”,點擊右側“Rebuild index”,等待nexus重新索引遠程代理倉庫即可
五、nexus3倉庫部署
1、創建docker倉庫
在nexus界面中點擊左側“Repositories”,選擇“Create Repository”
選擇“Docker(hosted)”,填寫相應的信息即可
2、推送docker鏡像到倉庫
# 登錄到nexus倉庫
docker login --username=admin --password=123456 registry.nexus.com:8081
# 構建docker鏡像,並命名為registry.nexus.com:8081/myimage:1.0
docker build -t registry.nexus.com:8081/myimage:1.0 .
# 推送鏡像到nexus倉庫
docker push registry.nexus.com:8081/myimage:1.0
3、使用部署的docker鏡像
在其他機器上使用該鏡像時,需要在該機器上登錄nexus倉庫並拉取相應的鏡像
docker login --username=admin --password=123456 registry.nexus.com:8081
docker pull registry.nexus.com:8081/myimage:1.0
以上是nexus3使用的基本內容,希望對您有所幫助。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/290767.html