Nexus安装和搭建Maven私服

一、什么是Maven私服?

私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当Maven需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载
在这里插入图片描述
在这里插入图片描述

二、安装Nexus

1)、安装JDK和Maven

参考:https://blog.csdn.net/qq_40378034/article/details/86685680

2)、下载Nexus

https://www.sonatype.com/download-oss-sonatype

3)、解压

[root@localhost ~]# tar -zxf nexus-3.16.1-02-unix.tar.gz -C /usr/local/

4)、修改配置文件

[root@localhost local]# cd /usr/local/nexus-3.16.1-02/etc/
[root@localhost etc]# ls
fabric  jetty  karaf  logback  nexus-default.properties  ssl
[root@localhost etc]# vi nexus-default.properties

修改对应端口号
在这里插入图片描述
5)、关闭防火墙

启动: systemctl start firewalld

关闭: systemctl stop firewalld

查看状态: systemctl status firewalld

开机禁用 : systemctl disable firewalld

开机启用 : systemctl enable firewalld

6)、启动Nexus

[root@localhost etc]# cd /usr/local/nexus-3.16.1-02/bin/
[root@localhost bin]# ./nexus start

在这里插入图片描述
WARING:不建议使用root账户启动这个软件

[root@localhost bin]# useradd nexus
[root@localhost bin]# chown -R nexus:nexus /usr/local/nexus-3.16.1-02/
[root@localhost bin]# chown -R nexus:nexus /usr/local/sonatype-work/
[root@localhost bin]# su nexus
[nexus@localhost bin]$ nohup ./nexus run &

7)、访问http://IP:8081/

使用默认的账户名、密码登录:admin/admin123

8)、修改ulimit
在这里插入图片描述
在这里插入图片描述

[nexus@localhost bin]$ su root
[nexus@localhost bin]$ vi /etc/security/limits.conf

添加如下配置:

* soft nofile 65536
* hard nofile 65536

重启服务器

9)、修改密码
在这里插入图片描述
改为123456

三、Nexus的使用

1)、仓库类型

  • proxy:代理仓库,用于代理远程仓库
  • group:仓库组,通常包含了多个代理仓库和宿主仓库,在项目中只要引入仓库组就可以下载到代理仓库和宿主仓库中的包
  • hosted:宿主仓库,内部项目、付费jar

在这里插入图片描述
2)、新建仓库
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
3)、将刚才新建的仓库加入到仓库组中
在这里插入图片描述在这里插入图片描述
4)、配置代理
在这里插入图片描述
改为阿里云地址:http://maven.aliyun.com/nexus/content/groups/public/
在这里插入图片描述
5)、本地maven配置

修改本地Maven的conf目录中的settings.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
		  <localRepository>D:\Maven\repository</localRepository>
  <pluginGroups>

  </pluginGroups>
 
  <proxies>
   
  </proxies>

  <servers>
    <server>
      <id>hxt-releases</id>
      <username>admin</username>
      <password>123456</password>
    </server>
	<server>
      <id>hxt-snapshots</id>
      <username>admin</username>
      <password>123456</password>
    </server>
  </servers>
  
  <mirrors>
    
  </mirrors>
  
  <profiles>
	<profile>
      <id>hxt</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <!-- 私有库地址-->
      <repositories>
        <repository>
          <id>hxt</id>
          <url>http://192.168.126.159:8081/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <!--插件库地址-->
      <pluginRepositories>
        <pluginRepository>
          <id>hxt</id>
          <url>http://192.168.126.159:8081/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <!--激活profile activeProfile与profile中id相对应-->
  <activeProfiles>
    <activeProfile>hxt</activeProfile>
  </activeProfiles>
</settings>

url在Nexus中复制即可
在这里插入图片描述
6)、pom.xml添加一个本地没有的依赖进行测试

这里我在项目的pom.xml中添加了如下依赖

        <dependency>
            <groupId>org.xwiki.commons</groupId>
            <artifactId>xwiki-commons-component-api</artifactId>
            <version>11.3</version>
        </dependency>

然后去Nexus中查看效果如下,证明私服配置成功:
在这里插入图片描述
在这里插入图片描述
7)、本地项目打包后发到私服

项目的pom.xml中添加配置

    <!--本地项目打包后发到私服 id要跟本地maven的setting.xml相同 -->
    <distributionManagement>
        <repository>
            <id>hxt-releases</id>
            <name>Ruizhi Release Repository</name>
            <url>http://192.168.126.159:8081/repository/maven-releases/</url>
        </repository>

        <snapshotRepository>
            <id>hxt-snapshots</id>
            <name>Ruizhi Snapshot Repository</name>
            <url>http://192.168.126.159:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

使用mvn clean deploy命令将本地项目打包后发到私服

因为项目的pom.xml中的版本为SNAPSHOT,所以会发布到maven-snapshots
在这里插入图片描述
在这里插入图片描述
8)、直接上传jar包到私服
在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邋遢的流浪剑客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值