Nexus簡介html
Nexus是Sonatype推出的強大Maven倉庫管理器產品,要比之前TSS上介紹的Artifactory要好使用的多,也是一個拆箱即用的Java App,內嵌Jetty容器和Java Wrapper作Windows服務,安裝簡單到解壓而後雙擊install便可。更詳細的幫助手冊請上官方網站查看,這裏推薦一個翻譯中的書籍——《Maven權威指南》(在線閱讀英文版,中文版),一本全面介紹Maven的書,其中也有介紹Nexus的章節,猛擊這。Nexus的優勢這裏得囉嗦一下(摘抄自Maven中文Blog):java
默認安裝後的訪問路徑爲http://localhost:8081/nexus/, 管理員登陸爲admin/admin123,UI是用Ext搭建的,熟悉Ext的人根本沒有操做障礙,登陸後最重要的事情就是打開遠程索引下載,操做爲選 擇菜單Administrator->Repositories,而後在右邊打開的列表中依次選擇type字段爲proxy的記錄,在下方的編輯區 中修改"Download Remote Indexes"值爲true,再從這三個倉庫上點右鍵選擇"Re-Index",這一步別忘,我當時搭建的時候就忘了Re-Index,結果等了一天還 沒任何索引文件。Re-Index後,Nexus會從後臺去官方地址下載倉庫索引文件,大概20M大小,根據網速快慢下載相應時間後選擇倉庫時會以樹形目 錄的方式顯示倉庫內容。web
角色權限sql
Nexus的操做權限徹底仿照RBAC角色權限模型,默認三個用戶:admin、anonymous、deployment,對應的是管理用戶、匿 名訪問用戶和部署用戶,管理用戶用於倉庫管理和系統配置,匿名用戶用於倉庫查詢和倉庫下載,部署用戶用於私人jar包的上傳。在這裏,我對 deployment的默認角色Nexus Deployment Role作了自定義修改,加入了"All M2 Repositories"的create和update權限,而且加入了"UI:Base UI Privaties"權限,用意稍後解釋。apache
Nexus的使用瀏覽器
<settings> <proxies> <proxy> <id>normal</id> <active>true</active> <protocol>http</protocol> <username>deployment</username> <password>deploy</password> <host>localhost:8081/nexus</host> <port>80</port> <nonProxyHosts>localhost:8081/nexus</nonProxyHosts> </proxy> </proxies> <mirrors> <mirror> <!--This is used to direct the public snapshots repo in the profile below over to a different nexus group --> <id>nexus-public-snapshots</id> <mirrorOf>public-snapshots</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public-snapshots</url> </mirror> <mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <id>development</id> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <!--this profile will allow snapshots to be searched when activated--> <id>public-snapshots</id> <repositories> <repository> <id>public-snapshots</id> <url>http://public-snapshots</url> <releases><enabled>false</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public-snapshots</id> <url>http://public-snapshots</url> <releases><enabled>false</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>development</activeProfile> </activeProfiles> </settings>
而後,在從你的工程裏的pom.xml中加入如下內容:服務器
<distributionManagement> <repository> <id>repo</id> <name>public</name> <url>http://localhost:8081/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>Snapshots</id> <name>Snapshots</name> <url>http://localhost:8081/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement>
解釋一下:
settings.xml中的proxies/proxy節點配置的是部署服務器訪問屬性,deployment/deploy對應的是部署用戶名和密 碼;mirrors/mirror配置的是maven訪問倉庫的地址,這裏使用的是Nexus提供的羣組概念,將多個倉庫組成一個public- group的方式進行訪問;profiles/profile則主要用來描述倉庫部署的訪問配置。app
和apache結合掛域名訪問也很簡單,官方網站上有介紹,我這裏給出一種最簡單的方式:maven
ProxyRequests Off ProxyPreserveHost On
3. 虛擬主機的配置相似下面ide
ServerName repo.duduwolf.com ServerAdmin duduwolf@duduwolf.com ProxyPass / http://localhost:8081/nexus ProxyPassReverse / http://localhost:8081/nexus ErrorLog logs/nexus-error.log CustomLog logs/nexus-access.log common