使用樹莓派搭建Nexus2私服需要的材料有:
- 樹莓派3B+(或者4B)
- 移動硬盤一個
樹莓派相關文章:
- 樹莓派搭建nexus2.x私服(本文)
- 樹莓派搭建視頻監控平台
- 樹莓派視頻監控平台實現錄制歸檔
- 樹莓派實現人臉打卡機
1. 下載nexus2.x安裝包
由於nexus2.x官方的啟動環境並不支持arm架構的樹莓派,所以這里采用tomcat7 + nexus2.x的方式搭建私服。
下載 nexus-2.14.17-01-bundle.tar.gz
下載 apache-tomcat-7.0.104.tar.gz
2. 移除nexus2.x不必要的插件
將下載的nexus-2.14.17-01-bundle.tar.gz
解壓后,會有如下幾個目錄:
bin # nexus各種操作系統的啟動腳本,這里並不支持arm架構
nexus # nexus主應用,使用tomcat + nexus,只需要這部分
logs
lib
conf
...
用tomcat7來跑nexus,只需要nexus這個目錄中的東西,但是由於樹莓派的內存有限,所以這里移除了nexus中沒有用到的插件,比如ldap,nuget,yum等。
下面是我們用不到的插件(這個具體根據自己的需要調整),插件的位置在/nexus/WEN-INF/plugin-repository
這個目錄中。
nexus-analytics-plugin-2.14.17-01
nexus-archetype-plugin-2.14.17-01
nexus-atlas-plugin-2.14.17-01
nexus-capabilities-plugin-2.14.17-01
nexus-crypto-plugin-2.14.17-01
nexus-groovy-plugin-2.14.17-01
nexus-h2-plugin-2.14.17-01
nexus-iq-repository-oss-plugin-2.14.17-01
nexus-kazuki-plugin-2.14.17-01
nexus-ldap-realm-plugin-2.14.17-01
nexus-logging-plugin-2.14.17-01
nexus-lvo-plugin-2.14.17-01
nexus-migrationagent-plugin-2.14.17-01
nexus-nuget-plugin-2.14.17-01
nexus-outreach-plugin-2.14.17-01
nexus-rrb-plugin-2.14.17-01
nexus-ruby-plugin-2.14.17-01
nexus-rutauth-plugin-2.14.17-01
nexus-siesta-plugin-2.14.17-01
nexus-site-repository-plugin-2.14.17-01
nexus-timeline-plugin-2.14.17-01
nexus-wonderland-plugin-2.14.17-01
nexus-yum-repository-plugin-2.14.17-01
3. 修改nexus的工作目錄
默認情況下nexus的工作目錄為${user.home}/sonatype-work/nexus
,由於硬盤是掛載在樹莓派的/mnt/Disk
目錄中,所以這里需要調整一下nexus的工作目錄。
修改/nexus/WEB-INF/classes/plexus.properties
中的nexus-work
配置:
nexus-work=/mnt/Dist/nexus2/sonatype-work/nexus
runtime=${bundleBasedir}
nexus-app=${runtime}
4. 將nexus部署到tomcat中
可以把nexus當做一個普通的java web項目即可,由於資源有限,這里將tomcat默認的項目統統刪除掉,即刪除tomcat/webapps
中的所有目錄。
然后將nexus這個目錄放到/tomcat/webapps
目錄下即可,啟動tomcat。
cd bin
./startup.sh
5. nexus2.x的storage目錄
nexus2.x跟nexus3.x有很大的區別,在存儲上nexus2.x采用的是目錄結構,而nexus3.x使用的是ElasticSearch,這也是為什么我選用nexus2.x而不是最新的nexus3.x的原因,樹莓派的資源根本跑不起ElasticSearch。
下面是nexus2啟動后會創建的目錄:
backup
conf
db
felix-cache
health-check
indexer
iq
logs
nexus.lock
nuget
orient
plugin-repository
storage
timeline
這里,只需要關注storage這個目錄即可,因為私服的所有依賴都存放在這個目錄下面,下面是storage的目錄結構:
apache-snapshots
central # 倉庫遷移位置
central-m1
npm_all
npmjs_my
npmjs_central
public # 依賴發布
releases
snapshots
thirdparty
6. 上傳已有的依賴(或依賴遷移)
正常情況下,在我們搭建nexus2.x私服之前,我們本地都會有一個maven本地倉庫,我們可以將本地的maven倉庫中的依賴FTP傳到nexus中。
- 將依賴工作目錄的
storage/central
中。 - 登錄nexus2.x的管理界面,在 Repositories-> central 中右鍵 reindex 一次。
這樣當我們拉取依賴的時候,central已經有的依賴就不用再到maven中央倉庫去拉取了,沒有的情況下nexus2才先到maven中央倉庫拉取。
當然,如果是私服遷移的話,只需將源私服的storage下面的倉庫備份到新私服上,執行reindex即可,這比nexus3.x的遷移好方便好多。
關注公眾號,閱讀更多關於nexus2.x的文章。(如:nexus搭建npm倉庫,nexus權限管理,maven倉庫的使用等將持續更新...)