一、為什么需要搭建mave私服
如果沒有私服,我們所需的所有構件都需要通過maven的中央倉庫和第三方的Maven倉庫下載到本地,而一個團隊中的所有人都重復的從maven倉庫下 載構件無疑加大了倉庫的負載和浪費了外網帶寬,如果網速慢的話,還會影響項目的進程。很多情況下項目的開發都是在內網進行的,連接不到maven倉庫怎么 辦呢?開發的公共構件怎么讓其它項目使用?這個時候我們不得不為自己的團隊搭建屬於自己的maven私服,這樣既節省了網絡帶寬也會加速項目搭建的進程, 當然前提條件就是你的私服中擁有項目所需的所有構件。
二、Nexus下載
下載地址:http://www.sonatype.org/nexus/go
這里使用的是nexus-2.11.2-03的版本
三、解壓下載的Nexus
使用tar命令進行解壓 tar -zxvf nexus-2.11.2-03-bundle.tar.gz,解壓進入到nexus-2.11.3-03中使用使用命令ls,進行查看目錄結構。
bin:二進制執行目錄
conf:配置目錄
lib:包目錄
logs:日志目錄
nexus:web應用目錄
tmp:臨時文件目錄
四、配置當前訪問的端口和用戶
1.進入到/nexus-2.11.2-03/bin目錄下。使用vi命令開打nexus. "vi nexus",增加RUN_AS_USER =ROOT 顯示如圖:
2.配置端口,進入到/nexus-2.11.2-03/bin目錄下,使用VI打開nexus.properties文件。如圖
nexus 是使用jetty容器進行啟動的。默認的端口為8081.若端口沒有被暫用的情況下默認使用8081
五、設置防火牆
如果有啟用防火牆的情況下需要供其他用戶進行訪問的情況下,配置防火牆。
1.對iptables進行編輯,使用vi 命令進行打開。“vi etc/sysconfig/iptables”
2.對iptables 插入 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
3.使用命令重啟防火牆. service iptables restart
五、啟動nexus
進入到nexus的bin目錄下。使用sh命令進行啟動。s
[root@instance-9j07wgiz nexus-2.11.2-03]# cd bin/ [root@instance-9j07wgiz bin]# ls jsw nexus nexus.bat [root@instance-9j07wgiz bin]# pwd /u01/nexus/nexus-2.11.2-03/bin [root@instance-9j07wgiz bin]# sh nexus start
六、在項目中的pom進行修改倉庫。
1、配置jar包倉庫
<repositories> <repository> <id>nexus</id> <name>nexus</name> <url>http://192.168.1.103:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
2、插件配置使用私有maven庫
<pluginRepositories> <pluginRepository> <id>nexus</id> <name>nexus</name> <url>http://192.168.1.103:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>