docker安装nexus私服

1 简介

 在从事Java开发的这一年来,因为多提供REST服务,因此使用了Spring Boot框架来开发,随着动态语言的流行(Ruby, Groovy, Scala, Node.js),Java的开发格外的笨重,繁多的配置、低下的开发效率、复杂的部署流程以及第三方技术集成难度较大。在上述环境下,Spring Boot应运而生。它使用“习惯优于配置”(项目中存在大量的配置,此外还内置一个习惯性的配置,让你无须手动进行配置)的理念让你的项目快速运行起来。而多使用的是使用Spring Boot开发REST服务。
Maven作为跨平台的项目管理工具,主要服务于基于Java平台的项目构建、依赖管理和项目信息管理,了解Maven需要了解构建的过程。
 构建(build)几乎是每一位程序员每天都在做的工作。早上来到公司,我们做的第一件事情就是从源码库签出最新的源码,然后进行单元测试,如果发现失败的测试,会找相关的同事一起调试,修复错误代码。接着回到自己的工作上,编写自己的单元测试及产品代码,生成项目测试文档,诸如像模像样的测试覆盖率报告,然后使用IDE生成一个war包,部署到web容器下,启动容器,等这个过程即为构建的过程。
在这里插入图片描述

Maven是优秀的构建工具,具有如下优点:
在这里插入图片描述
上图使用了XMind对Maven的强大之处进行了总结。

2 Maven

2.1 Nexus私服

 有三种专门的Maven仓库管理软件可以用来帮助大家建立私服:Apache基金会的Archiva、JFrog的Artifactory和Sonatype的Nexus。而Nexus是当前最流行的Maven仓库管理工具。
 私服是一种特殊的远程仓库,它是架设在局域网内的仓库服务,私服代理广域网上的远程仓库。供局域网内的Maven用户使用。当Maven需要下载构件的时候,它从私服请求,如果私服上不存在该构件,则从远程仓库下载,缓存在私服上以后,再为Maven的下载请求提供服务。此外,一些无法从外部仓库下载到的构件也能从本地上传到私服上供大家服务。
在这里插入图片描述
 私服的工作原理容如下图所示:
在这里插入图片描述

2.2 Docker

 Docker是一个轻量级容器技术,类似于虚拟机技术(xen,kvm,vmware,virtualbox).Docker是直接运行在当前操作系统(Linux)智商,而不是运行在虚拟机中国,但也实现了虚拟机技术的资源隔离,性能远远高于虚拟机技术。
在这里插入图片描述
 Docker支持将软件编译成一个镜像(image),在这个镜像里做好对软件的各种配置,然后发布这个镜像,使用者可以运行这个镜像,运行中的镜像称之为容器(container),容器的启动非常快,一般都是秒级的。
 目前各大主流云计算平台都支持Docker容器技术,包括阿里云、百度云、Cloud Foundry、HeroKu、OpenShhift、Deis,连微软下一个版本的Windows Server及其云平台Azure上也支持Docker。
 这里云计算平台一般指Paas(平台即服务),它是这样的一个云计算:平台提供了存储、数据库、网络、负载均衡、自动扩展等功能。目前主流的软件以及非主流的软件大部分都有人将其封装成Docker镜像,只需要下载好Docker镜像,然后运行镜像就可以快速获得已做好配置可运行的软件。
3 材料

可以连接外网的centos
内外网相同的centos
两个centos均安装了相同版本的docker、sonatype/nexus
一台与外网同局域网的部署了IDEA的电脑

4 私服搭建过程

4.1 外网操作

4.1.1 下载和安装docker

使用yum命令下载相应的包。

[root@localhost docker]# yum install --downloadonly --downloaddir=. docker
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-74.git6e3bb8e.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
 Package                 Arch                    Version                                               Repository               Size
=====================================================================================================================================
Installing:
 docker                  x86_64                  2:1.13.1-74.git6e3bb8e.el7.centos                     extras                   16 M

Transaction Summary
=====================================================================================================================================
Install  1 Package

Total download size: 16 M
Installed size: 57 M
Background downloading packages, then exiting:
docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64.rpm                                                             |  16 MB  00:00:35     
exiting because "Download Only" specified

在外网安装docker。

[root@localhost docker]# yum -y install docker
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-74.git6e3bb8e.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
 Package                 Arch                    Version                                               Repository               Size
=====================================================================================================================================
Installing:
 docker                  x86_64                  2:1.13.1-74.git6e3bb8e.el7.centos                     extras                   16 M

