搭建企业maven私服

maven私服-nexus

下载安装

下载nexus

访问官网: https://help.sonatype.com/repomanager3/product-information/download

下载Linux版本

在服务器中创建文件夹:nexus

在这里插入图片描述

上传压缩包到文件夹中

在这里插入图片描述

解压文件
tar -zxvf nexus-3.61.0-02-unix.tar.gz

在这里插入图片描述

nexus 配置

进入nexus-3.61.0-02/bin 文件夹

/usr/local/software/nexus/nexus-3.61.0-02/bin
在这里插入图片描述
在这里插入图片描述

编辑nexus.vmoptions文件

根据自己机器内存大小,适当配置内存。内存太小未来启动nexus会失败。

vim nexus.vmoptions

这个是已经修改过的
在这里插入图片描述

配置端口
  • 进入etc文件夹
    在这里插入图片描述
  • 查看nexus-default.properties文件

在这里插入图片描述
可以修改此处的端口号
这里我没有修改,如果修改了以后 :wq 保存退出,然后开放防火墙端口

[root@localhost etc]# firewall-cmd --add-port=8081/tcp --permanent 
success
[root@localhost etc]# firewall-cmd --reload
success

运行nexus

启动nexus
./nexus start            //启动命令

在这里插入图片描述在这里插入图片描述

查看nexus的运行状态
在浏览器中输入    http://192.168.107.130:8081       //IP是自己的服务器IP

在这里插入图片描述

修改管理员密码

在这里插入图片描述

  • 查看管理员密码
  1. 进入sonatype-work\nexus3文件夹
    在这里插入图片描述
    2.查看管理员密码
    在这里插入图片描述
  • 修改管理员密码
    1.浏览器登录nexus
    image-20221230205922783
    2.修改密码
    image-20221230210005734
    image-20221230210125712image-20221230210220617image-20221230210254339

一定要修改密码,默认的密码是一次性的

配置私有仓库

nexus中默认仓库

maven-releases (Version policy=Release)默认只允许上传不带SNAPSHOT版本尾缀的包,默认部署策略是Disable redeploy 不允许重复上传相同版本号信息的jar,避免包版本更新以后使用方无法获取到最新的包。

maven-snapshots (Version policy=Snapshot)只允许上传带SNAPSHOT版本尾缀的包,默认部署策略是Allow redeploy,允许重复上传相同版本号信息的jar,每次上传的时候会在jar的版本号上面增加时间后缀信息。

maven-central 中央仓库的拷贝,如果环境可以访问中央仓库,则可以获取到相关的包,否则没用

maven-public 仓库组,不是实际个一个仓库地址,只是将现有的组合到一次,可以通过它看到所属组内全部仓库的jar信息

image-20231012140451067image-20221230210907451

创建自定义仓库

添加repository仓库

image-20221230211115408

image-20221230211211724

选择maven2(hosted)

image-20231012140759153
image-20231012140921861
在这里插入图片描述

添加release仓库

在这里插入图片描述

添加snapshot仓库

在这里插入图片描述

添加新建仓库到maven-public群组中

选中maven-public群组,之后访问maven-public就可以访问自己的私有仓库了

image-20231012141330410
在这里插入图片描述
在这里插入图片描述

另外2个同理

在这里插入图片描述

批量上传本地文件到自定义仓库中

上传本地仓库内容到linux服务器

记得提前创建文件夹,上传到文件夹中

找到自己的本地仓库位置

在这里插入图片描述

全选然后点击上传

在这里插入图片描述

等待上传完成

在这里插入图片描述

编辑批量上传脚本

在本地仓库上传的文件夹(maven-repository)下创建一个shell脚本,命名 repo.sh

  • 创建脚本
touch repo.sh
  • 编辑脚本
vim repo.sh

把下面的代码复制进去

#!/bin/bash
while getopts ":r:u:p:" opt; do
    case $opt in
        r) REPO_URL="$OPTARG"
        ;;
        u) USERNAME="$OPTARG"
        ;;
        p) PASSWORD="$OPTARG"
        ;;
    esac
done

find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
添加权限

给脚本repo.sh添加执行权限

chmod +x repo.sh

添加之前
image-20231012142413163
变成
image-20231012142432201

导入本地仓库到nexus私有仓库

执行以下命令

./repo.sh -u nexus用户名 -p nexus密码 -r 仓库地址
./repo.sh -u admin -p 123 -r http://192.168.107.130:8081/repository/wnhz-repository/

在这里插入图片描述

等待上传完成

image-20221230220912896

上传完成以后这里就可以看到

在这里插入图片描述

项目中引用nexus库

在maven的conf/settings.xml中配置server

id: 名字不能重复,和pom引入名称相同

username/password: nexus的登录用户名密码

image-20231012144312455

<server>
    <id>wnhz</id>
    <username>admin</username>
    <password>123</password>
</server>
<server>
  <id>wnhz-releases</id>
  <username>admin</username>
  <password>123</password>
</server>
<server>
  <id>wnhz-snapshots</id>
  <username>admin</username>
  <password>123</password>
</server>
在maven中配置镜像

中央仓库的资源从阿里云访问,其它资源来自nexus私服

image-20221231104454031

  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.   
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>

     -->
    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>central</mirrorOf>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>nexus djs</name>
      <url>http://192.168.0.101:8081/repository/maven-public/</url>
    </mirror>

  </mirrors>

私服访问地址从下图获取:http://192.168.107.130:8081/repository/maven-public/

在这里插入图片描述

nexus仓库配置
<profile>
<!--profile 的 id-->
<id>nexus</id>
<repositories>
  <repository>
      <!--仓库 id,repositories 可以配置多个仓库,保证 id 不重复-->
      <id>nexus</id>
      <!--仓库地址,即 nexus 仓库组的地址-->
      <url>http://192.168.201.81:8081/repository/maven-public/</url>
      <!--是否下载 releases 构件-->
      <releases>
          <enabled>true</enabled>
      </releases>
      <!--是否下载 snapshots 构件-->
      <snapshots>
          <enabled>true</enabled>
      </snapshots>
  </repository>
</repositories>
<pluginRepositories>
  <!-- 插件仓库,maven 的运行依赖插件,也需要从私服下载插件 -->
  <pluginRepository>
      <!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 -->
      <id>public</id>
      <name>Public Repositories</name>
      <url>http://192.168.201.81:8081/repository/maven-public/</url>
      <!--是否下载 releases 构件-->
      <releases>
          <enabled>true</enabled>
      </releases>
      <!--是否下载 snapshots 构件-->
      <snapshots>
          <enabled>true</enabled>
      </snapshots>
  </pluginRepository>
</pluginRepositories>
</profile>
activeprofile
<activeProfiles>
  <activeProfile>nexus</activeProfile>
</activeProfiles>
项目中配置发布管理

在项目的pom.xml文件中添加 <distributionManagement>

<distributionManagement>
    <snapshotRepository>
        <id>wnhz-snapshots</id>
        <url>http://192.168.201.81:8081/repository/wnhz-snapshots/</url>
    </snapshotRepository>
    <repository>
        <id>wnhz-releases</id>
        <url>http://192.168.201.81:8081/repository/wnhz-releases/</url>
    </repository>
</distributionManagement>
<repositories>
    <repository>
        <id>nexus</id>
        <url>http://192.168.201.81/repository/maven-public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
部署项目到私服

在maven中运行部署,部署(deploy)项目到私服。

image-20221231110237600
在这里插入图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值