Nexus Repository Manager - mengliyuebai/DevOps GitHub Wiki

Nexus Repository Manager Nexus /'neksəs/ Repository Manager (https://www.sonatype.com/download-oss-sonatype) 提供了强大的仓库管理功能,构件搜索功能,它基于REST,占用较少的内存,基于简单文件系统而非数据库。常用做Maven仓库管理器,也可以做docker仓库。

一、nexus的docker版

二、nexus管理 1、Repository Management 2、Security安全 3、System菜单 三、nexus的windows版

一、nexus的docker版

1、安装 Containerization Running NXRM in a Docker container may reduce the impact of a successful attack. Without containerisation, if a malicious person succesfully exploits a service and gains root access, they could do damage to other services running on the host. On the other hand, containerising means a succesful attack on that service is restricted to the container running that service. The NXRM3 docker images can be found at: https://hub.docker.com/r/sonatype/nexus3/. docker pull sonatype/nexus3

# docker run -d -p 8081:8081 --name nexus \ -v nexus-data:/nexus-data \ --restart=always \ sonatype/nexus3

提示:创建容器的时候报错WARNING: IPv4 forwarding is disabled. Networking will not work. # vim /usr/lib/sysctl.d/00-system.conf net.ipv4.ip_forward=1 ##添加代码 # systemctl restart network #重启network服务,删除错误的容器,再次创建新容器

firewall-cmd --zone=public --add-port=8081/tcp --permanent #防火墙开放8081端口 firewall-cmd --reload #使其生效 curl -u admin:admin123 http://localhost:8081/service/metrics/ping #测试

访问:http://192.168.1.178:8081 账号admin docker inspect -f '{{.Mounts}}' nexus ##查看容器的数据卷在主机的目录 more /var/lib/docker/volumes/nexus-data/_data/admin.password ##登录界面有提示

管理用户:修改admin密码:admin321 匿名用户:匿名用户可以访问,应该禁用掉 Change the Administrative Email Address (没啥用) Configure the SMTP Settings (邮件设置) Configure Default HTTP and HTTPS Proxy Settings (没啥用) Setup a Backup procedure for your server (深入研究) docker logs -f nexus ##查看日志 docker update --restart=always nexus ##自启(docker update )

2、升级 2020年4月23日,安装版本:Sonatype Nexus Repository ManagerOSS 3.22.1-02 问题:docker版本的是直接升级镜像? 3、备份 可用宿主机映射容器内部文件目录 volumes: - /usr/local/nexus/sonatype-work/nexus/storage:/sonatype-work/storage 注意,宿主机映射的文件目录下要设置任何人可读可写权限,否则会报错 chmod -R 777 /usr/local/nexus/

二、nexus管理

1、Repository Management Blob Stores Choosing the Number of Blob Stores Estimating Blob Store Size Choosing the Blob Store Type Adding a Soft Quota Proxy Repository Hosted Repository Repository Group

实际仓库配置: Blob Stores:1个 ,说明:Blob Stores一个服务器就创建了一个,所有Repository共用。Repository由产品实际情况决定。 Repository Group:1个(1个产品一般1个就够了) Hosted Repository:1个(1个产品一般1个就够了) Proxy Repository:1+个(一般一个ailiyun代理,一个spring代理) 规范性要求: 仓库名字以产品标识开头,比如:proxy库:G1cloud-maven-aliyun、G1Cloud-maven-spring;仓库group:G1cloud-maven-group;hosted库:G1Cloud-base-jar 问题:现在两个产品都有自己的proxy仓库。如果多个产品如果共用同一个ailiyun代理,一个spring代理,会造成混乱吗?