Transaction Summary
=====================================================================================================================================
Install  1 Package

Total download size: 16 M
Installed size: 57 M
Downloading packages:
docker-1.13.1-74.git6e3bb8e.el FAILED                                          
http://mirrors.zju.edu.cn/centos/7.5.1804/extras/x86_64/Packages/docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64.rpm: [Errno 12] Timeout on http://mirrors.zju.edu.cn/centos/7.5.1804/extras/x86_64/Packages/docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64.rpm: (28, 'Resolving timed out after 30568 milliseconds')
Trying other mirror.
docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64.rpm                                                             |  16 MB  00:00:39     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64                                                                   1/1 
  Verifying  : 2:docker-1.13.1-74.git6e3bb8e.el7.centos.x86_64                                                                   1/1 

Installed:
  docker.x86_64 2:1.13.1-74.git6e3bb8e.el7.centos                                                                                    

Complete!

4.1.2 禁用SELinux

修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled

[root@localhost docker]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
[root@localhost docker]# reboot 

通过reboot命令重启电脑即可。

4.1.3 配置docker国内源

外网配置docker国内源,默认国外的下载太慢。

[root@localhost docker]# vim /etc/docker/daemon.json
配置内容如下:
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

注意:此处可使用阿里源,具体配置方式参见docker通过修改配置文件使用阿里云镜像

4.1.4 启动docker并拉取nexus镜像

[root@localhost /]# systemctl restart docker 重启docker服务
[root@localhost /]# docker pull sonatype/nexus3   拉取nexus3
Using default tag: latest
Trying to pull repository docker.io/sonatype/nexus3 ... 
latest: Pulling from docker.io/sonatype/nexus3
Digest: sha256:19d186d5bc8be1ea4f7bae72756baa830e79bf20aae0e9e7b1a0c7d3ce7ac136
Status: Image is up to date for docker.io/sonatype/nexus3:latest
# 由于之前已经下载过,因此Status为Imaeg is up to date for docker.io/sonatype/nexus3:latest。表示已经下载过该镜像

4.1.5 保存镜像

首先查看一下本地的镜像,使用docker images命令。
对于没有私有仓库来说,将本地镜像放到其它服务器上执行时,我们可以使用save和load方法,前者用来把镜像保存一个tar文件,后台从一个tar文件恢复成一个镜像,这个功能对于我们开发者来说还是很方便的!

[root@localhost tmp]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/sonatype/nexus3   latest              777b20c20405        2 weeks ago         505 MB

[root@localhost tmp]# docker save -o nexus_iso.tar sonatype/nexus3
[root@localhost tmp]# ls
abrt
docker
nexus_iso.tar

可以看到nexus_iso.tar压缩包已经生成了。之后则可以在内网使用docker load命令把压缩包转换成镜像。

4.1.6 创建数据目录,关联启动nexus镜像,创建容器

首先创建数据目录
[root@localhost nexus-data]mkdir –p  /usr/nexus-data
[root@localhost nexus-data]# pwd
/usr/nexus-data
[root@localhost nexus-data] chown –R 200 /usr/nexus-data

注意:chown很关键,不然会报错问题总结

使用下载的镜像通过docker命令创建容器

[root@localhost tmp]# docker run -d -p 8081:8081 --name nexus -v /usr/nexus-data:/nexus-data sonatype/nexus3
/usr/bin/docker-current: Error response from daemon: Conflict. The container name "/nexus" is already in use by container b24e7dcd1aa99a3ef8c6c25860de5b0e6022a32fda31e54789161f477e08f756. You have to remove (or rename) that container to be able to reuse that name..
See '/usr/bin/docker-current run --help'.
[root@localhost tmp]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS                    NAMES
b24e7dcd1aa9        sonatype/nexus3     "sh -c ${SONATYPE_..."   17 hours ago        Exited (255) 49 minutes ago   0.0.0.0:8081->8081/tcp   nexus
[root@localhost tmp]# docker start b24e7dcd1aa9
b24e7dcd1aa9
[root@localhost tmp]#

此时既可以通过网页进行访问nexus,即私服网页
访问网址虚拟机IP:8081,由于本次安装的虚拟机IP为192.168.0.165,如下访问:
在这里插入图片描述

192.168.0.165:8081

4.1.7 修改中央仓库代理配置

登陆网页,用户名为admin,密码为admin123
点击

settings->Repository->Repositories

,弹出如下界面:
在这里插入图片描述
点击maven-central修改:
修改Remote storage:

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

