使用樹莓派搭建Nexus2私服需要的材料有:
1. 樹莓派3B+(或者4B)
2. 移動硬碟一個
下載nexus2.x安裝包
由於nexus2.x官方的啟動環境並不支持arm架構的樹莓派,所以這裡採用tomcat7 + nexus2.x的方式搭建私服。
下載 nexus-2.14.17-01-bundle.tar.gz
下載 apache-tomcat-7.0.104.tar.gz
移除nexus2.x不必要的插件
將下載的nexus-2.14.17-01-bundle.tar.gz解壓後,會有如下幾個目錄:
binnexuslogslibconf...
用tomcat7來跑nexus,只需要nexus這個目錄中的東西,但是由於樹莓派的內存有限,所以這裡移除了nexus中沒有用到的插件,比如ldap,nuget,yum等。
下面是我們用不到的插件(這個具體根據自己的需要調整),插件的位置在 /nexus/WEN-INF/plugin-repository 這個目錄中。
nexus-analytics-plugin-2.14.17-01nexus-archetype-plugin-2.14.17-01nexus-atlas-plugin-2.14.17-01nexus-capabilities-plugin-2.14.17-01nexus-crypto-plugin-2.14.17-01nexus-groovy-plugin-2.14.17-01nexus-h2-plugin-2.14.17-01nexus-iq-repository-oss-plugin-2.14.17-01nexus-kazuki-plugin-2.14.17-01nexus-ldap-realm-plugin-2.14.17-01nexus-logging-plugin-2.14.17-01nexus-lvo-plugin-2.14.17-01nexus-migrationagent-plugin-2.14.17-01nexus-nuget-plugin-2.14.17-01nexus-outreach-plugin-2.14.17-01nexus-rrb-plugin-2.14.17-01nexus-ruby-plugin-2.14.17-01nexus-rutauth-plugin-2.14.17-01nexus-siesta-plugin-2.14.17-01nexus-site-repository-plugin-2.14.17-01nexus-timeline-plugin-2.14.17-01nexus-wonderland-plugin-2.14.17-01nexus-yum-repository-plugin-2.14.17-01
修改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/nexusruntime=${bundleBasedir}nexus-app=${runtime}
將nexus部署到tomcat中
可以把nexus當做一個普通的java web項目即可,由於資源有限,這裡將tomcat默認的項目統統刪除掉,即刪除`tomcat/webapps`中的所有目錄。
然後將nexus這個目錄放到`/tomcat/webapps`目錄下即可,啟動tomcat。
cd bin./startup.sh
nexus2.x的storage目錄
nexus2.x跟nexus3.x有很大的區別,在存儲上nexus2.x採用的是目錄結構,而nexus3.x使用的是ElasticSearch,這也是為什麼我選用nexus2.x而不是最新的nexus3.x的原因,樹莓派的資源根本跑不起ElasticSearch。
下面是nexus2啟動後會創建的目錄:
backupdbfelix-cachehealth-checkindexeriqnexus.locknugetorientplugin-repositorystoragetimeline
這裡,只需要關注storage這個目錄即可,因為私服的所有依賴都存放在這個目錄下面,下面是storage的目錄結構:
apache-snapshotscentralcentral-m1npm_allnpmjs_mynpmjs_centralpublicreleasessnapshotsthirdparty
上傳已有的依賴(或依賴遷移)
正常情況下,在我們搭建nexus2.x私服之前,我們本地都會有一個maven本地倉庫,我們可以將本地的maven倉庫中的依賴FTP傳到nexus中。
1. 將依賴工作目錄的`storage/central`中。
2. 登錄nexus2.x的管理界面,在 Repositories-> central 中右鍵 reindex 一次。
這樣當我們拉取依賴的時候,central已經有的依賴就不用再到maven中央倉庫去拉取了,沒有的情況下nexus2才先到maven中央倉庫拉取。
當然,如果是私服遷移的話,只需將源私服的storage下面的倉庫備份到新私服上,執行reindex即可,這比nexus3.x的遷移好方便好多。
關注公眾號(HiIT青年)閱讀更多文章。