Nexus搭建和使用

Nexus 是一个强大的 Maven 和其它仓库的管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问

Nexus 官网:

https://www.sonatype.com/

官方下载说明

https://help.sonatype.com/en/download.html

官方下载页面

https://help.sonatype.com/en/download-archives—repository-manager-3.html

官方安装文档链接

https://help.sonatype.com/repomanager3/installation

安装要求

https://help.sonatype.com/repomanager3/installation/system-requirements #官方要求内存8G以上,太小比如4G以下会导致无法启动

部署nexus

注意:nexus 版本要最新版,否则会出现 502 bad gateway

apt install openjdk-11-jdk -y
wget https://download.sonatype.com/nexus/3/nexus-3.69.0-02-java11-unix.tar.gz
tar xf nexus-3.69.0-02-unix.tar.gz -C /usr/local/
ln -s /usr/local/nexus-3.29.2-02/ /usr/local/nexus
ln -s /usr/local/nexus/bin/nexus /usr/bin/

#指定运行身份
vim /usr/local/nexus/bin/nexus.rc
run_as_user="root"  #不推荐

#查看配置文件,可以在此文件中修改端口等配置
/usr/local/nexus/etc/nexus-default.properties

#查看JVM配置文件
/usr/local/nexus/bin/nexus.vmoptions

#前台运行
nexus run 

#后台运行
nexus start

#查看状态
nexus status

#停止服务
nexus stop

#查看默认密码
cat /usr/local/sonatype-work/nexus3/admin.password


#查看端口
ss -ntlp|grep java

#创建service文件
#参考链接https://help.sonatype.com/repomanager3/installation/system-requirements

[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/usr/local/nexus/bin/nexus start
ExecStop=/usr/local/nexus/bin/nexus stop
User=root
#User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target

参见脚本 nexus安装脚本

默认仓库有以下 type 类型

Hosted:本地仓库,通常我们会部署自己的构件到这一类型的仓库,比如公司的第三方库
Proxy:代理仓库,它们被用来代理远程的公共仓库,如maven 中央仓库(官方仓库)
Group:仓库组,用来合并多个 hosted/proxy 仓库,当你的项目希望在多个repository 使用资源时就不需要多次引用了,只需要引用一个 group 即可

配置邮件服务

搭建maven ,参考下面yum

搭建apt仓库

搭建apt仓库跟yum仓库类似,唯一区别在以下

搭建yum仓库

创建 Blob Store 创建自定义存储存放仓库数据

mkdir -p /data/blobs/