在这里插入图片描述

然后保存访问私服的url即可
在这里插入图片描述

4.2 触发下载

4.2.1 IDEA触发下载

打开IDEA配置自定义的settings.xml,settings.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>C:\apache-maven-3.3.9\conf\repository</localRepository>
  <mirrors>
	<mirror>
		<id>my mavenn</id>
		<name>my maven</name>
		<url>http://192.168.0.165:8081/repository/maven-central/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
	
  </mirrors>
</settings>

注意:settings.xml文件中中的url 地址为虚拟机的ip,此处url获得参见4.1.7修改中央仓库代理配置

在IDEA中配置自定义的settings.xml文件。
在这里插入图片描述

4.2.2 Import Changes

在pom.xml文件上,右击maven->Reimport,即可看到正在私服下载相关依赖,如果私服不存在,即会从阿里云上下载到私服。
在这里插入图片描述
此时可以看到很多标红的,是因为自己把本地仓库删掉,IDEA找不到相应的库。使用命令Import Changes触发下载依赖
待下载完成,则会变成黑色。

4.3 mvn 命令触发下载

在此演示使用mvn 命令下载fastjson-1.2.32.jar。
首先修改POM,在中添加fastjson-1.2.32的依赖,确保基本坐标正确。

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.cetc52</groupId>
  <artifactId>download</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>download</name>
  <url>http://maven.apache.org</url>
  
 
 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
	<dependency>
		<groupId>com.alibaba</groupId>
		<artifactId>fastjson</artifactId>
		<version>1.2.32</version>
	</dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

在POM所在目录执行如下的命令

mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true

此命令会同时拉取依赖,sources和javadoc

D:\Git\test\download>mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.cetc52:download >-------------------------
[INFO] Building download 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from nexus: http://172.20.10.4:8081/repository/maven-central/com/alibaba/fastjson/1.2.32/fastjson-1.2.32.pom

Downloaded from nexus: http://172.20.10.4:8081/repository/maven-central/com/alibaba/fastjson/1.2.32/fastjson-1.2.32.pom
(4.9 kB at 2.6 kB/s)
Downloading from nexus: http://172.20.10.4:8081/repository/maven-central/com/alibaba/fastjson/1.2.32/fastjson-1.2.32.jar

Downloaded from nexus: http://172.20.10.4:8081/repository/maven-central/com/alibaba/fastjson/1.2.32/fastjson-1.2.32.jar
(466 kB at 266 kB/s)
[INFO]
[INFO] --- maven-dependency-plugin:2.8:sources (default-cli) @ download ---
Downloading from nexus: http://172.20.10.4:8081/repository/maven-central/com/alibaba/fastjson/1.2.32/fastjson-1.2.32-sou
rces.jar
Downloaded from nexus: http://172.20.10.4:8081/repository/maven-central/com/alibaba/fastjson/1.2.32/fastjson-1.2.32-sour
ces.jar (303 kB at 243 kB/s)
Downloading from nexus: http://172.20.10.4:8081/repository/maven-central/junit/junit/3.8.1/junit-3.8.1-sources.jar
Downloaded from nexus: http://172.20.10.4:8081/repository/maven-central/junit/junit/3.8.1/junit-3.8.1-sources.jar (58 kB
 at 77 kB/s)
[INFO]
[INFO] The following files have been resolved:   # 已解决依赖
[INFO]    com.alibaba:fastjson:jar:sources:1.2.32:compile
[INFO]    junit:junit:jar:sources:3.8.1:test
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.083 s
[INFO] Finished at: 2019-06-09T20:21:29+08:00
[INFO] ------------------------------------------------------------------------

D:\Git\test\download>
D:\Git\test\download>

4.4 验证

4.4.1 验证1 本地仓库新增依赖

之前自己删除了本地仓库

C:\apache-maven-3.3.9\conf\repositorycat

待下载完成之后可以看到:
在这里插入图片描述

4.4.2 验证2私服中可检索到依赖

浏览私服网址
在这里插入图片描述
至此,就已经在私服下载了一些包
在这里插入图片描述

4.4.3 验证3 fastjson-1.2.32.jar

在这里插入图片描述
点击进去,可以查看到sources和jar同时下了下来。
在这里插入图片描述
此时便可以把私服挪进内网了。还要进行如下的步骤:

4.5 打包依赖数据

由于目录/usr/nexus-data目录为由镜像nexus所起的容器的关联容器,因此,只要把该数据目录打包,拷贝进入内网。
首先stop容器

