简介
使用nexus可以搭建私人的仓库。
优点
- Nexus是一套“开箱即用”的系统不需要数据库,它使用文件系统加Lucene来组织数据。
- 支持WebDAV与LDAP安全身份认证。
安装
需要jdk
创建目录
mkdir /usr/local/nexus3
复制安装包
cp nexus-3.18.1-01-unix.tar /usr/local/nexus3
解压文件
tar -zxvf nexus-3.18.1-01-unix.tar
生成2个文件夹
- sonatype-work 是nexus工作目录
- nexus-3.18.1-01 安装目录
修改端口地址[可选]
cd nexus-3.18.1-01/etc/
vimnexus-default.properties
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
# 服务端口
application-port=9090
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/
# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
nexus-pro-feature
nexus.hazelcast.discovery.isEnabled=true
启动服务
cd nexus-3.18.1-01/bin
./nexus start 可后台启动
./nexus stop 停止服务
浏览器打开地址:http://localhost:9090/
用户名 admin
密码在 sonatype-work/nexus3/admin.password 文件
实践
搭建npm仓库上传下载依赖
前提已安装了npm。
nexus上创建npm的仓库
下面这三个都可以创建一个
- hosted 表示本地的仓库
- proxy 表示代理的仓库,优先本地,本地没有会到配置的代理服务地址下载
- group 表示组
复制仓库地址
创建角色
创建用户
添加realms
一种方法
vim ~/.npmrc
1 registry=http://localhost:9090/repository/npm-proxy/
2 home=https://www.npmjs.org
3 email=deployer@qq.com
4 _auth=ZGVwbG95ZXI6ZGVwbG95ZXI=
_auth 是nexus的用户的 [用户名:密码] 串的base64编码(不包括中括号)
另一种方法
nrm add npm-group http://localhost:9090/repository/npm-group/
nrm use npm-group
npm adduser
接着发布
npm publish
下载依赖
npm install
搭建maven仓库上传下载依赖
前提已安装了maven nexus上创建maven仓库
创建仓库没什么好说的,写好名字下一步下一步。。。
回到仓库首页,获取仓库url
修改maven配置文件setting.xml
cd /usr/local/apache-maven-3.5.4/conf
添加认证 和 镜像地址
<server>
<id>test</id>
<username>deployer</username>
<password>deployer</password>
</server>
... ...
<mirror>
<id>test</id>
<!--*指的是访问任何仓库都使用我们的私服-->
<mirrorOf>*</mirrorOf>
<name>Nexus myself</name>
<url>http://localhost:9090/repository/test/</url>
</mirror>
maven的pom文件
<distributionManagement>
<repository>
<id>test</id>
<name>Nexus Release Repository</name>
<url>http://localhost:9090/repository/test/</url>
</repository>
</distributionManagement>
使用 开发工具自带的maven deploy