【Centos7内网环境Nexus3私服搭建】

1、使用背景

在项目开发的过程中,我们通常在内部网络进行开发,在内网环境开发中我们经常遇到 Maven包、Npm包、Yum镜像、Docker镜像等无法联网下载问题,当然这些问题也可以通过离线安装的方式进行安装,但是做为软件开发项目组或者公司等,搭建自己的开发环境私服,也是一个非常好的选择。本文对Nexus私服搭建过程进行详细描述,并亲测可用。
搭建思路是,在外网环境搭建好Nexus私服,拷贝Nexus到内网服务器。

2、Nexus安装

2.1 Nexus文件下载

我们在Nexus的官网下载:

https://help.sonatype.com/repomanager3/product-information/download

使用版本为: nexus-3.37.3-02-unix.tar.gz

2.2 Nexus解压
tar -zxvf nexus-3.37.3-02-unix.tar.gz

解压后的文件夹包括:
nexus-3.37.3-02 :程序的安装执行文件
sonatype-work :数据存储、缓存等文件

2.3 Nexus启动

进入文件夹

cd nexus-3.37.3-02\bin

执行 ./nexus start 启动,启动过程长一点。

[root@VM-0-17-centos bin]# ./nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
Starting nexus

如果启用了防火墙,需要添加访问端口

[root@VM-0-17-centos bin]# firewall-cmd --zone=public --add-port=8081/tcp --permanent

重新加载防火墙配置

[root@VM-0-17-centos bin]# firewall-cmd --reload 
success

访问地址:http://服务器地址:8081/
首次登录,需查看Nexus的密码:

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

登录用户 admin
登录成功后,修改密码
修改admin用户的密码启用匿名访问
启用匿名访问

3、Nexus仓库添加

仓库类型分为3种:
group : 组类型,能够组合多个仓库为一个地址提供服务
hosted : 本地存储。像官方仓库一样提供本地私库功能
proxy : 提供代理其它仓库的类型

3.1 Maven仓库配置
3.1.1 添加阿里云代理仓库

1、点击 “repositories” ->“Create repository”
2、选择 “maven2(proxy)”
3、输入仓库名:maven-aliyun
4、代理仓库地址:http://maven.aliyun.com/nexus/content/groups/public
添加Maven仓库

3.1.2 将代理仓库添加到 maven-group 仓库

将代理仓库添加到maven-group仓库

3.1.3 使用方式一:修改的Maven setting.xml文件
<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>
  <!--添加 maven-central 地址-->
  <mirrors>
    <mirror>
        <id>nexus-releases</id>
        <mirrorOf>*</mirrorOf>
        <url>http://192.168.56.5:8081/repository/maven-public/</url>
    </mirror>
    <mirror>
        <id>nexus-snapshots</id>
        <mirrorOf>*</mirrorOf>
        <url>http://192.168.56.5:8081/repository/maven-releases/</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>nexus-releases</id>
          <url>http://nexus-releases</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-releases</id>
          <url>http://nexus-releases</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>
  
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

3.1.3 使用方式二:修改的项目的 pom.xml文件

两种方式都可以使用

<repositories>
        <repository>
            <id>aliyun-repos</id>
            <url>http://192.168.56.5:8081/repository/maven-public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>aliyun-plugin</id>
            <url>http://192.168.56.5:8081/repository/maven-public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
3.2 Npm仓库配置
3.2.1 添加Blob Stores

仓库名称:npm-store
在这里插入图片描述

3.2.2 添加 npm-hosted

仓库名称:npm-hosted
在这里插入图片描述

3.2.3 添加 npm-proxy

仓库名称:npm-proxy
代理仓库地址:https://registry.npm.taobao.org
在这里插入图片描述

3.2.4 添加 npm-group

在这里插入图片描述

3.2.5 添加 node-sass代理

选择类型:raw(proxy)
仓库名称:node-sass
代理仓库地址:https://npm.taobao.org/mirrors/node-sass/
在这里插入图片描述

3.2.5 添加 node-sass代理

设置npm镜像地址

npm config set registry=http://192.168.56.5:8081/repository/npm-group/

设置node-sass镜像地址

npm config set sass_binary_site=http://192.168.56.5:8081/repository/node-sass/
3.3 Docker仓库配置
3.3.1 添加 docker-store

在这里插入图片描述

3.3.2 添加 docker-hosted仓库

在这里插入图片描述在这里插入图片描述

3.3.3 修改 /etc/docker/daemon.json
{
   "insecure-registries" : [
        "192.168.56.5:8082"
    ]
}

重启docker

systemctl restart docker
3.3.4 上传这个镜像到刚刚搭建的私服

修改已下载的redis镜像Tag

docker tag redis:5.0.3 192.168.56.5:8082/redis:5.0.3

push镜像到私服

docker push 192.168.56.5:8082/redis:5.0.3
3.3.5 下拉私服的镜像
[root@localhost ~]# docker pull 192.168.56.5:8082/redis:5.0.3
5.0.3: Pulling from redis
f7e2b70d04ae: Pull complete 
421427137c28: Pull complete 
4af7ef63ef0f: Pull complete 
b858087b3517: Pull complete 
2aaf1944f5eb: Pull complete 
8270b5c7b90d: Pull complete 
Digest: sha256:b33e5a3c00e5794324fad2fab650eadba0f65e625cc915e4e57995590502c269
Status: Downloaded newer image for 192.168.56.5:8082/redis:5.0.3
192.168.56.5:8082/redis:5.0.3
3.4 yum仓库配置
3.4.1 添加 yum-store

在这里插入图片描述

3.4.2 添加 yum-hosted 仓库

在这里插入图片描述

3.4.3 添加 yum-proxy 仓库

代理仓库地址:

http://mirrors.aliyun.com/centos/

在这里插入图片描述

3.4.4 添加 yum-group 仓库

在这里插入图片描述

在这里插入图片描述

4、Nexus迁移

拷贝 nexus-3.37.3-02 、sonatype-work 两个文件夹到服务器。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值