[root@localhost nexus-data]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
b24e7dcd1aa9        sonatype/nexus3     "sh -c ${SONATYPE_..."   18 hours ago        Up 50 minutes       0.0.0.0:8081->8081/tcp   nexus
[root@localhost nexus-data]# docker stop b24e7dcd1aa9
b24e7dcd1aa9

然后执行tar命令把数据目录备份

[root@localhost nexus-data]# pwd
/usr/nexus-data
[root@localhost nexus-data]# tar cvf nexus.tar /some
/usr/nexus-data/cache/bundle96/bundle.info
/usr/nexus-data/cache/bundle96/version0.0/
/usr/nexus-data/cache/bundle96/version0.0/bundle.jar
/usr/nexus-data/cache/bundle96/version0.0/revision.location
/usr/nexus-data/cache/bundle97/
/usr/nexus-data/cache/bundle97/bundle.info
/usr/nexus-data/cache/bundle97/version0.0/
/usr/nexus-data/cache/bundle97/version0.0/bundle.jar
/usr/nexus-data/cache/bundle97/version0.0/revision.location
/usr/nexus-data/cache/bundle98/
/usr/nexus-data/cache/bundle98/bundle.info
/usr/nexus-data/cache/bundle98/version0.0/

然后把所有的文件拷贝进入内网,拷贝的材料如下:

  • 下载不安装的docker
  • 打包的/usr/nexus-data目录nexus.tar
  • docker命令导出的镜像tar包

4.6 内网操作

在相同Centos版本比如在开发机安装的Centos版本如下:

[root@localhost docker]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)

确保内外网的Centos版本一致。

4.6.1 安装docker

首先要在内网安装docker,cd到rpm所在目录
执行命令

 [root@localhost tmp]# rpm -Uvh *
warning: audit-2.8.1-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
preparing…                      ############################### [100%]
Updating / installing…
	1:libsepol-2.5-8.1.el7             ############################## [100%]
	2:libselinux-2.5-l2.el7             ##############################  [100%]3:docker-2:1.13.1-63.git94f4240.el7 ################################### [100%]
	

使用docker load –i nexus_iso.tar,装载镜像。

[root@localhost ~]# docker load -i nexus.tar
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

该问题遇到,请重启docker服务

[root@localhost ~]# service docker restart
Redirecting to /bin/systemctl restart  docker.service
[root@localhost ~]# docker load -i nexus_iso.tar
1d31b5806ba4: Loading layer [=======================>] 208.3MB/208.3 MB
147340bc3324: Loading layer [=======================>] 5.12 kB/5.12kB
147340bc3324: Loading layer [=======================>] 306.6 MB/306.6B
Loaded image: docker.io/sonatype/nexus3:latest

4.6.2 解压数据目录

操作如下:

tar xvf nexus.tar
mv ./some / # 拷贝到根目录下生成目录/usr/nexus-data/
chown -R 200 /usr/nexus-data/

4.6.3 运行镜像

[root@localhost ~]# doker run –d –p 8081:8081 --name -v /usr/nexus-data/:/nexus-data sonatype/nexus3
c8ffadffad126739783ff83733rj3fhfjhajfdafh8238

4.6.4 网页验证

使用内网虚拟机IP登陆sonatype nexus Repository,注意使用虚拟机ip

192.168.95.101:8081

登录名和密码依然为admin和admin123
在这里插入图片描述
这表示内部在内网已经运行成功了。

4.6.5 docker容器管理

使用docker ps -a,可以看到由镜像模板装载的容器列表。

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES
50336317ab6f        sonatype/nexus3     "sh -c ${SONATYPE_..."   2 days ago          Exited (137) 20 minutes ago     

可以使用docker restart/start/stop 50336317ab6f对该容器进行重启,停止,重新启动。

4.6.6 docker镜像管理

下载镜像
[root@kvm ~]# docker pull sonatype/nexus3
latest: Pulling from centos
 