1)Blob Stores A blob store is the internal storage mechanism for the binary parts of components and their assets. They can be local file system or cloud-based Amazon S3. Each blob store can be used by one or multiple repositories and repository groups. 了解Blob Store特性: Blob Store创建后不能修改,被Repository使用后不能被删除。删除Blob Store仅是标记删除,只有执行“The compact blob store”任 务才能真正物理删除,释放空间。Blob Store不能分拆。1个Blob Store可以多个仓库使用。Repository被分配到某个Blob Store后,也不能修改为其他Blob Store。 选择Blob Stores的数量: 一个存储设备只创建1个Blob Store:适用于仓库体积增长缓慢。(选择了此方案) 一个存储设置创建多个:预计1年内就会达到存储上限,还无法转移到更大的存储设备上。 一个Repository创建1个Blob Store:最灵活。不推荐。 为hosted仓库创建单独的Blob Store:如果考虑备份hosted,备份的时候只需要备份hosted文件夹和配置文件即可。 估算Blob Stores的大小: Blob Stores包含二进制组件( .bytes file)和属性文件(少量<1k的元数据,用于灾难恢复) The total storage size of a blob store is therefore approximately the total size of all of your components, plus an allowance for the properties files and the block size of your storage device. (On average, this will be 1.5 * # of components * block size.) 选择Blob Store类型: File blob store(选择了此方案)
S3 blob store:支持AWS 云 添加Blob Store的soft quota: 功能不是限制读写,而是在超出限制时提出警告。 2)Proxy Repository Proxy ,代理远程的公共仓库,如maven-central。代理url地址: 阿里云地址: http://maven.aliyun.com/nexus/content/groups/public Spring地址:https://repo.spring.io/milestone 官方地址: http://repo1.maven.org/maven2 3)Hosted Repository Hosted ,宿主仓库,用于部署自己的构件。如maven-releases发行版,maven-snapshots调试版,不稳定、处于开发中的版本。 提示:Deployment policy :Allow redeploy ,以允许重复发布覆盖同版本的jar包。 4)Group Group,仓库组,如maven-public,把hosted仓库和proxy组合在一起,对外提供单一的库地址,类似权限组、角色的概念。 注意:组成员排序,获取构建时从上到下访问,远程代理仓库应该放在最后。 When the repository manage searches for a component in a repository group, it will return the first match. 说明:Maven没有group的概念,hosted,proxy和group,对maven都一样,只根据 groupId,artifactId,version等信息索要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者 proxy合并成一个group,这样,Maven只需要通过一个group,便能使用所有该group包含的仓库的内容。

2、Security安全 https://help.sonatype.com/repomanager3/security Realms Privileges Roles Users Security Setup with User Tokens Authentication via Remote User Token Configuring SSL Default Role Nexus Repository Manager采用的是基于角色的访问控制。所以权限控制的关键就是如何设置角色。 实际角色设置: 每个产品的开发团队,使用团队共用的用户,访问自己创建的Repository。 规范性要求: 角色名称:依据产品标识创建;共用的用户名称:依据产品标识创建;邮箱依据产品管理者。

1)Privileges Manage 读懂Privilege的含义是,设置角色的前提。一般使用默认的Privilege即可,不用再创建新的Privilege。

  1. repository仓库的权限,包括(*、add、browse、delete、edit、read)。又分为admin管理权限和普通的view权限。
  2. nx-repository-admin---add :创建仓库(create repository)功能。
  3. nx-repository-admin---edit:编辑repository仓库
  4. nx-repository-admin---delete:删除repository仓库
  5. nx-repository-admin---read:如果分配了这个权限,就会看到所有的仓库。不要分配read权限。
  6. nx-repository-admin---browse:不明白作用?不用分配,不影响create功能,分配了也不会看到所有的仓库。
  7. nx-blobstores-read:blob store读权限,没有,在创建库的时候不能选择blob。
  8. nx-component-upload:开启Upload上传菜单,可在Web界面,上传组件到Hosted仓库。发布功能。
  9. nx-search-read:开启Search搜索菜单,可搜索仓库中的组件,jar包。
  10. nx-analytics-all:All permissions for Analytics 不知道作用?
  11. nx-apikey-all:All permissions for APIKey 在用户(点登录后显示的登录名)下,可以添加NuGet API Key
  12. nx-healthcheck-read :健康检查
  13. nx-healthcheck-summary-read:健康检查
  14. nx-healthcheck-update:开启proxy仓库的HealthCheck列的“Analyze"按钮。Click this button to request a Repository Health Check(RHC) by IQ Server. 不知道该分析按钮的真正的作用?
  15. nx-roles-all 角色权限。添加这个权限后,未显示角色菜单,不知道原因?
  16. nx-script-- :没找对应的菜单,不知道作用?
  17. nx-selectors-all:All permissions for Analytics 启用Content Selectors菜单
  18. nx-atlas-all :所有支持工具,包括分析、日志、系统信息等。
  19. nx-settings-all :包括Security(Anonymous Access和Realms)菜单、System(API、Email Server、HTTP)菜单。
  20. nx-ssl-truststore-all :SSL Certificates菜单
  21. nx-tasks-all:任务
  22. nx-users-all:用户
  23. nx-userschangepw:更改密码。建议单独设置角色。随意修改密码,可能导致已经写入到maven等配置文件中的密码,要修改。
  24. nx-wonderland-all:All permissions for Wonderland 不知道作用?
  25. nx-all :所有权限,就是管理员权限。

