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”,示例如下:

http://192.168.120.202:8081/nexus/content/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom?describe

http://localhost:8081/nexus/content/groups/public/foo/bar/1.0/bar-1.0.jar?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"
]
}
}
}

最新文章

  1. [dpdk] 熟悉SDK与初步使用 (二)(skeleton源码分析)
  2. Git 查看某个版本修改了哪些文件
  3. jenkins gitlab整合注意事项
  4. 浅谈RSA加密算法
  5. jquery中ajax的使用
  6. Java 14 类型信息
  7. MAX16054
  8. ASP.NET MVC5 PagedList分页示例
  9. PHP利用超级全局变量$_POST来接收表单数据。
  10. linux 虚拟机模拟配置网络路由环境-简版
  11. buaacoding_2018算法期末上机G题.地铁建设题解
  12. [Windows] [VS] [C] [取得指针所指内存的十六进制形式字符串]
  13. nginx的location、rewrite玩法详解
  14. 不要使用Integer做HashMap的key,尤其在json序列化的时候
  15. IP段,ASN与BGP之间的关系
  16. django框架--cookie/session
  17. 7、Android---网络技术
  18. 剑指 Offer——数字在排序数组中出现的次数
  19. tomcat服务器重启后session可以继续使用
  20. 项目期复习总结2:Table, DIV+CSS,标签嵌套规则

热门文章

  1. 《只是为了好玩:Linux之父林纳斯自传》
  2. Effective Java 76 Write readObject methods defensively
  3. .net 中使用配置文件需注意引用dll文件
  4. mysql插入数据与删除重复记录的几个例子(收藏)
  5. sql 执行动态语句
  6. Android之TelephonyManager类的方法详解
  7. bootstrap学习总结-css组件(三)
  8. MySQL数据库学习笔记(十二)----开源工具DbUtils的使用(数据库的增删改查)
  9. Unity原厂讲师大解密
  10. 转: CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法