第3篇說明了倉庫的分類,其中講到了私服,私服的好處很明顯,這篇繼續跟着公衆號學習私服的搭建、倉庫管理、構件部署等知識。web
Sonatype Nexus:spring
這裏學習nexus的服務搭建,JFrog的後續再寫。vim
下載,下載安裝包到/opt/nexus
目錄緩存
[root@john nexus]# pwd /opt/nexus [root@john nexus]# ll total 132256 -rw-r--r-- 1 root root 135426386 Nov 14 00:31 latest-unix.tar.gz
解壓服務器
[root@john nexus]# tar -zxvf latest-unix.tar.gz [root@john nexus]# ll total 132264 -rw-r--r-- 1 root root 135426386 Nov 14 00:31 latest-unix.tar.gz drwxr-xr-x 9 root root 4096 Dec 15 15:50 nexus-3.19.1-01 drwxr-xr-x 3 root root 4096 Dec 15 15:50 sonatype-work
啓動服務maven
[root@john /]# cd /opt/nexus/nexus-3.19.1-01/bin/ [root@john bin]# ./nexus start
開放端口tcp
編輯iptables文件學習
[root@john bin]# vim /etc/sysconfig/iptables
打開nexus服務默認端口8081ui
# 添加一行內容 -A INPUT -p tcp -m state --state NEW -m tcp --dport 8081 -j ACCEPT
重啓防火牆阿里雲
[root@john bin]# systemctl restart iptables.service
訪問nexus服務
http://nexus服務器ip:8081
登陸:
admin
/opt/nexus/sonatype-work/nexus3/admin.password
文件中。登陸nexus後,發現nexus內置了三種類型的倉庫。
建立代理倉庫,代理aliyun倉庫。
Name
: maven-aliyunMaven2 > Version Policy
:表示該倉庫爲發佈版本(Release)倉庫仍是快照(Snapshot)版本倉庫,這裏選擇Release。Proxy > Remote storage
:阿里雲倉庫地址(https://maven.aliyun.com/repository/public
,該地址是個倉庫組,具體可查看https://maven.aliyun.com/mvn/view)建立宿主倉庫
Name
: maven-test-releasesMaven2 > Version Policy
:這裏選擇Relase,代表該倉庫爲發佈版本倉庫。部署構件:
什麼是倉庫組?
爲何使用倉庫組?
組內倉庫順序
在項目pom文件配置倉庫(${project.basedir}/pom.xml
)
<repositories> <repository> <id>maven-nexus</id> <url>http://nexus服務ip:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
在用戶配置中配置倉庫認證信息(~/.m2/setting.xml
)
<server> <!-- 注意:這裏id的值和`pom.xml中repository->id`的值一致 --> <id>maven-nexus</id> <username>repouser</username> <password>repopwd</password> </server>
構件下載驗證
org.springframework:spring-web:5.2.1.RELEASE
構件。mvn compile
查看命令執行結果
[INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.john.example:demo1 >----------------------- [INFO] Building HellMaven 1.0 [INFO] --------------------------------[ jar ]--------------------------------- Downloading from maven-nexus: http://nexus服務ip:8081/repository/maven-public/org/springframework/spring-web/5.2.1.RELEASE/spring-web-5.2.1.RELEASE.pom Downloaded from maven-nexus: http://nexus服務ip:8081/repository/maven-public/org/springframework/spring-web/5.2.1.RELEASE/spring-web-5.2.1.RELEASE.pom (1.9 kB at 15 kB/s) ... [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo1 --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo1 --- [INFO] Nothing to compile - all classes are up to date [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 26.582 s [INFO] Finished at: 2019-12-17T23:30:09+08:00 [INFO] ------------------------------------------------------------------------
修改用戶配置文件(~/.m2/setting.xml
),配置鏡像
<mirror> <id>mirror-nexus</id> <mirrorOf>*</mirrorOf> <name>nexus鏡像</name> <url>http://nexus服務ip:8081/repository/maven-public/</url> </mirror>
配置倉庫認證信息(~/.m2/setting.xml
)。
<server> <!-- 注意:這裏id的值和`pom.xml中repository->id`的值一致 --> <id>mirror-nexus</id> <username>repouser</username> <password>repopwd</password> </server>
構件下載驗證。
org.springframework:spring-web:5.2.1.RELEASE
構件。mvn compile
查看命令執行結果
[INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.john.example:demo1 >----------------------- [INFO] Building HellMaven 1.0 [INFO] --------------------------------[ jar ]--------------------------------- Downloading from mirror-nexus: http://nexus服務ip:8081/repository/maven-public/org/springframework/spring-web/5.2.1.RELEASE/spring-web-5.2.1.RELEASE.pom Downloaded from mirror-nexus: http://nexus服務ip:8081/repository/maven-public/org/springframework/spring-web/5.2.1.RELEASE/spring-web-5.2.1.RELEASE.pom (1.9 kB at 16 kB/s) [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo1 --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo1 --- [INFO] Nothing to compile - all classes are up to date [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 26.202 s [INFO] Finished at: 2019-12-17T23:49:22+08:00 [INFO] ------------------------------------------------------------------------
快照版本構件
發佈版本構件
項目pom配置(${project.basedir}/pom.xml
)
<distributionManagement> <!-- Release 倉庫 --> <repository> <id>nexus-releases</id> <name>nexus私服中宿主倉庫->存放/下載發佈版本的構件</name> <url>http://nexus服務ip:8081/repository/maven-releases/</url> </repository> <!-- Snapshot 倉庫 --> <snapshotRepository> <id>nexus-snapshots</id> <name>nexus私服中宿主倉庫->存放/下載快照版本的構件</name> <url>http://nexus服務ip:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
配置倉庫認證信息(~/.m2/setting.xml
)
<server> <!-- 注意: `id`的值和pom.xml中的`distributionManagement->repository->id`的值一致。--> <id>nexus-releases</id> <username>repouser</username> <password>repopwd</password> </server> <server> <!-- 注意: `id`的值和pom.xml中的`distributionManagement->snapshotRepository->id`的值一致。--> <id>nexus-snapshots</id> <username>repouser</username> <password>repopwd</password> </server>
部署項目(mvn deploy
)
<version>1.0-SNAPSHOT</version>
: Uploaded to nexus-snapshots。<version>1.0</version>
: Uploaded to nexus-releases。注意