我是在centos7
环境上安装的 Nexus
,版本是nexus-3.22.0-02
。
Nexus
要求主机上 java
版本不低于1.8
,nexus
的安装和基础使用网上的教程已经很多了,这里主要是记录自己的使用。
nexus
安装包的下载很慢很慢很慢,奇坑无比,这里共享下安装包。
链接:https://pan.baidu.com/s/1xxb5pvUlN720_BBJ4lzj3g
密码:o03i
修改配置
配置文件在/NEXUS_PATH/nexus-3.22.0-02/etc/nexus-default.properties
,
端口号:修改application-port
的值,并重启即可。
上线文:修改nexus-context-path
的值,并重启即可。
文件的存储目录
nexus
下载的文件被存储在$NEXUS_HOME/sonatype-work/nexus3/blobs
目录下,在这个目录下会保存不同的存储目录,如下下图所示,除了默认的存储目录,我又新建了一个放置npm
包的存储目录。
在新建一个 repository
的时候,可以选择放置在那个存储目录中,如下图。
禁用匿名访问权限
忘记管理员密码
3.17及之后版本密码改成随即的了,重置密码的方式也变了参看官方文档
用户名密码访问仓库
maven
中使用
如下所示,需要注意的是,server
和mirror
的id
必须相同,才能配能匹配上,
<servers>
<server>
<id>maven-private</id>
<username>username</username>
<password>password</password>
</server>
...
</servers>
<mirrors>
<mirror>
<id>maven-private</id>
<mirrorOf>*</mirrorOf>
<name>本地私有仓库测试</name>
<url>http://localhost:3300/repository/maven-public/</url>
</mirror>
</mirrors>
npm
中使用
在npm
中,访问需要用户名密码的仓库,如果没有登录会收到如下的错误提示。
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
这时只需要手动登陆仓库地址,按提示输入账户名、密码、邮箱。
npm login registry="http://localhost:3300/repository/npm-public"
Username: username
Password:
Email: (this IS public) xxxx@mail.com
Logged in as username on http://localhost:3300/repository/npm-public/.
登录成功后,在$USER_HOME/.npmrc
中多了如下的一行,表示登录指定仓库的用户名密码的base64
的值。类似的记录可能存在多条
## 登录官方仓库的
//registry.npmjs.org/:_authToken=8dac076f-000000-0000000-97143e45c853
## 登录私有仓库的凭证
//localhost:3300/repository/npm-public/:_authToken=NpmToken.7efe8505-000000-74277fee3580
仓库迁移
Nexus
的构件仓库都保存在sonatype-work
目录中,该目录的位置由nexus/conf/nexus.properties
配置文件指定。仓库迁移需要两个过程:备份和还原
备份
将sonatype-work
文件夹整体备份即可,也可以选择只备份最重要的两个文件夹索引(indexer
)和仓库(storage
)
还原
将备份好的sonatype-work
文件拷贝到新的服务器中。然后修改nexus/conf/nexus.properties
配置文件,重新指定仓库的目录。