docker安装nexus3私有仓库

By prince No comments

一、部署

安装nexus

docker pull sonatype/nexus3

docker run -dti --name nexus \
--restart=always \
-p 8081:8081 \
-p 8082:8082 \
-p 8083:8083 \
-p 8084:8084 \
-v /data/program/nexus3/nexus-data:/nexus-data \
sonatype/nexus3

二、设置

访问 http://IP地址:8081进入nexus3,登陆admin账户

创建Blob Stores,这里主要创建maven和docker的存储空间。

maven仓库配置

Browse可以查看当前有多少仓库,搭建好的Nexus,默认会带有一些maven仓库,一般使用这些仓库就足够了。

1.默认仓库说明

maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

maven-releases:私库发行版jar,初次安装请将Deployment policy设置为Allow redeploy

maven-snapshots:私库快照(调试版本)jar

maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml或项目pom.xml中使用

2.仓库类型

Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的,用于方便开发人员自己设定的仓库。maven-public就是一个Group类型的仓库,内部设置了多个仓库,访问顺序取决于配置顺序,3.x默认Releases,Snapshots,  Central,当然你也可以自己设置。

Hosted:私有仓库,内部项目的发布仓库,专门用来存储我们自己生成的jar文件
3rd party:未发布到公网的第三方jar (3.x去除了)
Snapshots:本地项目的快照仓库
Releases: 本地项目发布的正式版本
Proxy:代理类型,从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage属性的值即被代理的远程仓库的路径),如可配置阿里云maven仓库
Central:中央仓库
Apache Snapshots:Apache专用快照仓库(3.x去除了)

3.添加仓库

(1)按照步骤添加新的代理源

(2)选择添加maven2的代理

(3)添加代理(Cache统一设置为200天 288000)

(4)逐个增加常用代理

1. aliyun
http://maven.aliyun.com/nexus/content/groups/public
2. apache_snapshot
https://repository.apache.org/content/repositories/snapshots/
3. apache_release
https://repository.apache.org/content/repositories/releases/
4. atlassian
https://maven.atlassian.com/content/repositories/atlassian-public/
5. central.maven.org
http://central.maven.org/maven2/
6. datanucleus
http://www.datanucleus.org/downloads/maven2
7. maven-central (安装后自带,仅需设置Cache有效期即可)
https://repo1.maven.org/maven2/
8. nexus.axiomalaska.com
http://nexus.axiomalaska.com/nexus/content/repositories/public
9. oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
10.pentaho
https://public.nexus.pentaho.org/content/groups/omni/

(5) 设置maven-public 将这些代理加入Group,最好将本地的maven库放到最上面

(6)设置私用仓库可重复发布

三、配置域名及nginx代理

1.设置域名解析

maven.example.com –>公网ip

2.编辑nginx配置文件

upstream nexus_web {
server 172.17.0.2:8081;
}
server {
    listen 80;
    server_name maven.example.com;
    index index.html index.htm index.php;
    access_log /var/log/nginx/maven.example.com.log main;

    location / {
       proxy_pass http://nexus_web;
       proxy_set_header Host $host;
       client_max_body_size 512m;
       proxy_connect_timeout 3600;
       proxy_send_timeout 3600;
       proxy_read_timeout 3600;
       proxy_buffering off;
       proxy_request_buffering off;
   }
}

四、使用

1.设置用户setting.xml文件

设置用户密码

<server>
<id>releases</id>
<username>admin</username>
<password>admin</password>
</server>

<server>
<id>snapshots</id>
<username>admin</username>
<password>admin</password>
</server>

配置镜像

  
  <mirror>
      <id>nexus</id>
      <mirrorOf>nexus</mirrorOf>
      <url>http://maven.example.com/repository/maven-public/</url>
  </mirror>
  <mirror>
      <id>central</id>
      <mirrorOf>central</mirrorOf>
      <url>http://maven.example.com/repository/maven-central/</url>
  </mirror>
  <mirror>
      <id>releases</id>
      <mirrorOf>releases</mirrorOf>
      <url>http://maven.example.com/repository/maven-releases/</url>
  </mirror>
  <mirror>
      <id>snapshots</id>
      <mirrorOf>snapshots</mirrorOf>
      <url>http://maven.example.com/repository/maven-snapshots/</url>
  </mirror>

配置仓库

<profile>
<id>env-dev</id>

<properties> 
<maven.compiler.source>1.8</maven.compiler.source> 
<maven.compiler.target>1.8</maven.compiler.target> 
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>

<!-- 文件拷贝时的编码 --> 
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
<!-- 编译时的编码 --> 
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> 
</properties>
<repositories>
    <repository>
          <id>nexus</id>
          <name>Nexus Public Repositories</name>
          <url>http://maven.example.com/repository/maven-public/</url>
          <releases> 
             <enabled>true</enabled> 
          </releases> 
          <snapshots> 
             <enabled>true</enabled> 
          </snapshots>
    </repository>

    <repository>
       <id>central</id>
       <name>Nexus Central Repository</name>
       <url>http://maven.example.com/repository/maven-central/</url>
       <releases>
         <enabled>true</enabled>
       </releases>
       <snapshots>
         <enabled>false</enabled>
       </snapshots>
    </repository>

    <repository>
      <id>releases</id>
      <name>Nexus Release Repository</name>
      <url>http://maven.example.com/repository/maven-releases/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>

    <repository>
      <id>snapshots</id>
      <name>Nexus Snapshots Repository</name>
      <url>http://maven.example.com/repository/maven-snapshots/</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
 </repositories>

 <pluginRepositories>
     <pluginRepository>
       <id>nexus</id>
       <url>http://maven.example.com/repository/maven-public/</url>
       <releases>
          <enabled>true</enabled>
       </releases>
       <snapshots>
          <enabled>true</enabled>
       </snapshots>
    </pluginRepository>
    <pluginRepository>
      <id>central</id>
      <url>http://maven.example.com/repository/maven-central/
      </url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>releases</id>
        <url>http://maven.example.com/repository/maven-releases/</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
           <enabled>false</enabled>
        </snapshots>
     </pluginRepository>
     <pluginRepository>
        <id>snapshots</id>
        <url>http://maven.example.com/repository/maven-snapshots/</url>
        <releases>
           <enabled>false</enabled>
        </releases>
        <snapshots>
           <enabled>true</enabled>
        </snapshots>
     </pluginRepository>
 </pluginRepositories>

</profile>

激活配置

<activeProfiles>
    <activeProfile>env-dev</activeProfile>
</activeProfiles>

2.设置项目pom文件

<distributionManagement>
    <repository>
        <id>releases</id>
        <name>Nexus Release Repository</name>
        <url>http://maven.example.com/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://maven.example.com/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

 

 

发表评论

 

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据