Maven 私服Nexus 基于compose部署

控制面板操作

  1. 打开浏览器输入,输入nexus的地址:http://192.168.1.250:8888/
  2. 登录到控制面板
  3. 创建存储库
    点击设置按钮, 选中Blob Stores, 点击Create blob store, 输入仓库名称, 并且点击Create blob store;
    Maven 私服Nexus 基于compose部署

Maven 私服Nexus 基于compose部署

  1. 创建仓库
    设置 --> Repositories --> Create repository --> Select Recipe ( 选择仓库类型 ) --> 输入仓库的相关信息 --> Create repository
    注意: Hosted 选项选择 Allow redeploy
    Maven 私服Nexus 基于compose部署

nexus默认仓库

  • maven-central: maven*库, 默认从https://repo1.maven.org/maven2/拉取jar;

  • maven-releases: 私库发行版 jar;

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

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

nexus默认仓库类型

  • group ( 仓库组类型 ) : 又叫组仓库,用于方便开发人员自己设定的仓库;

  • hosted ( 宿主类型 ) : 内部项目的发布仓库 ( 内部开发人员,发布上去存放的仓库 );

  • proxy ( 代理类型 ) : 从远程*仓库中寻找数据的仓库 ( 可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径);

  • virtual ( 虚拟类型 ) : 虚拟仓库 ( 这个基本用不到,重点关注上面三个仓库的使用) ;

国内*仓库

  1. http://www.sonatype.org/nexus/ ( 私服nexus工具使用 )
  2. http://mvnrepository.com/ ( 推荐 )
  3. http://repo1.maven.org/maven2
  4. https://maven.aliyun.com/repository/public/ ( 阿里云 - 个人推荐 )
  5. http://repo2.maven.org/maven2/ ( 私服nexus工具使用 )
  6. http://uk.maven.org/maven2/
  7. http://repository.jboss.org/nexus/content/groups/public
  8. http://maven.oschina.net/content/groups/public/ oschina
  9. http://mirrors.ibiblio.org/maven2/
  10. http://maven.antelink.com/content/repositories/central/
  11. http://nexus.openkoala.org/nexus/content/groups/Koala-release/

部署文件

compose-nexus.yaml

version: "3"
services:
  nexus3:
    image: sonatype/nexus3
    container_name: nexus
    restart: always
    privileged: true
    ports:
      - "8888:8081"
    volumes:
      # echo 'Asia/Shanghai' > /etc/timezone/timezone
      - /etc/timezone/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - ./nexus-data:/nexus-data

PS:如果报nexus-data目录没有权限,这需要给目录赋予权限,使用命令如下:chmod +x nexus-data

启动脚本

startup.sh

#! /usr/bin/bash
# 定义一个名称变量
project_name="nexus"
network_name="${project_name}_bridge"

if [ ! -d "nexus-data" ]; then
  mkdir ${project_name}-data
  chmod 777 ${project_name}-data
fi

mkdir -p /etc/timezone
echo 'Asia/Shanghai' > /etc/timezone/timezone

filterName=`docker network ls | grep $network_name | awk '{ print $2 }'`

if [ "$filterName" == "" ]; then
    # 不存在就创建
    docker network create $network_name
    echo "Created network $network_name success!!"
fi

docker-compose -f ./compose-${project_name}.yaml up -d
docker ps -a
docker logs -f ${project_name}

本地maven配置

setting.xml

	<pluginGroups>

	</pluginGroups>

	<proxies>

	</proxies>
    <servers>
        <server>
            <id>public-repo</id>
            <username>mvn123</username>
            <password>1234566</password>
        </server>
		
		<server>
		  <id>releases-repo</id>
		  <username>mvn123</username>
		  <password>1234566</password>
		</server>

		<server>
		  <id>snapshots-repo</id>
		  <username>mvn123</username>
		  <password>1234566</password>
		</server>

    </servers>
	
	<mirrors>
        <!-- 阿里云仓库 -->
        <mirror>
            <id>ali maven</id>
            <mirrorOf>central</mirrorOf>
            <name>ali maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
        
		 <mirror>
              <id>public-repo</id>
              <mirrorOf>*</mirrorOf>
              <name>Nexus osc</name>
              <url>http://120.92.141.131:8888/repository/maven-public/</url>
		</mirror>
	</mirrors>

项目内依赖配置

pom.xml

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <!--发布代码Jar插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <!--id与 maven settings.xml 中的id 文件保持一致-->
            <id>public-repo</id>
            <!--  对应的私服仓库地址-->
            <url>http://120.92.141.131:8888/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        
        <repository>
            <id>ali maven</id>
            <url>http://maven.aliyun.com/nexus/content/groups/public//</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>local private nexus</name>
            <url>http://120.92.141.131:8888/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        
        <pluginRepository>
            <id>ali maven</id>
            <name>ali maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <distributionManagement>
        <repository>
            <id>releases-repo</id>
            <name>Nexus Releases Repository</name>
            <url>http://120.92.141.131:8888/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots-repo</id>
            <name>Nexus Snapshot  Repository</name>
            <url>http://120.92.141.131:8888/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

Maven 私服Nexus 基于compose部署

上一篇:docker环境下安装maven私服和gitlab


下一篇:阿里云仓库配置