Nexus3 For Docker 安装配置

Nexus3 For Docker 安装配置教程

安装前准备

安装 nexus3:

下载&安装

下载镜像

docker pull sonatype/nexus3

创建挂载目录

mkdir -p /usr/local/docker/nexus/nexus-data

授权挂载目录

chown -R 200 /usr/local/docker/nexus/nexus-data

运行 nexus

docker run --name nexus \
    --restart=unless-stopped \
    -v /usr/local/docker/nexus/nexus-data:/nexus-data \
    -p 10000:8081 \
    -d sonatype/nexus3
  • -v 挂载目录,防止 docker 停止导致数据丢失
  • -p 端口映射, 使外部可以访问
查看日志
docker logs -f --tail 200 nexus
登录 nexus

获取 admin 登录密码

cat /usr/local/docker/nexus/nexus-data/admin.password
  • 浏览器输入 ip:10000
  • 点击右上角 sign in
  • 输入用户名密码,然后按提示操作
创建角色: 开发者最小权限集请看(骚操作)
创建用户
添加 aliyun maven 仓库
# http://maven.aliyun.com/nexus/content/groups/public/
配置 maven -> setting.xml
<?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">
  <!--  本地仓库地址-->
  <localRepository>/root/.m2/repository</localRepository>

  <pluginGroups>
  </pluginGroups>

  <proxies>
  </proxies>

  <servers>
    <!-- 配置服务,其实只要一个就可以,但是为了权限区分,所以使用多个-->
	<server>
      <id>nexus</id>
      <username>project-developer</username>
      <password>developer123</password>
    </server>
	<server>
      <id>nexus-releases</id>
      <username>project-developer</username>
      <password>developer123</password>
    </server>
	<server>
      <id>nexus-snapshots</id>
      <username>project-developer</username>
      <password>developer123</password>
    </server>
  </servers>

  <mirrors>
    <!-- 定义镜像地址 -->
    <!-- 私有镜像库 id 要和 servers 中的 server 中的 id 一致, 才会用对应的信息验证权限-->
    <!-- mirrorOf 直接用 * 就可以 -->
    <mirror>
	  <id>nexus</id>
	  <name>myself maven</name>
	  <mirrorOf>*</mirrorOf>
	  <url>http://192.168.220.50:10000/repository/maven-public/</url>
	</mirror>
	<mirror>
	  <id>alimaven</id>
	  <name>aliyun maven</name>
	  <mirrorOf>central</mirrorOf>
	  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
	</mirror> 
	<mirror>  
      <id>defmaven</id>
	  <name>maven repository</name>
      <mirrorOf>central</mirrorOf>
      <url>http://repo2.maven.org/maven2/</url>
    </mirror>
  </mirrors>

  <profiles>
    <!-- 如果该处定义的 profile 都在 activeProfiles 中激活的话, 会按这边的顺序后面的覆盖前面的-->
	<!-- override maven center releases and snapshots -->
    <profile>
      <id>central</id>
      <repositories>
          <repository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
          </repository>
      </repositories>
      <pluginRepositories>
          <pluginRepository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
          </pluginRepository>
      </pluginRepositories>
    </profile>
    <!-- 定义私库 -->
    <profile>
        <id>nexus</id>
        <repositories>
          <repository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://192.168.220.50:10000/repository/maven-public/</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
          </repository>
        </repositories>
        <pluginRepositories>
          <pluginRepository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://192.168.220.50:10000/repository/maven-public/</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
          </pluginRepository>
        </pluginRepositories>
    </profile>
  </profiles>
 
  <!-- active last profile which definition in profiles -->
  <activeProfiles>
    <activeProfile>central</activeProfile>
	<activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

配置项目 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>cn.texous.test</groupId>
    <artifactId>demo-gitlabci</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo-gitlabci</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <url>http://192.168.220.50:10000/repository/maven-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>nexus-releases</id>
            <url>http://192.168.220.50:10000/repository/maven-releases/</url>
        </repository>
    </distributionManagement>

</project>

骚操作

nexus 图形界面介绍
nexus3 开发者最小权限集
# nx-repository-view-*-*-browse
# nx-repository-view-*-*-edit
# nx-repository-view-*-*-read
maven docker 镜像配置本地仓库
  • maven 官方镜像说明
  • maven 的镜像默认配置文件地址 /root/.m2
  • 所以实现自定义 settings.xml 只需要将配置好的 settings.xml 拷贝到 /root/.m2 的挂载目录下
  • 比如 docker run -v /data/.m2:/root/.m2 那么只要将 settings.xml 拷贝到 /data/.m2/ 就可以了
  • 注意: settings.xml 中的 localRepository 需要配镜像内的地址,而不是挂载地址. 例: /root/.m2/repository
可优化
  • nexus3 具有 docker 镜像仓库的功能, 后期可以从 gitlab 自带仓库中迁移

参考文献

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值