zoukankan      html  css  js  c++  java
  • 使用Docker 容器配置nexus3.29 私有仓库

    在创建 repository之前,还是需要先设定一个指定的文件存储目录,便于统一管理。

    默认创建在nexus安装目录下数据目录

    选择仓库类型 这里选择proxy类型如图

    配置仓库

    该仓库指定一个唯一的名称、HTTP的端口、允许交互的API等

    由于访问中央仓库有时候会比较慢,这里我添加一个阿里云的代理仓库,然后优先级放到默认中央库之前, 阿里云的maven仓库url为http://maven.aliyun.com/nexus/content/groups/public

    注意上图的 Release,nexus2不清楚,但是在nexus3中,这个库要区分是存放RELEASE稳定版本的,还是存储SNAPSHOT不稳定版本的。

    这会影响到当你使用mvn deploy命令把本地的jar或其他maven构件上传到nexus私服时,如果你的项目打包版本例如是0.0.1-SNAPSHOT,就会说不允许上传到release稳定版本库中。

    默认的这几个仓库我解释一下:

    1. maven-central: maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
    2. maven-releases: 私库发行版jar,初次安装请将Deployment policy设置为Allow redeploy
    3. maven-snapshots: 私库快照(调试版本)jar
    4. maven-public: 仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

    Nexus默认的仓库类型有以下四种:

    1. group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库;
    2. hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库);
    3. proxy(代理类型):从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage属性的值即被代理的远程仓库的路径);
    4. virtual(虚拟类型):虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用);

     

     

     

    Nexus搜索页
      这个不需要登录就可以访问,用来查询jar包。支持模糊查询

    本地Maven使用私服

    安装和配置好之后,在开发中如何使用呢。可在maven的默认配置settings.xml中修改如下:

    <servers>
      <server>
        <id>maven-releases</id>  <!--对应pom文件中的id-->
        <username>admin</username>
        <password>admin457280</password>
      </server>
      <server>
        <id>aliyun-proxy</id>    <!--对应pom中的id-->
        <username>admin</username>
        <password>admin457280</password>
      </server>
      <server>
        <id>maven-snapshots</id> <!--对应pom中的id-->
        <username>admin</username>
        <password>admin457280</password>
      </server>
    </servers>

    一般,仓库的下载和部署是在pom.xml文件中的repositoriesdistributionManagement元素中定义的。然而,一般类似用户名、密码(有些仓库访问是需要安全认证的)等信息不应该在pom.xml文件中配置,这些信息可以配置在settings.xml中。

    <!--配置远程仓库(私服) -->
    <
    mirrors> <!-- 指定仓库的下载镜像。 --> <mirror> <!-- 该镜像的唯一标识符。id用来区分不同的mirror元素。 --> <id>aliyun-proxy</id> <!-- 镜像名称 --> <name>nexus repository</name> <!-- 被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo.maven.apache.org/maven2/)的镜像,就需要将该元素设置成central。这必须和中央仓库的id central完全一致。 --> <mirrorOf>*</mirrorOf> <!-- 该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 --> <url>http://192.168.1.111:8081/repository/aliyun-proxy/</url> </mirror> <!--maven aliyun镜像配置 --> <mirror> <id>maven-public</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://192.168.1.111:8081/repository/maven-public/</url> </mirror> </mirrors>
    <profiles>
       <profile>  
            <id>dev</id>
            <repositories>
              <repository>
                <id>nexus</id>
                <url>http://192.168.1.111:8081/repository/maven-public/</url>
                <releases>
                  <enabled>true</enabled>
                </releases>
                <snapshots>
                  <enabled>true</enabled>
                </snapshots>
              </repository>
            </repositories>
          <pluginRepositories>
           <pluginRepository>
             <id>nexus</id>
             <name>znlearn</name>
             <url>http://192.168.1.111:8081/repository/maven-public/</url>
           </pluginRepository>
          </pluginRepositories>
      </profile>
    </profiles>

    repositories中可配置多个仓库repository(这里只配置了一个),id:唯一标识,name:自定义仓库名称,url:远程仓库地址,releases 的enable设置为true,告诉maven可以下载releases(稳定版本)的构件;snapshots 的enable 为false,即为禁止下载snapshot(开发中、不稳定)的构件
    其他仓库以供备用:


    激活的profile
    <activeProfiles>
        <!-- 要激活的profile id -->
        <activeProfile>dev</activeProfile>
    </activeProfiles>

    如果要发布自己的jar到私服,就需要修改工程的pom.xml,添加如下内容,否则什么都不用做:

    <!--发布远程部署到私服-->
    <distributionManagement>
        <repository>
            <!-- 发布到 发行版本的仓库中,也可以发布到3rd party 仓库 -->
            <id>station-release</id>
            <name>sze511-rd-Repository</name>
            <url>http://192.168.110.103:8081/repository/station-release/</url>
            <uniqueVersion>true</uniqueVersion>
        </repository>
        <!-- 发布到 快照版本的仓库,即 测试版本仓库 -->
        <snapshotRepository>
            <id>station-hosted</id>
            <name>sze511-rd-Repository</name>
            <url>http://192.168.110.103:8081/repository/station-hosted/</url>
        </snapshotRepository>
    </distributionManagement>

    将本地项目 jar 包推送至远程私服

     

    本地项目快照版本 jar 包已成功推送至nexus ,登陆至nexus管理界面查看

     至此环境成功搭建

  • 相关阅读:
    Druid 使用 Kafka 将数据载入到 Kafka
    Druid 使用 Kafka 数据加载教程——下载和启动 Kafka
    Druid 集群方式部署 —— 启动服务
    Druid 集群方式部署 —— 端口调整
    Druid 集群方式部署 —— 配置调整
    Druid 集群方式部署 —— 配置 Zookeeper 连接
    Druid 集群方式部署 —— 元数据和深度存储
    Druid 集群方式部署 —— 从独立服务器部署上合并到集群的硬件配置
    Druid 集群方式部署 —— 选择硬件
    Druid 独立服务器方式部署文档
  • 原文地址:https://www.cnblogs.com/lwx57280/p/14498403.html
Copyright © 2011-2022 走看看