47d44cb6f252: Already exists 
6fdebd7b0eb5: Already exists 
a63aae4d216f: Already exists 
Digest: sha256:381f21e4c7b3724c6f420b2bcfa6e13e47ed155192869a2a04fa10f944c78476
Status: Image is up to date for centos:latest
查看下载到本地的镜像
[root@kvm ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              bb3d629a7cbc        3 weeks ago         196.6 MB
删除镜像
[root@kvm ~]# docker rmi bb3d629a7cbc
Untagged: centos:test-img2
[root@kvm ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              bb3d629a7cbc        3 weeks ago         196.6 MB
test-img            latest              bb3d629a7cbc        3 weeks ago         196.6 MB

5 再次导入

再经过一段时间的开发之后,或许在外网又重新下载了许多依赖包。需要重新再次导入内网。操作如下:
将外网的数据拷贝重新拷贝进入内网

  1. 外网docker stop 容器id
  2. 外网tar命令对目录/usr/nexus-data目录压缩
  3. 把数据目录压缩包拷贝进入内网。
  4. 内网根据容器id停止运行
  5. 内网解压缩,并修改权限chown -R 200 /usr/nexus-data
  6. 内网使用命令docker run重新拉起容器运行
docker run -d -p 8081:8081 --name nexus -v /usr/nexus-data:/nexus-data sonatype/nexus3

6 问题总结

6.1 mkdir: cannot create directory ‘…/sonatype-work/nexus3/log’: Permission denied

使用

docker logs container_id

报错如下:

mkdir: cannot create directory '../sonatype-work/nexus3/log': Permission denied
mkdir: cannot create directory '../sonatype-work/nexus3/tmp': Permission denied
OpenJDK 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to No such file or directory
Warning:  Cannot open log file: ../sonatype-work/nexus3/log/jvm.log
Warning:  Forcing option -XX:LogFile=/tmp/jvm.log
java.io.FileNotFoundException: ../sonatype-work/nexus3/tmp/i4j_ZTDnGON8hezynsMX2ZCYAVDtQog=.lock (No such file or directory)
	at java.io.RandomAccessFile.open0(Native Method)
	at java.io.RandomAccessFile.open(RandomAccessFile.java:316)
	at java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)
	at com.install4j.runtime.launcher.util.SingleInstance.check(SingleInstance.java:72)
	at com.install4j.runtime.launcher.util.SingleInstance.checkForCurrentLauncher(SingleInstance.java:31)
	at com.install4j.runtime.launcher.UnixLauncher.checkSingleInstance(UnixLauncher.java:88)
	at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:67)
Unable to update instance pid: Unable to create directory /nexus-data/instances
/nexus-data/log/karaf.log (No such file or directory)
Unable to update instance pid: Unable to create directory /nexus-data/instances

解决方式:

chown –R 200 /usr/nexus-data

6.2 内网运行

在外网虚拟机上运行的虚拟机ip一般与内网虚拟机ip地址是不同的,因此当把下拉好的nexus-data(jar包数据)放进内网之后。
使用如下命令运行:

docker run -d -p 8081:8081 --name nexus -v /usr/nexus-data:/nexus-data sonatype/nexus3

比如说在内网,虚拟机和主机的ip地址分别为

192.168.1.102   虚拟机

此时,打开nexus网页,可以看到私服的url已经修改为

在这里插入图片描述

http://10.53.30.250/repository/maven-central/

应该把该私服的url写进内网的settings.xml,这样import时才会从中央仓库把jar包拉取到私服和本地仓库中,不然会出现许多的.lastUpdated文件。
在这里插入图片描述
关于此类lastUpdated的处理参见maven仓库中的LastUpdated文件生成原因及删除。

6.2.1 Window删除.lastUpdated

创建批处理文件cleanLastUpdated.bat

@echo off
rem create by NettQun
  
rem 这里写你的仓库路径
set REPOSITORY_PATH=D:\Java\maven-repository\maven-aliyun\repository
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
    echo %%i
    del /s /q "%%i"
)
rem 搜索完毕
pause

6.2.2 Linux删除.lastUpdated
创建shell脚本cleanLastUpdated.sh

# create by NettQun
 
# 这里写你的仓库路径
REPOSITORY_PATH=~/Documents/tools/repository
echo 正在搜索...
find $REPOSITORY_PATH -name "*lastUpdated*" | xargs rm -fr
echo 搜索完

7 总结

 至此,内网搭建maven私服的过程总结完毕。整个过程并不复杂。对jar包依赖的解决,maven私服的确是一个不错的方式。
  花了好久的时间,总算自己也算能够使用docker辅助自己做私服了,虽然事后才发现原来nexus网站上已经提供了war包用来方便的进行私服的管理,但这是后话了。至于如何使用war包部署的博客在之后再写吧。比较简单,只要在本地安装一个Tomcat即可,把war丢入Tomcat安装目录下的webapps下即可。至于nexus网站的介绍随后再进行吧。

8 下载

maven私服搭建.pdf

																20196921:15:58端午第三天于马塍路36
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值