2)创建角色 Role ID:G1Cloud (按产品标识创建) Role name :G1Cloud Role description:G1Cloud产品使用 Privileges:在Available选项下过滤:G1Cloud 分配的权限: 选择所有包含G1Cloud字符的仓库权限。(必选,设置后,拥有仓库全部操作权限) 前提是,该产品的Repository的名字,都以G1Cloud 开头,否则只能按仓库名字逐一添加。 Role ID:Repo-admin

  1. nx-component-upload(设置后,拥有上传组件权限)
  2. nx-search-read (设置后,拥有查询组件权限)
  3. nx-repository-admin---add
  4. nx-repository-admin---edit
  5. nx-repository-admin---delete
  6. nx-blobstores-read (不设置create时候无法选择) (以上,设置后,拥有创建仓库,编辑和删除权限)
  7. nx-healthcheck-read
  8. nx-healthcheck-summary-read
  9. nx-healthcheck-update (以上设置后,拥有分析仓库健康权限) Role ID:Support
  10. nx-atlas-all (可选,设置后,拥有全部支持工具包括日志、系统信息、分析图等权限) Role ID:userpw
  11. nx-userschangepw (不设置,有修改需求的时候增加,允许用户自己修改密码权限) 说明:可以设置角色包含其他角色。

3)创建用户 ID:G1Cloud Email:[email protected] (产品管理者的邮箱) Roles:授予角色G1Cloud 、Repo-admin 192.168.6.11服务器:faspdev/faspdev123,翁跃东;G1Cloud/G1Cloud,赵孝涛

3、System管理 1)Capabilities菜单 管理Capabilitie。有些默认未显示的Capabilitie,通过create一个新Capabilitie,显示。 2)Tasks菜单 Admin-Compact blob store ,清理blob Admin-Delete orphaned API keys Admin-Execute Script Admin-Export databases for backup ,备份,执行时Repository处于只读模式。 Docker-Delete Incomplete uploads Docker-Delete unused manifests and images

5)maven项目访问 maven项目访问,见maven手册

6)nexus管理docker镜像 https://yq.aliyun.com/articles/666110?spm=5176.10695662.1996646101.searchclickresult.1017463bLE1oAg nexus 3.6做docker私服

三、nexus的windows版 nexus-3.4.0.02需要JDK1.8。 1、安装 安装Nexus之前必须配置好java环境变量。 1)官网下载,解压缩即可使用,默认仓库目录sonatype-work。Nexus内嵌了Jetty,只要有JRE就能直接运行。 2)修改默认8081端口:D:\nexus-3.4.0-02-win64\nexus-3.4.0-02\etc\nexus-default.properties application-port=8082 3)手动运行 cd D:\nexus-3.4.0-02-win64\nexus-3.4.0-02\bin nexus.exe /run

4)以服务方式运行,以管理员身份运行cmd cmd> cd D:\nexus-3.4.0-02-win64\nexus-3.4.0-02\bin cmd>nexus.exe /install Nexus Service

成功后,“服务”列表里会出现对应的服务Nexus Server 2、升级 当前版本:nexus-3.4.0.02 https://help.sonatype.com/repomanager3/upgrading/upgrade-procedures 问题:不能确定是否可以兼容以前的数据。所以至今未升级。

3、备份(windows) 提示:nexus的数据都存储在sonatype-work文件夹,主要是blobs和db目录。 方法一:备份整个物理文件夹 备份仓库:将sonatype-work文件夹整体备份即可。 还原仓库:将备份好的sonatype-work文件拷贝到新的服务器中。 window,然后修改bin/nexus.vmoptions配置文件,重新指定仓库的目录。-Dkaraf.data=../sonatype-work/nexus3 Linux,修改nexus/conf/nexus.properties配置文件,重新指定仓库的目录 方法二:利用备份task https://help.sonatype.com/repomanager3/backup-and-restore 数据存储在blob stores,元数据和配置信息存储在数据库中,必须同时备份。否则,恢复时blob存储的元数据可能无法解析。 When the Component database is restored, the corresponding blob stores containing components must also be restored. 备份、恢复步骤(同样适用于备份后迁移到新服务器): 1、备份 1)备份blobs文件夹: ..\sonatype-work\nexus3\blobs ,拷贝到备份目录。 2)备份数据库:在管理界面System-Tasks界面,点击“Create task”,选择Admin-Export databases for backup,手动执行一次备份。 component-2019-08-18-18-00-00.bak 2、恢复数据 1)停止NEXUS服务 cd E:\nexus-3.15.0-01-win64\nexus-3.15.0-01\bin nexus /stop

2)删除..\sonatype-work\nexus3\db 下的如下目录 accesslog analytics audit component config security 3)将数据库备份生成的6个.bak文件,拷贝到 ..\sonatype-work\nexus3\restore-from-backup (3.10.0版本前,叫backup)

3、导入备份的blobs到..\sonatype-work\nexus3\blobs 4、重启nexus cd E:\nexus-3.15.0-01-win64\nexus-3.15.0-01\bin nexus /start

说明: 元数据(Meta Data)是关于数据仓库的数据,指在数据仓库建设过程中所产生的有关数据源定义,目标定义,转换规则等相关的关键数据。同时元数据还包含关于数据含义的商业信息,所有这些信息都应当妥善保存。为数据仓库的发展和使用提供方便。

⚠️ **GitHub.com Fallback** ⚠️