惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
T
Threat Research - Cisco Blogs
N
News and Events Feed by Topic
Hacker News: Ask HN
Hacker News: Ask HN
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
Security Latest
Security Latest
Spread Privacy
Spread Privacy
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
U
Unit 42
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Scott Helme
Scott Helme
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
爱范儿
爱范儿
S
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
Latest news
Latest news
GbyAI
GbyAI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
PCI Perspectives
PCI Perspectives
Jina AI
Jina AI
AI
AI
NISL@THU
NISL@THU
I
Intezer
G
GRAHAM CLULEY
B
Blog
S
Secure Thoughts
IT之家
IT之家
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
V2EX - 技术
V2EX - 技术
Recorded Future
Recorded Future
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - James.H.Fu

PMS-授权中心 如何从现有版本1.4.8升级到element UI2.0.11 Maven私有仓库: 发布release版本报错:Return code is: 400, ReasonPhrase: Repository does not allow upd ating assets: maven-releases. spring boot + dubbo开发遇到过的异常 java,javascript中的url编码 SpringBoot favicon.ico SpringBoot 异常处理 spring boot 跨域请求 在centos 7上安装BIMServer maven 单独构建多模块项目中的单个模块 MongoDB 安装及副本集简单操作 spring-boot dubbo项目使用docker方式部署 Spring Boot和Dubbo整合 springboot 定制错误页面 centos7 sentry部署指南 静态文件服务器部署指南 开始使用ansible 2016项目开发经验总结及后续计划 - James.H.Fu - 博客园 2016工作总结
Maven私有仓库-使用docker部署Nexus - James.H.Fu - 博客园
James.H.Fu · 2017-08-23 · via 博客园 - James.H.Fu

查看官方镜像说明

建议使用nexus2,可能网上的资料这个版本居多。
我选择的是nexus3,~~~

启动容器

官方说明中提到的是使用docker直接启动。我选择用docker-compose启动。
docker-compose.yml文件如下:

  • mkdir -p /opt/nexus
  • cd /opt/nexus
  • vim docker-compose.yml
    version: '2'
    services:
      nexus3:
        image: sonatype/nexus3
        container_name: nexus3
        volumes:
          - './nexus-data:/nexus-data:rw'
        ports:
          - '8081:8081'
  • docker-compose up -d
  • docker-compose ps #查看容器启动状态

使用supervisor管理容器进程

  • vim /etc/supervisor/conf.d/nexus.conf
    [program:nexus]
    directory = /opt/nexus ; 程序的启动目录
    command=docker-compose up ; 启动命令,可以看出与手动在命令行启动的命令是一样的
    autostart = true     ; 在 supervisord 启动的时候也自动启动
    startsecs = 30        ; 启动 5 秒后没有异常退出,就当作已经正常启动了
    autorestart = true   ; 程序异常退出后自动重启
    startretries = 3     ; 启动失败自动重试次数,默认是 3
    user = root          ; 用哪个用户启动
    redirect_stderr = true  ; 把 stderr 重定向到 stdout,默认 false
    stdout_logfile_maxbytes = 20MB  ; stdout 日志文件大小,默认 50MB
    stdout_logfile_backups = 20     ; stdout 日志文件备份数
    ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
    stdout_logfile = /var/log/nexus.log
  • supervisorctl update #更新配置,就会启动新增的程序nexus
  • supervisorctl status nexus
  • cd /opt/nexus
  • docker-compose ps

访问nexus3的portal

http://0.0.0.0:18081
帐号:admin
密码:admin123
默认已经有四个maven相关的仓库,分别是maven-central,maven-releases,maven-snapshots,maven-public。其中的类型的定义如下:

  • proxy是远程仓库的代理。比如说在nexus中配置了一个central repository的proxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库 下载,然后返回给用户,相当于起到一个中转的作用。

  • hosted是宿主仓库,用户可以把自己的一些构件,deploy到hosted中,也可以手工上传构件到hosted里。比如说oracle的驱动程序,ojdbc6.jar,在central repository是获取不到的,就需要手工上传到hosted里。

  • group是仓库组,在maven里没有这个概念,是nexus特有的。目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址就可以了。

如何发布自己的构件到私有仓库中?

  • 在~/.m2/settings中增加server节点,根据需要可以添加多个server
  <servers>
	<server>
      <id>nexus-ielong</id>
      <username>admin</username>
      <password>admin123</password>
   </server>
  </servers>
  • 在项目的pom.xml/build/中配置中配置maven-deploy-plugin
    <!--发布到私有仓库依赖的插件-->
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-deploy-plugin</artifactId>
       <version>2.8.1</version>
       <executions>
          <execution>
             <id>default-deploy</id>
             <phase>deploy</phase>
             <goals>
                <goal>deploy</goal>
             </goals>
          </execution>
       </executions>
       <configuration>
            <skip>false</skip>
        </configuration>
    </plugin>

温馨提示:如果在多模块项目中,可以将不需要发布的项目配置为skip=true。比如在parent的pom.xml中增加以下内容后,所有模块都会跳过发布。

    <build>
        <plugins>
            <!--发布到私有仓库依赖的插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • 在项目的pom.xml中配置distributionManagement
    <!--发布到私有仓库的配置-->
    <distributionManagement>
		<repository>
			<id>nexus-ielong</id>
			<name>nexus-ielong-releases</name>
			<url>http://0.0.0.0:18081/repository/maven-releases/</url>
		</repository>
		<snapshotRepository>
			<id>nexus-ielong</id>
			<name>nexus-ielong-snapshots</name>
			<url>http://0.0.0.0:18081/repository/maven-snapshots/</url>
			<uniqueVersion>false</uniqueVersion>
			<layout>legacy</layout>
		</snapshotRepository>
	</distributionManagement>

其中repository.id指~/.m2/settings.xml中配置的server.id, 这两个是同一个概念,值要一致。

  • 运行pom.xml所在目录 运行发布命令
    mvn clean deploy -Dmaven.test.skip=true

如何指定使用私有仓库下载maven构件?

有两种方式,建议使用第二种方式:

  • 第一种方式:在需要引用构件的项目中添加repository配置
    <!--在项目中指定使用私有仓库或者在~/.m2/settings.xml配置全局的mirror-->
	<repositories>
		<repository>
			<id>nexus-ielong</id>
			<name>ielong Nexus Repository</name>
			<url>http://0.0.0.0:18081/repository/maven-public/</url>
		</repository>
	</repositories>
  • 第二种方式: 在~/.m2/settings中指定mirror
    <mirrors>
        <!--不再使用aliyun的镜像-->
    	<!--<mirror>
    		<id>nexus-aliyun</id>
    		<name>Nexus aliyun</name>
    		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
    		<mirrorOf>central</mirrorOf>
    	</mirror>-->
    	
    	<!--使用自己的私有镜像-->
        <mirror>
            <id>nexus-ielong</id>
            <name>nexus public group</name>
            <url>http://0.0.0.0:18081/repository/maven-public/</url>
            <mirrorof>*</mirrorof>
        </mirror>

    </mirrors>

参考文档