美文网首页
Nexus3 docker私有仓库搭建

Nexus3 docker私有仓库搭建

作者: 郑码 | 来源:发表于2018-09-07 15:51 被阅读0次

需求

项目前端主要运用nodejs与java 前后端开发,经常要下载很多依赖的包,各同事间项目不同,存在着重复下载的问题。需要一个公司的私有仓库,Nexus3就成了首选方案,支持的仓库类型多。
由于docker已经使用harbor作为私有仓库,就不再配置,其实配置方法都是类似的。

image.png

解决方法

docker安装

[root@htwy volume]# docker volume create --name nexus-data
nexus-data
[root@htwy dockerwork]# docker volume inspect nexus-data
[
    {
        "CreatedAt": "2018-09-07T02:23:56-04:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/nexus-data/_data",
        "Name": "nexus-data",
        "Options": {},
        "Scope": "local"
    }
]

[root@htwy ~]# docker run -d -p 8181:8081 --name nexus3 -v nexus-data:/nexus-data sonatype/nexus3:3.13.0
47fb062f3d56395ccfec0cad93cb9d657e8545bfce7166de436a549886f674c7
[root@htwy ~]# docker ps | grep 8181
47fb062f3d56        sonatype/nexus3:3.13.0      "sh -c ${SONATYPE_DI…"   10 seconds ago      Up 9 seconds    0.0.0.0:8181->8081/tcp     nexus3

用docker安装就是这么方便,减少无用功,提高效率。 "_"

配置过程

主要是增加仓库。

Nexus中主要是有三种类型,分别是group、hosted、proxy。其含义解释如下:
hosted : 本地存储,即同maven官方仓库一样提供本地私服功能
proxy : 提供代理其他仓库的类型,如maven中央仓库
group : 组类型,实质作用是组合多个仓库为一个地址,可以把hosted,proxy类型的仓库放在现一个group中,供开发人员使用。

npm仓库

npm官方代理仓库


n-n-1.png n-n-2.png n-n-3.png n-n-4.png n-n-5.png

taobao npm仓库代理


n-n-6.png n-n-9.png

maven仓库

增加aliyun代理


n-n-7.png n-n-8.png

修改settings.xml配置,使用nexus私有库

<?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">   
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups> 
 <servers> 
  <server>    
      <id>nexus-releases</id>    
      <username>admin</username>    
      <password>admin123</password>    
    </server>    
    <server>    
      <id>nexus-snapshots</id>    
      <username>admin</username>    
      <password>admin123</password>    
    </server>    
  </servers> 
<!--
这是Server的ID(不是登录进来的user),与Maven想要连接上的repository/mirror中的id元素相匹配。username,password:这两个元素成对出现,表示连接这个server需要验证username和password。在nexus中,默认管理员用户名为admin,密码为admin123。这里使用两个服务器配置,分别对应release和snapshot。
-->
  <mirrors>     
    <mirror>     
      <id>nexus-public</id>     
      <mirrorOf>*</mirrorOf>     
      <url>http://htwy:8181/repository/maven-public/</url>     
    </mirror>    
    <mirror>     
      <id>nexus-snapshots</id>     
      <mirrorOf>*</mirrorOf>     
      <url>http://htwy:8181/repository/maven-snapshots/</url>     
    </mirror>     
  </mirrors> 
<!--
id,name:唯一的镜像标识和用户友好的镜像名称。id被用来区分mirror元素,并且当连接时候被用来获得相应的证书。
mirrorOf:镜像所包含的仓库的Id。例如,指向Maven central仓库的镜像(http://repo1.maven.org/maven2/),设置这个元素为central。更多的高级映射例如repo1,repo2 或者*,!inhouse都是可以的。没必要一定和mirror的id相匹配。在这里mirrorOf项当然应该使用*,以表明是所有仓库都会被镜像到指定的地址。
url:镜像基本的URL,构建系统将使用这个URL来连接仓库。这里应该添nexus仓库的地址,地址可以在nexus仓库页面中找到。
--> 
    <profiles>    
   <profile>    
      <id>nexus</id>    
      <repositories>    
        <repository>    
          <id>nexus-public</id>    
          <url>http://nexus-public</url>    
          <releases><enabled>true</enabled></releases>    
          <snapshots><enabled>true</enabled></snapshots>    
        </repository>    
        <repository>    
          <id>nexus-snapshots</id>    
          <url>http://nexus-snapshots</url>    
          <releases><enabled>true</enabled></releases>    
          <snapshots><enabled>true</enabled></snapshots>    
        </repository>    
      </repositories>    
      <pluginRepositories>    
         <pluginRepository>    
                <id>nexus-public</id>    
                 <url>http://nexus-public</url>    
                 <releases><enabled>true</enabled></releases>    
                 <snapshots><enabled>true</enabled></snapshots>    
               </pluginRepository>    
               <pluginRepository>    
                 <id>nexus-snapshots</id>    
                  <url>http://nexus-snapshots</url>    
                <releases><enabled>true</enabled></releases>    
                 <snapshots><enabled>true</enabled></snapshots>    
             </pluginRepository>    
         </pluginRepositories>    
    </profile>    
  </profiles>    
<!---
profile项代表maven的基本配置。按照maven的一贯尿性,很多xml的配置项都会有一个配置项的复数形式作为父节点,以保证该配置项可以配置多个。在profiles项中,当然也可以配置多个profile,不过在这里配一个就够了。下面介绍profile项的各个子节点。
id:用来确定该profile的唯一标识。
repositories/repository:用以规定依赖包仓库的相关信息。在下属节点中,id就不用多说了;URL是指仓库地址,这里使用伪造的地址,否则即使设置了mirror,maven也有可能会直接从中央仓库下载包;releases和snapshots放在一块说吧,这两个节点下属的enable节点用以规定对应的依赖包是否对当前策略有效,假如将snapshot的enable项设为disable,则不会下载snapshot包。
-->
  <activeProfiles>    
      <activeProfile>nexus</activeProfile>    
    <!-- 用以规定当前启用的配置,将对应profile的ID加入到这一项即可使profile生效。-->
  </activeProfiles>    
</settings>

上传jar到nexus

第一种方式:
mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=dubbo -Dversion=2.8.4 -Dpackaging=jar -Dfile=jar所在路径/dubbo-2.8.4.jar -Durl=http://htwy:8081/repository/maven-releases/ -DrepositoryId=nexus-public

DrepositoryId和settings.xml里配置的id一样

第二种方式:

代码的pom.xml中直接接入

<distributionManagement>  
        <repository>  
            <id>nexus-releases</id>  
            <name>maven-public</name>  
           <url>http://htwy:8081/repository/maven-public/</url>  
        </repository>  
</distributionManagement> 
mvn deploy

引用私有仓库

<repositories>
        <repository>
            <id>nexus-public</id>
            <name>maven-public</name>
            <url>http://htwy:8181/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

参考:

使用nexus3搭建npm私服
构建Docker镜像仓库的另一选择:Nexus3
maven私服nexus3.x环境配置
使用nexus3 配置maven的私有仓库

相关文章

  • Kubernetes部署Nexus3

    Kubernetes部署Nexus3 重点参考kubernetes集群:nexus搭建docker私有仓库及使用 ...

  • maven备忘

    1. 搭建私有库 使用docker搭建私有maven库,docker image为sonatype/nexus3 ...

  • Nexus搭建并代理AliYun镜像

    使用 Docker 搭建 Nexus3 私服. Docker 仓库地址 https://hub.docker.co...

  • Docker

    构建镜像仓库 Docker运行java程序 1.1.6 搭建docker私有仓库 新建私有仓库 1.2.1 数据挂...

  • 5.私有与公有镜像仓库

    一. 搭建私有镜像仓库 Docker Hub作为Docker默认官方公共镜像;如果想自己搭建私有镜像仓库,官方也提...

  • Docker

    一、Docker 私有仓库搭建 环境centos 6 192.168.1.2 Docker 仓库 192.168....

  • Nexus3 docker私有仓库搭建

    需求 项目前端主要运用nodejs与java 前后端开发,经常要下载很多依赖的包,各同事间项目不同,存在着重复下载...

  • k8s学习笔记-5-私有harbor

    5 创建docker私有仓库 使用node5节点搭建harbor私有仓库 harbor仓库依赖docker和doc...

  • Docker搭建私有仓库之Harbor

    Docker搭建私有仓库之Harbor Harbor Harbor是构建企业级私有docker镜像的仓库的开源解决...

  • Docker之八私有仓库

    个人专题目录 Docker 私有仓库 1. 私有仓库搭建 2. 将镜像上传至私有仓库 3. 从私有仓库拉取镜像

网友评论

      本文标题:Nexus3 docker私有仓库搭建

      本文链接:https://www.haomeiwen.com/subject/ttucgftx.html