docker安装配置nexus3

一.  nexus安装部署

1. docker搜索nexus镜像

docker search nexus

2. 查询nexus镜像版本

打开docker镜像仓库,并搜索nexus

找到搜索到的对应镜像,并点击tags

3. 拉取nexus镜像

docker pull sonatype/nexus3:3.26.1

4. 并编写docker-compose.yaml

version: '3'
services:
  nexus3:
    restart: always
    image: sonatype/nexus3:3.26.1
    privileged: true
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
      resources:
        limits:
          cpus: '0.5'
          memory: 1024M
        reservations:
          cpus: '1'
          memory: 2408M
    volumes:
      - /opt/data/nexus:/nexus-data
    ports:
      - "8081:8081"
      - "8082:8082"
      - "8083:8083"
    container_name: "nexus3"
    networks:
      - back-up
#附带redis
  redis:
    restart: always
    image: redis:6.0
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
      resources:
        limits:
          cpus: '0.5'
          memory: 1024M
        reservations:
          cpus: '1'
          memory: 2408M
    volumes:
      - /opt/data/redis:/opt/data/redis
      - /opt/logs/redis:/opt/logs/redis
    command: redis-server --requirepass 123456
    ports:
      - "16379:6379"
    container_name: "redis"
    networks:
      - back-up
networks:
  back-up:
    driver: bridge

5. 安装nexus容器

docker-compose -f docker-compose.yaml up -d

6. 修改宿主机挂载文件夹权限

chmod 777 /opt/data/nexus

7. 进入容器

docker exec -it nexus3 bash

8. 优化nexus容器

-Xms128m
-Xmx256m
-XX:MaxDirectMemorySize=600m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Dkaraf.log=../sonatype-work/nexus3/log
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false

二. nexus私服配置

1. 查看nexus admin用户密码,需要进入容器内

cat /opt/sonatype/sonatype-work/nexus3/admin.password

2. 使用admin.password密码进行登录,登录成功后配置nexus代理仓库(可配置多代理仓库)

å¨è¿éæå¥å¾çæè¿°

http://maven.aliyun.com/nexus/content/groups/public

3. 配置maven-public

将阿里云仓库添加到maven-public仓库中

å¨è¿éæå¥å¾çæè¿°

4. 配置 maven-release、maven-snapshots,允许上传Jar包

å¨è¿éæå¥å¾çæè¿°

5. 创建测试用户

å¨è¿éæå¥å¾çæè¿°

三. 修改maven settings文件

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.home}/conf/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
 
  -->
 <localRepository>D:\develop tools\nec-repository</localRepository>
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
   <server> 
      <id>releases</id> 
      <username>admin</username> 
      <password>1qaz!QAZ2wsx@WSX</password> 
    </server> 
    <server> 
      <id>snapshots</id> 
      <username>admin</username> 
      <password>1qaz!QAZ2wsx@WSX</password> 
    </server> 
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
	<mirror>
	  <id>nexus-myself</id>
	  <mirrorOf>my-nexus</mirrorOf>
	  <name>Nexus myself</name>
	  <url>http://172.28.104.88:8081/repository/maven-public</url>
	</mirror>
  </mirrors>

  <profiles>
	<profile>    
		<!--profile 的 id--> 
		<id>nec</id>    
		<repositories>    
			<repository>   
				<id>central</id>    
				<url>http://172.28.104.88:8081/repository/maven-public</url>    
				<releases>    
					<enabled>true</enabled>    
				</releases>    
				<snapshots>    
					<enabled>true</enabled>    
				</snapshots>    
			</repository>   
			<repository>   
				<id>maven-releases</id>    
				<url>http://172.28.104.88:8081/repository/maven-releases</url>    
				<releases>    
					<enabled>true</enabled>    
				</releases>    
				<snapshots>    
					<enabled>true</enabled>    
				</snapshots>    
			</repository>
			<repository>   
				<id>maven-snapshots</id>    
				<url>http://172.28.104.88:8081/repository/maven-snapshots</url>    
				<releases>    
					<enabled>true</enabled>    
				</releases>    
				<snapshots>    
					<enabled>true</enabled>    
				</snapshots>    
			</repository>			
		</repositories>   
		<pluginRepositories>   
		 <!-- 插件仓库,maven 的运行依赖插件,也需要从私服下载插件 --> 
			<pluginRepository>   
			 <!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 --> 
				<id>public</id>   
				<name>Public Repositories</name>   
				<url>http://172.28.104.88:8081/repository/maven-public</url>   
			</pluginRepository>   
		</pluginRepositories>   
	</profile>   
  </profiles>

  <activeProfiles> 
    <activeProfile>nec</activeProfile> 
  </activeProfiles> 
