makefile 分析 -- 内置变量及自动变量
2026/6/11 9:23:50
Nexus Repository Manager 3(简称Nexus3)是Sonatype公司推出的一款仓库管理工具,主要用于存储、管理和分发:
Nexus3的仓库类型主要分为三大类:代理仓库(Proxy Repository)、宿主仓库(Hosted Repository)和仓库组(Repository Group)。
代理仓库(Proxy Repository)
{"name":"maven-central","type":"proxy","format":"maven2","url":"https://repo.maven.apache.org/maven2","storage":{"blobStoreName":"default","strictContentTypeValidation":true},"proxy":{"remoteUrl":"https://repo.maven.apache.org/maven2","contentMaxAge":1440,"metadataMaxAge":1440},"negativeCache":{"enabled":true,"timeToLive":1440},"httpClient":{"blocked":false,"autoBlock":true,"connection":{"retries":0,"userAgentSuffix":"Nexus","timeout":60,"enableCircularRedirects":false,"enableCookies":false}}}宿主仓库(Hosted Repository)
{"name":"maven-releases","type":"hosted","format":"maven2","online":true,"storage":{"blobStoreName":"default","writePolicy":"ALLOW_ONCE",// 防止覆盖"strictContentTypeValidation":true},"cleanup":{"policyNames":["weekly-cleanup"]},"maven":{"versionPolicy":"RELEASE",// RELEASE, SNAPSHOT 或 MIXED"layoutPolicy":"STRICT"// STRICT 或 PERMISSIVE}}仓库组(Repository Group)
{"name":"maven-public","type":"group","format":"maven2","online":true,"storage":{"blobStoreName":"default","strictContentTypeValidation":true},"group":{"memberNames":["maven-releases","maven-snapshots","maven-central","third-party"]}}Nexus3 支持多种包管理格式:
Maven 仓库
# 配置示例maven-central(proxy)# Maven中央仓库代理maven-releases(hosted)# 内部发布版本maven-snapshots(hosted)# 内部快照版本maven-public(group)# 聚合所有Maven仓库Docker 仓库
# 类型docker-hosted# 存储内部Docker镜像docker-proxy# 代理Docker Hub/Registrydocker-group# 聚合多个Docker仓库# 配置要点- 需要配置HTTP/HTTPS端口 - 支持Blob存储优化 - 可配置清理策略NPM 仓库
# 类型npm-proxy# 代理npm官方仓库npm-hosted# 存储私有npm包npm-group# 聚合npm仓库# 使用示例npmconfigsetregistry http://nexus:8081/repository/npm-group/# 拉取 Nexus3 官方镜像docker pull sonatype/nexus3:latest# 创建数据目录(用于持久化存储mkdir-p /usr/local/src/nexus/nexus-datachmod777/usr/local/src/nexus/nexus-data基础运行命令
# 最简单的方式docker run -d --name nexus3 -p8081:8081 sonatype/nexus3# 推荐方式(挂载数据卷)docker run -d\--name nexus3\-p8081:8081\-v nexus-data:/nexus-data\sonatype/nexus3:latest完整配置命令(生产环境推荐)
docker run -d\--name nexus3\--restart unless-stopped\-p8081:8081\-p5000:5000\# Docker 仓库端口(可选)-v /usr/local/src/nexus/nexus-data:/nexus-data\-v /etc/localtime:/etc/localtime:ro\-eINSTALL4J_ADD_VM_PARAMS="-Xms256M -Xmx512M -XX:MaxDirectMemorySize=1g"\-eNEXUS_CONTEXT="/"\sonatype/nexus3:latest-d:后台运行--name nexus3:容器名称--restart unless-stopped:自动重启策略,其他选项:no(不重启)、always(总是重启)、on-failure(失败时重启)-p 8081:8081:映射 Web 管理端口:主机8081 -> 容器8081-p 5000:5000:Docker 私有仓库端口-v nexus-data:/nexus-data:挂载数据卷(持久化存储),将主机目录挂载到容器内-v /etc/localtime:/etc/localtime:ro:时区同步,将主机的时区文件挂载到容器内-e INSTALL4J_ADD_VM_PARAMS:JVM 内存参数设置-e NEXUS_CONTEXT="/":上下文路径(默认为根目录)# 查看容器日志,找到初始密码docker logs nexus3|grep"admin.password"# 或者直接查看文件dockerexecnexus3cat/nexus-data/admin.password禁用匿名访问
设置 → Security → Anonymous Access 取消勾选"Allow anonymous users to access the server"创建用户
设置 → Security → Users → Createlocaluser 填写:ID、First Name、Last Name、Email、Password 选择 Role:nx-admin(管理员权限)创建宿主仓库(Hosted)
创建仓库组(Group)
启用 Docker 仓库
设置 → Repository → Repositories → Create repository 选择 docker(hosted)配置 Docker 仓库
Name: docker-hosted HTTP:8082# 注意此端口需要与容器映射端口一致Deployment policy: Allow redeployMaven 配置
<settings><servers><server><id>nexus</id><username>deployment</username><password>your-password</password></server></servers><mirrors><mirror><id>nexus</id><mirrorOf>*</mirrorOf><url>http://localhost:8081/repository/maven-public/</url></mirror></mirrors></settings>项目 pom.xml 配置:
<distributionManagement><repository><id>nexus</id><name>Releases</name><url>http://localhost:8081/repository/maven-releases/</url></repository><snapshotRepository><id>nexus</id><name>Snapshots</name><url>http://localhost:8081/repository/maven-snapshots/</url></snapshotRepository></distributionManagement>发布和拉取
# 发布到 Nexusmvn clean deploy# 从 Nexus 拉取依赖mvn cleaninstall配置 Docker 客户端
# 1. 配置 insecure-registries(Linux/Mac)sudovim/etc/docker/daemon.json{"insecure-registries":["localhost:8082"]}# 重启 Dockersudosystemctl restart docker# 2. 登录到 Nexusdocker login localhost:8082# 用户名/密码:Nexus 创建的用户推送/拉取镜像
# 1. 给镜像打标签docker tag my-image:latest localhost:8082/my-image:latest# 2. 推送到 Nexusdocker push localhost:8082/my-image:latest# 3. 从 Nexus 拉取docker pull localhost:8082/my-image:latest# 4. 拉取远程镜像(通过代理)# Nexus 会自动缓存 Docker Hub 的镜像docker pull localhost:8082/library/nginx:latest设置 → Security → Roles 设置 → Security → Privileges设置 → Security → LDAP设置 → Repository → Cleanup Policies设置 → System → Capabilities → Webhook配置事件通知,如: