Linux搭建Nexus私服

本文详述了在Linux环境中安装Nexus的步骤,包括创建仓库、用户和角色,以及如何配置Maven从多个远程仓库下载jar包和发布项目到Nexus。Nexus作为一个仓库管理工具,允许自定义仓库以供项目使用,并提供了权限管理功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

​​​​前言

本文重要介绍了一下几个内容:

  • linux中安装nexus,以及nexus中创建仓库,创建用户,创建角色,关联权限供实际项目中使用。
  • 如何从多个远程仓库中下载jar包(即项目中jar包可能来自于多个仓库)。
  • 如何将项目发布到nexus仓库。

nexus下载

nexus3基于jdk8,所以需要先安装jdk8环境。

推荐资源

nexus3下载官方网站:Download Archives - Repository Manager 3 (外网,很难下载下来)。

nexus3百度云盘下载:https://pan.baidu.com/s/1KzzpfA67En_nb59KQ7efEw(提取码:0000,nexus-3.25.1-04-unix.tar.gz)。

nexus安装

下载完成后,将安装包上传至linux服务器进行安装。

#创建安装目录
mkdir /home/software/nexus
#解压
tar -zxvf nexus-3.25.1-04-unix.tar.gz

解压出两个文件夹:nexus-3.25.1-04(用于实现 nexus 功能)  和 sonatype-work (用于存储数据

nexus常用命令

cd /home/software/nexus/nexus-3.25.1-04/bin
#后台启动服务
./nexus start
#停止服务
./nexus stop
#重启服务
./nexus restart
#查看服务状态
./nexus status

nexus默认端口为8081,服务根路径默认为/。如果需要变更可以更改nexus.properties配置。

#进入配置文件目录
cd /home/software/nexus/sonatype-work/nexus3/etc
#编辑配置文件
vim nexus.properties

 nexus日志记录

#进入nexus日志记录目录
cd /home/software/nexus/sonatype-work/nexus3/log

nexus启动

后台启动nexus服务后,可通过http://xx:8081访问nexus web服务了。

#进入nexus bin目录
cd /home/software/nexus/nexus-3.25.1-04/bin
#后台启动nexus
./nexus start

nexus配置

nexus通常需要创建新的用户,给用户分配角色,角色关联相应权限。供项目中使用。

创建仓库

创建自定义仓库,项目发布时可将jar包发布到该仓库中。

关于仓库的类型说明:

项目具体说明
hosted本地存储。像官方仓库一样提供本地私库功能
proxy提供代理其它仓库的类型
group组类型,能够组合多个仓库为一个地址提供服务

 

 点击创建仓库,创建好的仓库地址如下,项目发布时可引用该地址。

创建角色并分配权限

索引关键字:nx-repository-admin-maven2-

赋予仓库的权限,这里把maven2下 central、public、release、snapshots 库非删除权限(如:browse、edit、read权限),都赋予给 新建的角色,另外把新建的私库的 * 权限(所有权限)也赋予给该角色。

检索自定义仓库的库名,赋予权限 nx-repository-view-maven2-自定义库名-*

检索 searchbrowseupload 关键字,把 nx-search-read、nx-repository-view-*-*.browse、nx-comopnet-upload 权限赋予给该角色。这些权限用于展示如下菜单。

创建用户

nexus默认的账户名admin,初始密码在/home/software/nexus/sonatype-work/nexus3下的admin.password中,修改密码后该文件会消失。

创建新用户,并分配权限,后续项目中项目发布可使用该用户。

maven项目中使用nexus

公共服务项目经过验收测试无误时,可发布到私服供其他项目使用。

maven setting文件配置

    <!--配置发布到私服某个仓库账户信息-->
    <servers>
        <server>
            <id>test-repo</id>
            <username>xx</username>
            <password>xx</password>
        </server>
    </servers>


    <!--此处指定多个mirrors镜像,镜像只会执行第一个位置mirror-->
  <!-- <mirrors>
        <mirror>
            <id>devmaven</id>
            <name>dev maven</name>
            <url>http://xxx:xxxx/repository/xxx/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>https://maven.aliyun.com/repository/public</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>-->
    
    <!--从多个远程仓库下载jar包,查找次序为从下至上。即按照 aliyun->devmaven->maven中央仓库 顺序查询 -->
    <profiles>
        <profile>
          <id>devmaven</id>
          <repositories>
            <repository>
              <id>devmaven</id>
              <url>http://xxx:xxxx/repository/xxx/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
              </snapshots>
            </repository>
          </repositories>
        </profile>
        <profile>
          <id>aliyun</id> 
          <repositories>
            <repository>
              <id>aliyun</id> 
              <url>https://maven.aliyun.com/repository/public</url> 
              <releases>
                <enabled>true</enabled>
              </releases> 
              <snapshots>
                <enabled>true</enabled> 
                <updatePolicy>always</updatePolicy>
              </snapshots>
            </repository>
          </repositories>
        </profile>
  </profiles>
 
 <!--激活profile配置 -->
  <activeProfiles>
      <activeProfile>devmaven</activeProfile>
      <activeProfile>aliyun</activeProfile>
  </activeProfiles>

maven pom文件配置

      <distributionManagement>
        <repository>
            <!--和setting中配置的id保持一致即可,不必和仓库名一致-->
            <id>test-repo</id>
            <name>common service</name>
            <url>http://xxx:xxxx/repository/test-repo/</url>
        </repository>
    </distributionManagement>

执行mvn deploy命令完成项目发布。

参考:

Linux 部署 Nexus (下载、安装、使用)_Stephen·You的博客-CSDN博客_linux nexus

idea svn创建trunk主干、branch分支和tag标签_yy1209357299的博客-CSDN博客_svn 创建tag

Maven版本管理-Maven Release Plugin插件_和代码去流浪的博客-CSDN博客_maven 版本管理插件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值