</settings>

查看仓库url地址

四.  其他

1.  仓库类型

类型

描述

proxy

可以自主配置使用的远程仓库地址

hosted

内部项目构件发布的仓库类型

virtual

虚拟仓库类型(基本不用)

group

可以自由顺序组合多个仓库使用

2. maven仓库

仓库

类型

描述

maven-central

proxy

远程中央仓库

maven-releases

hosted

私库发行仓库

maven-snapshots

hosted

私库快照仓库

maven-public

group

仓库组

3. maven配置文件解析

servers

<!--配置服务端的一些设置。一些设置如安全证书不应该和pom.xml一起分发。这种类型的信息应该存在于构建服务器上的settings.xml文件中。 -->
<servers>
  <!--服务器元素包含配置服务器时需要的信息 -->
  <server>
    <!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 -->
    <id>server001</id>
    <!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
    <username>my_login</username>
    <!--鉴权密码 。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。密码加密功能已被添加到2.1.0 +。详情请访问密码加密页面 -->
    <password>my_password</password>
    <!--鉴权时使用的私钥位置。和前两个元素类似,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)以及如果需要的话,一个密语。将来passphrase和password元素可能会被提取到外部,但目前它们必须在settings.xml文件以纯文本的形式声明。 -->
    <privateKey>${usr.home}/.ssh/id_dsa</privateKey>
    <!--鉴权时使用的私钥密码。 -->
    <passphrase>some_passphrase</passphrase>
    <!--文件被创建时的权限。如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(permission)。这两个元素合法的值是一个三位数字,其对应了unix文件系统的权限,如664,或者775。 -->
    <filePermissions>664</filePermissions>
    <!--目录被创建时的权限。 -->
    <directoryPermissions>775</directoryPermissions>
  </server>
</servers>

 Mirrors :  mirror的作用一般是为了使用一个更快速度的镜像,主要是访问速度的考虑,或者突破屏蔽(部分jar被河蟹)使用可以访问的镜像

1.在maven中不配置mirror时如果本地仓库中找不到jar包,使用的maven的中央库。

2.在maven中配置一个mirror时,mirror通常会设置成*,还有可能是一个具体的值,还有可能是逗号隔开的几个值..

例如:

<mirrorOf>*</mirrorOf>  匹配所有远程仓库
<mirrorOf>external:*</mirrorOf> 匹配所有远程仓库,匹配所有不在本机的仓库
<mirrorOf>repo1,repo2</mirrorOf> 匹配仓库repo1和repo2
<mirrorOf>*,!repo1</mirrorOf> 匹配所有远程仓库,除了repo1

<mirrors>
  <!-- 给定仓库的下载镜像。 -->
  <mirror>
    <!-- 该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
    <id>mirrorId</id>
    <!-- 镜像名称 -->
    <name>PlanetMirror Australia</name>
    <!-- 该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 -->
    <url>http://downloads.planetmirror.com/pub/maven2</url>
    <!-- 被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo.maven.apache.org/maven2/)的镜像,就需要将该元素设置成central。这必须和中央仓库的id central完全一致。 -->
    <mirrorOf>repositoryId</mirrorOf>
  </mirror>
</mirrors>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值