maven 私服 nexus3 配置,踩坑 , Ready to Connet

maven 私服 nexus3 配置,使用,踩坑(歡迎留言提意見,共同進步)

繼續上文docker-compose 搭建 maven 私服 nexus3 筆記


新增一個阿里的倉庫
在這裏插入圖片描述
類型
在這裏插入圖片描述
起個名字,配置上阿里雲的地址,保存
https://maven.aliyun.com/repository/public
在這裏插入圖片描述
然後就添加好了
在這裏插入圖片描述
這裏簡單說一下maven倉庫組的概念

Nexus包含多種倉庫概念、包括主要的宿主倉庫、代理倉庫、倉庫組等。不同倉庫提供不同配置、服務
四種倉庫類型:hosted(宿主倉庫)、proxy(代理倉庫)、group(倉庫組)、irtual(虛擬倉庫)。每個倉庫的格式爲maven2或者maven1、此外倉庫還有個屬性爲Policy(策略)、表示該倉庫是發佈(Release)版本倉庫、還是快照(Snapshot)版本。最後兩列是倉庫的狀態和路徑

個人理解看下圖
在這裏插入圖片描述
我們把aliyun的倉庫添加到這個組裏。

但是這個 Ready to Connect 狀態不能用,Remote Available 這纔是可用的
在這裏插入圖片描述
我這裏能用的這個倉庫是阿里雲的公共倉庫,也是我試了很多個唯一一個能自動下載好的,其他的新增倉庫都是一直處於 Ready to Connet 狀態,
阿里雲的公共倉庫 https://maven.aliyun.com/repository/public
新增阿里雲倉庫後也是 Ready to Connet 狀態,只要你網絡狀態良好,過一段時間,它就自己下載好了,時間可能會比較長
其他倉庫怎麼讓它可用呢,我們要用到離線下載,

查資料發現大部分都是這麼說的,但是地址都不能用
在這裏插入圖片描述
它給的地址都是不能用的
在這裏插入圖片描述
後來找到的問題
在這裏插入圖片描述
英語好的自己看一下,其實原因這個就是原來網站走http協議的,現在不支持了,現在走https協議了,下載地址如下
https://repo.maven.apache.org/maven2/.index/ 找到需要下載的索引文件。
如:https://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.gz
還有
https://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時就表示已同步完成了。


按步驟展示
下載好文件
在這裏插入圖片描述
要上傳到的位置

# 我的是docker數據卷映射的路徑
[root@MiWiFi-R3P-srv default] pwd
/usr/local/docker/nexus/data/blobs/default
[root@MiWiFi-R3P-srv default] ls
7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-deletions.index  7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-metrics.properties  content  metadata.properties

# 上傳文件後
[root@MiWiFi-R3P-srv default] ll
總用量 840860
-rw-r--r--. 1  200  200      4096 4月   4 00:03 7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-deletions.index
-rw-r--r--. 1  200  200        84 4月   4 00:03 7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-metrics.properties
drwxr-xr-x. 2  200  200         6 4月   4 00:03 content
-rw-r--r--. 1  200  200        72 4月   4 00:03 metadata.properties
-rw-r--r--. 1 root root 861021613 4月   4 02:52 nexus-maven-repository-index.gz
-rw-r--r--. 1 root root      1130 4月   4 02:52 nexus-maven-repository-index.properties.txt

# 解壓 nexus-maven-repository-index.gz
[root@MiWiFi-R3P-srv default] gzip nexus-maven-repository-index.gz -d
[root@MiWiFi-R3P-srv default] ll -h
總用量 5.8G
-rw-r--r--. 1  200  200 4.0K 4月   4 00:03 7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-deletions.index
-rw-r--r--. 1  200  200   84 4月   4 00:03 7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-metrics.properties
drwxr-xr-x. 2  200  200    6 4月   4 00:03 content
-rw-r--r--. 1  200  200   72 4月   4 00:03 metadata.properties
-rw-r--r--. 1 root root 5.8G 4月   4 02:52 nexus-maven-repository-index
-rw-r--r--. 1 root root 1.2K 4月   4 02:52 nexus-maven-repository-index.properties.txt
# 文件真大,將近6G
# 改一下用戶和組跟其他文件一直
[root@MiWiFi-R3P-srv default] chown 200:200 nexus-maven-repository-index.properties.txt
[root@MiWiFi-R3P-srv default] chown 200:200 nexus-maven-repository-index
# 查看一下
[root@MiWiFi-R3P-srv default] ll
總用量 6055324
-rw-r--r--. 1 200 200       4096 4月   4 00:03 7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-deletions.index
-rw-r--r--. 1 200 200         84 4月   4 00:03 7C248FA1-C573123B-BA7706F9-7F826828-08F9CBF9-metrics.properties
drwxr-xr-x. 2 200 200          6 4月   4 00:03 content
-rw-r--r--. 1 200 200         72 4月   4 00:03 metadata.properties
-rw-r--r--. 1 200 200 6200633318 4月   4 02:52 nexus-maven-repository-index
-rw-r--r--. 1 200 200       1130 4月   4 02:52 nexus-maven-repository-index.properties.txt

# 權限不夠的話還可以往大了放開
[root@MiWiFi-R3P-srv default] chmod 777 nexus-maven-repository-index
[root@MiWiFi-R3P-srv default] chmod 777 nexus-maven-repository-index.properties.txt 

#重啓一下容器
[root@MiWiFi-R3P-srv default] docker ps
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                  NAMES
beb0f1825f10        192.168.31.185:5000/sonatype/nexus3   "sh -c ${SONATYPE_..."   3 hours ago         Up 14 minutes       0.0.0.0:80->8081/tcp   nexus3
[root@MiWiFi-R3P-srv default] docker restart beb0f1825f10
beb0f1825f10

果然可以了
在這裏插入圖片描述
我發現能用的倉庫狀態有時也不對,我下面的兩個倉庫都是能用的,但是狀態不對。。。
在這裏插入圖片描述


接下來出,在項目中怎樣使用maven 私服,下載pom文件依賴,打包部署到私服,怎麼從私服下載自己寫的jar,怎麼上傳三方jar包,內容比較簡單,網上到處都是教程,個人感覺這編涉及到的內容網上資料比較少

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章