Sonatype Nexus 的安装配置参见: CentOS 系统中安装 Nexus 并导入已有的构件库. Nexus 内置了 Jetty 容器,${NEXUS_HOME}/bin/jsw 目录下包含了各个操作系统的启动脚本. 当然, 如果你不喜欢内置的 Jetty 容器, 也可以下载 Nexus 的 war 包, 部署在 tomcat 等容器中.
安装部署后, 比较重要的是能够对其进行深入的管理和配置, 本文将介绍一些关于 Sonatype Nexus 的高级配置技巧, 方便您进行配置管理.
1, 使用 Maven 上传组件注意事项
host 类型的仓库才允许上传组件
仓库需要开启允许上传功能, 配置选项中的 Deployment Policy 选择 "Allow Redeploy", 见下图
Nexus 用户必须具有 "Artifact Upload" 的权限, Nexus 内置了一些角色, 比如 "Nexus Deployment Role", 就可以上传组件
Maven 主配置文件中需要配置用户信息及上传的仓库信息, 配置示例如下:
- <server>
- <id>thirdparty</id>
- <username>deployment</username>
- <password>password</password>
- </server>
2, 修改监听端口
默认情况下, Nexus 监听端口 8081. 可以通过以下方法更改这个端口.
停止 Nexus
编辑 ${NEXUS_HOME}/conf/plexus.properties 文件, 修改 applicationPort 的值
重启 Nexus.
3, 使 Nexus 支持其它格式的包
Nexus 默认支持 jar,war,pom,ejb,ear,rar,par 等类型的包, 如果希望能添加一些其它类型的包, 可以配置如下:
在 ${nexus-work}/conf/packaging2extension-mapping.properties 配置文件中增加配置:
my-custom-packaging=myextension
如果该配置文件不存在则手动创建该文件.
4, 更新仓库索引
1) 强制更新索引
nexus 索引经常会出现与远程仓库索引不一致的情况, 导致某些包不能正常下载, 可以强制更新仓库索引, 保持索引同步:
以管理员身份登录
右键点击仓库, 选择 Expire Cache
右键点击仓库, 选择 Update Index
2) 定时更新索引
以管理员身份登录
左侧导航栏选择 Administration->Scheduled Tasks
点击 add 添加一个计划任务
任务类型选择: Update Repositories Index,Repository/Group 选择要更新的仓库, Recurrence 选择计划任务的周期类型
5, 调试组件下载过程
如果 Nexus 本地索引中包含组件, 但是却不能下载, 可能的原因如下:
包含组件的组件库不在 group 类型的组件库中
路由规则封锁了组件的下载
Nexus 提供了可以调试组件下载过程的方法, 在组件的下载全路径后面增加参数 "?describe", 示例如下:
Nexus 将会以 JSON 的形式返回调试的输出结果, 结果主要包括:
组件的地址
组件是否可以找到以及原因
如果能找到组件, 统计查找组件的过程
示例返回结果如下:
- {
- "data":{
- "requestUrl":"http://localhost:8081/nexus/content/groups/public/test/project/1.0/project-1.0.jar?describe",
- "processingTimeMillis":471,
- "request":{
- "requestUrl":"http://localhost:8081/nexus/content
- /groups/public/test/project/1.0/project-1.0.jar?describe",
- "requestPath":"/test/project/1.0/project-1.0.jar",
- "requestContext":[
- "request.received.timestamp=1276286536595",
- "request.address=0:0:0:0:0:0:0:1%0",
- "request.remoteOnly=false",
- "request.url=http://localhost:8081/nexus/content/groups/public/test/project/1.0/project-
- 1.0.jar?describe",
- "request.localOnly=false",
- "request.appRootUrl=http://localhost:8081/nexus"
- ]
- },
- "response":{
- "responseType":"NOT_FOUND",
- "processedRepositoriesList":[
- "public",
- "snapshots",
- "thirdparty",
- "central",
- "java.net-m2",
- "java.net-m1-m2",
- "google",
- "apache-snapshots",
- "codehaus-snapshots"
- ],
- "appliedMappings":[
- "public repository applied [11b647d6117038d8=
- [type=EXCLUSION, groupId=public, patterns=[.*/project/.*], mappedRepositories=[releases]]]"
- ]
- }
- }
- }
注意查看其中的 response 节点, 如上例中的 "responseType":"NOT_FOUND" 表示未找到组件, 通过该方法可以详细排查组件不能下载的原因.
再提供一个 pom 类型的包 "mojo-parent-30.pom" 的调试示例
- {
- "data": {
- "requestUrl": "http://192.168.120.202:8081/nexus/content/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom?describe",
- "processingTimeMillis": 1322,
- "request": {
- "requestUrl": "http://192.168.120.202:8081/nexus/content/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom?describe",
- "requestPath": "/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
- "requestContext": [
- "request.remoteOnly=false",
- "request.localOnly=true"
- ]
- },
- "response": {
- "responseType": "FILE",
- "responseActualClass": "org.sonatype.nexus.proxy.item.DefaultStorageFileItem",
- "responsePath": "/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
- "responseUid": "central:/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
- "originatingRepositoryId": "central",
- "originatingRepositoryName": "Central",
- "originatingRepositoryMainFacet": "org.sonatype.nexus.proxy.maven.MavenProxyRepository",
- "processedRepositoriesList": [ ],
- "properties": [
- "created=1333560570000",
- "modified=1333560570000",
- "lastRequested=1375255131976",
- "remoteChecked=1375255131556",
- "remoteUrl=http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
- "storedLocally=1375255131556",
- "isExpired=false",
- "readable=true",
- "writable=true",
- "virtual=false"
- ],
- "attributes": [
- "digest.md5=61a1f7765d45a51a6a7bb03bf410588f",
- "digest.sha1=be742febdaa3cc7a971dacdf8cdc7ebd94b5765b",
- "remote.sha1=be742febdaa3cc7a971dacdf8cdc7ebd94b5765b",
- "request.address=192.168.120.121",
- "request.user=anonymous",
- "storageItem-checkedRemotely=1375255131556",
- "storageItem-created=1333560570000",
- "storageItem-expired=false",
- "storageItem-generation=2",
- "storageItem-lastRequested=1375255131976",
- "storageItem-length=26627",
- "storageItem-modified=1333560570000",
- "storageItem-path=/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
- "storageItem-readable=true",
- "storageItem-remoteUrl=http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
- "storageItem-repositoryId=central",
- "storageItem-storedLocally=1375255131556",
- "storageItem-writable=true"
- ]
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2944989.html