使用基础架构即代码方法安装和配置 Nexus Sonatype

Sonatype Nexus 是一个集成平台,开发人员可以通过它代理、存储和管理 Java (Maven) 依赖项、Docker、Python、Ruby、NPM、Bower 映像、RPM 包、gitlfs、Apt、Go、Nuget,并分发其软件安全性。

为什么需要 Sonatype Nexus?

  • 用于存放私人物品;
  • 用于缓存从 Internet 下载的工件;

基本 Sonatype Nexus 包中支持的工件:

  • Java、Maven(jar)
  • 码头工人
  • Python(点)
  • 红宝石(宝石)
  • NPM
  • 鲍尔
  • 嗯(转)
  • 吉特夫
  • 公寓(德布)
  • Go
  • 努吉特

社区支持的工件:

  • 作曲家
  • 柯南
  • CPAN
  • 埃尔帕
  • 头盔
  • P2
  • R

使用以下命令安装 Sonatype Nexus https://github.com/ansible-ThoTeam/nexus3-oss

需求

  • 在 Internet 上阅读有关使用 ansible 的信息。
  • 安装ansible pip install ansible 在运行 playbook 的工作站上。
  • 吉尔林盖伊.java 在运行 playbook 的工作站上。
  • geerlingguy.apache 在运行 playbook 的工作站上。
  • 该角色已在 CentOS 7、Ubuntu Xenial (16.04) 和 Bionic (18.04)、Debian Jessie 和 Stretch 上进行了测试
  • jmespath 该库必须安装在运行 playbook 的工作站上。 安装: sudo pip install -r requirements.txt
  • 将 playbook 文件(如下示例)保存到 nexus.yml 文件
  • 运行 Nexus 安装 ansible-playbook -i host nexus.yml

用于在没有 LDAP 的情况下使用 Maven (java)、Docker、Python、Ruby、NPM、Bower、RPM 和 gitlfs 存储库安装 nexus 的示例 ansible-playbook。

---
- name: Nexus
  hosts: nexus
  become: yes

  vars:
    nexus_timezone: 'Asia/Omsk'
    nexus_admin_password: "admin123"
    nexus_public_hostname: 'apatsev-nexus-playbook'
    httpd_setup_enable: false
    nexus_privileges:
      - name: all-repos-read
        description: 'Read & Browse access to all repos'
        repository: '*'
        actions:
          - read
          - browse
      - name: company-project-deploy
        description: 'Deployments to company-project'
        repository: company-project
        actions:
          - add
          - edit
    nexus_roles:
      - id: Developpers # maps to the LDAP group
        name: developers
        description: All developers
        privileges:
          - nx-search-read
          - all-repos-read
          - company-project-deploy
        roles: []
    nexus_local_users:
      - username: jenkins # used as key to update
        first_name: Jenkins
        last_name: CI
        email: [email protected]
        password: "s3cr3t"
        roles:
          - Developpers # role ID here
    nexus_blobstores:
      - name: company-artifacts
        path: /var/nexus/blobs/company-artifacts
    nexus_scheduled_tasks:
      - name: compact-blobstore
        cron: '0 0 22 * * ?'
        typeId: blobstore.compact
        taskProperties:
          blobstoreName: 'company-artifacts'

    nexus_repos_maven_proxy:
      - name: central
        remote_url: 'https://repo1.maven.org/maven2/'
        layout_policy: permissive
      - name: jboss
        remote_url: 'https://repository.jboss.org/nexus/content/groups/public-jboss/'
      - name: vaadin-addons
        remote_url: 'https://maven.vaadin.com/vaadin-addons/'
      - name: jaspersoft
        remote_url: 'https://jaspersoft.artifactoryonline.com/jaspersoft/jaspersoft-repo/'
        version_policy: mixed
    nexus_repos_maven_hosted:
      - name: company-project
        version_policy: mixed
        write_policy: allow
        blob_store: company-artifacts
    nexus_repos_maven_group:
      - name: public
        member_repos:
          - central
          - jboss
          - vaadin-addons
          - jaspersoft

    # Yum. Change nexus_config_yum to true for create yum repository
    nexus_config_yum: true
    nexus_repos_yum_hosted:
      - name: private_yum_centos_7
        repodata_depth: 1
    nexus_repos_yum_proxy:
      - name: epel_centos_7_x86_64
        remote_url: http://download.fedoraproject.org/pub/epel/7/x86_64
        maximum_component_age: -1
        maximum_metadata_age: -1
        negative_cache_ttl: 60
      - name: centos-7-os-x86_64
        remote_url: http://mirror.centos.org/centos/7/os/x86_64/
        maximum_component_age: -1
        maximum_metadata_age: -1
        negative_cache_ttl: 60
    nexus_repos_yum_group:
      - name: yum_all
        member_repos:
          - private_yum_centos_7
          - epel_centos_7_x86_64

    # NPM. Change nexus_config_npm to true for create npm repository
    nexus_config_npm: true
    nexus_repos_npm_hosted: []
    nexus_repos_npm_group:
      - name: npm-public
        member_repos:
          - npm-registry
    nexus_repos_npm_proxy:
      - name: npm-registry
        remote_url: https://registry.npmjs.org/
        negative_cache_enabled: false

    # Docker. Change nexus_config_docker to true for create docker repository
    nexus_config_docker: true
    nexus_repos_docker_hosted:
      - name: docker-hosted
        http_port: "{{ nexus_docker_hosted_port }}"
        v1_enabled: True
    nexus_repos_docker_proxy:
      - name: docker-proxy
        http_port: "{{ nexus_docker_proxy_port }}"
        v1_enabled: True
        index_type: "HUB"
        remote_url: "https://registry-1.docker.io"
        use_nexus_certificates_to_access_index: false
        maximum_component_age: 1440
        maximum_metadata_age: 1440
        negative_cache_enabled: true
        negative_cache_ttl: 1440
    nexus_repos_docker_group:
      - name: docker-group
        http_port: "{{ nexus_docker_group_port }}"
        v1_enabled: True
        member_repos:
          - docker-hosted
          - docker-proxy

    # Bower. Change nexus_config_bower to true for create bower repository
    nexus_config_bower: true
    nexus_repos_bower_hosted:
      - name: bower-hosted
    nexus_repos_bower_proxy:
      - name: bower-proxy
        index_type: "proxy"
        remote_url: "https://registry.bower.io"
        use_nexus_certificates_to_access_index: false
        maximum_component_age: 1440
        maximum_metadata_age: 1440
        negative_cache_enabled: true
        negative_cache_ttl: 1440
    nexus_repos_bower_group:
      - name: bower-group
        member_repos:
          - bower-hosted
          - bower-proxy

    # Pypi. Change nexus_config_pypi to true for create pypi repository
    nexus_config_pypi: true
    nexus_repos_pypi_hosted:
      - name: pypi-hosted
    nexus_repos_pypi_proxy:
      - name: pypi-proxy
        index_type: "proxy"
        remote_url: "https://pypi.org/"
        use_nexus_certificates_to_access_index: false
        maximum_component_age: 1440
        maximum_metadata_age: 1440
        negative_cache_enabled: true
        negative_cache_ttl: 1440
    nexus_repos_pypi_group:
      - name: pypi-group
        member_repos:
          - pypi-hosted
          - pypi-proxy

    # rubygems. Change nexus_config_rubygems to true for create rubygems repository
    nexus_config_rubygems: true
    nexus_repos_rubygems_hosted:
      - name: rubygems-hosted
    nexus_repos_rubygems_proxy:
      - name: rubygems-proxy
        index_type: "proxy"
        remote_url: "https://rubygems.org"
        use_nexus_certificates_to_access_index: false
        maximum_component_age: 1440
        maximum_metadata_age: 1440
        negative_cache_enabled: true
        negative_cache_ttl: 1440
    nexus_repos_rubygems_group:
      - name: rubygems-group
        member_repos:
          - rubygems-hosted
          - rubygems-proxy

    # gitlfs. Change nexus_config_gitlfs to true for create gitlfs repository
    nexus_config_gitlfs: true
    nexus_repos_gitlfs_hosted:
      - name: gitlfs-hosted

  roles:
    - { role: geerlingguy.java }
    # Debian/Ubuntu only
    # - { role: geerlingguy.apache, apache_create_vhosts: no, apache_mods_enabled: ["proxy_http.load", "headers.load"], apache_remove_default_vhost: true, tags: ["geerlingguy.apache"] }
    # RedHat/CentOS only
    - { role: geerlingguy.apache, apache_create_vhosts: no, apache_remove_default_vhost: true, tags: ["geerlingguy.apache"] }
    - { role: ansible-thoteam.nexus3-oss, tags: ['ansible-thoteam.nexus3-oss'] }

屏幕截图:

使用基础架构即代码方法安装和配置 Nexus Sonatype

使用基础架构即代码方法安装和配置 Nexus Sonatype

可变角色

角色变量

具有默认值的变量(参见 default/main.yml):

一般变量

    nexus_version: ''
    nexus_timezone: 'UTC'

默认情况下,该角色将安装最新可用版本的 Nexus。 您可以通过更改变量来修复版本 nexus_version。 查看可用版本: https://www.sonatype.com/download-oss-sonatype.

如果您更改为较新的版本,该角色将尝试更新您的 Nexus 安装。

如果您使用的 Nexus 版本比最新版本旧,则应确保您没有使用已安装版本中不可用的功能(例如,托管 yum 存储库适用于高于 3.8.0 的 Nexus,git lfs repo对于大于 3.3.0 的 Nexus 等)

nexus timezone 是 Java 时区的名称,与以下 cron 表达式结合使用可用于 nexus_scheduled 任务。

Nexus 端口和上下文路径

    nexus_default_port: 8081
    nexus_default_context_path: '/'

Java连接进程的端口和上下文路径。 nexus_default_context_path 设置时必须包含正斜杠,例如: nexus_default_context_path: '/nexus/'.

Nexus 操作系统用户和组

    nexus_os_group: 'nexus'
    nexus_os_user: 'nexus'

如果缺少的话,用于拥有 Nexus 文件和运行服务的用户和组将由角色创建。

    nexus_os_user_home_dir: '/home/nexus'

允许更改 Nexus 用户的默认主目录

Nexus 实例目录

    nexus_installation_dir: '/opt'
    nexus_data_dir: '/var/nexus'
    nexus_tmp_dir: "{{ (ansible_os_family == 'RedHat') | ternary('/var/nexus-tmp', '/tmp/nexus') }}"

Nexus 目录。

  • nexus_installation_dir 包含已安装的可执行文件
  • nexus_data_dir 包含所有配置、存储库和下载的工件。 自定义 blobstore 路径 nexus_data_dir 可以定制,见下图 nexus_blobstores.
  • nexus_tmp_dir 包含所有临时文件。 redhat 的默认路径已从 /tmp 克服自动清洁程序的潜在问题。 参见#168。

配置 Nexus JVM 内存使用

    nexus_min_heap_size: "1200M"
    nexus_max_heap_size: "{{ nexus_min_heap_size }}"
    nexus_max_direct_memory: "2G"

这些是 Nexus 的默认设置。 请不要更改这些值 如果你还没有读过 Nexus 系统要求内存部分 并且不明白他们在做什么。

作为第二个警告,以下是上述文档的摘录:

不建议为了提高性能而将 JVM 堆内存增加到超过建议值。 这实际上可能会产生相反的效果,导致操作系统做不必要的工作。

管理员密码

    nexus_admin_password: 'changeme'

用于设置的“admin”帐户密码。 这仅适用于第一次默认安装。 如果您想稍后使用角色更改管理员密码,请参阅[首次安装后更改管理员密码](#change-admin-password-after-first-install)。

强烈建议不要在 playbook 中以明文形式存储密码,而是使用 [ansible-vault 加密] (https://docs.ansible.com/ansible/latest/user_guide/vault.html) (内联或在加载有例如 include_vars 的单独文件中)

默认匿名访问

    nexus_anonymous_access: false

默认情况下禁用匿名访问。 阅读更多关于 匿名访问.

公共主机名

    nexus_public_hostname: 'nexus.vm'
    nexus_public_scheme: https

Nexus 实例将可供其客户端使用的完全限定域名和方案(https 或 http)。

此角色的 API 访问权限

    nexus_api_hostname: localhost
    nexus_api_scheme: http
    nexus_api_validate_certs: "{{ nexus_api_scheme == 'https' }}"
    nexus_api_context_path: "{{ nexus_default_context_path }}"
    nexus_api_port: "{{ nexus_default_port }}"

这些变量控制角色如何连接到 Nexus API 进行配置。
仅适用于高级用户。 您可能不想更改这些默认设置

设置反向代理

    httpd_setup_enable: false
    httpd_server_name: "{{ nexus_public_hostname }}"
    httpd_default_admin_email: "[email protected]"
    httpd_ssl_certificate_file: 'files/nexus.vm.crt'
    httpd_ssl_certificate_key_file: 'files/nexus.vm.key'
    # httpd_ssl_certificate_chain_file: "{{ httpd_ssl_certificate_file }}"
    httpd_copy_ssl_files: true

SSL 反向代理.
为此,您需要安装 httpd。 注:当为 httpd_setup_enable 设定值true,nexus 联系人 127.0.0.1:8081,因此 没有 可通过 HTTP 端口 8081 从外部 IP 地址直接访问。

使用的默认主机名是 nexus_public_hostname。 如果由于某种原因需要不同的名称,您可以设置 httpd_server_name 具有不同的含义。

С httpd_copy_ssl_files: true (默认情况下)上述证书应存在于您的 playbook 目录中,并将被复制到服务器并在 apache 中进行配置。

如果您想使用服务器上现有的证书,请安装 httpd_copy_ssl_files: false 并提供以下变量:

    # These specifies to the vhost where to find on the remote server file
    # system the certificate files.
    httpd_ssl_cert_file_location: "/etc/pki/tls/certs/wildcard.vm.crt"
    httpd_ssl_cert_key_location: "/etc/pki/tls/private/wildcard.vm.key"
    # httpd_ssl_cert_chain_file_location: "{{ httpd_ssl_cert_file_location }}"

httpd_ssl_cert_chain_file_location 是可选的,如果您不想自定义链文件,则应保持未设置状态

    httpd_default_admin_email: "[email protected]"

设置默认管理员电子邮件地址

LDAP 配置

默认情况下禁用 LDAP 连接和安全领域

    nexus_ldap_realm: false
    ldap_connections: []

LDAP 连接,每个元素如下所示:

    nexus_ldap_realm: true
    ldap_connections:
      - ldap_name: 'My Company LDAP' # used as a key to update the ldap config
        ldap_protocol: 'ldaps' # ldap or ldaps
        ldap_hostname: 'ldap.mycompany.com'
        ldap_port: 636
        ldap_use_trust_store: false # Wether or not to use certs in the nexus trust store
        ldap_search_base: 'dc=mycompany,dc=net'
        ldap_auth: 'none' # or simple
        ldap_auth_username: 'username' # if auth = simple
        ldap_auth_password: 'password' # if auth = simple
        ldap_user_base_dn: 'ou=users'
        ldap_user_filter: '(cn=*)' # (optional)
        ldap_user_object_class: 'inetOrgPerson'
        ldap_user_id_attribute: 'uid'
        ldap_user_real_name_attribute: 'cn'
        ldap_user_email_attribute: 'mail'
        ldap_user_subtree: false
        ldap_map_groups_as_roles: false
        ldap_group_base_dn: 'ou=groups'
        ldap_group_object_class: 'posixGroup'
        ldap_group_id_attribute: 'cn'
        ldap_group_member_attribute: 'memberUid'
        ldap_group_member_format: '${username}'
        ldap_group_subtree: false

匿名身份验证(匿名绑定)的 LDAP 配置示例,这也是“最小”配置:

    nexus_ldap_realm: true
    ldap_connection:
      - ldap_name: 'Simplest LDAP config'
        ldap_protocol: 'ldaps'
        ldap_hostname: 'annuaire.mycompany.com'
        ldap_search_base: 'dc=mycompany,dc=net'
        ldap_port: 636
        ldap_use_trust_store: false
        ldap_user_id_attribute: 'uid'
        ldap_user_real_name_attribute: 'cn'
        ldap_user_email_attribute: 'mail'
        ldap_user_object_class: 'inetOrgPerson'

简单身份验证的 LDAP 配置示例(使用 DSA 帐户):

    nexus_ldap_realm: true
    ldap_connections:
      - ldap_name: 'LDAP config with DSA'
        ldap_protocol: 'ldaps'
        ldap_hostname: 'annuaire.mycompany.com'
        ldap_port: 636
        ldap_use_trust_store: false
        ldap_auth: 'simple'
        ldap_auth_username: 'cn=mynexus,ou=dsa,dc=mycompany,dc=net'
        ldap_auth_password: "{{ vault_ldap_dsa_password }}" # better keep passwords in an ansible vault
        ldap_search_base: 'dc=mycompany,dc=net'
        ldap_user_base_dn: 'ou=users'
        ldap_user_object_class: 'inetOrgPerson'
        ldap_user_id_attribute: 'uid'
        ldap_user_real_name_attribute: 'cn'
        ldap_user_email_attribute: 'mail'
        ldap_user_subtree: false

简单身份验证(使用 DSA 帐户)+ 映射为角色的组的 LDAP 配置示例:

    nexus_ldap_realm: true
    ldap_connections
      - ldap_name: 'LDAP config with DSA'
        ldap_protocol: 'ldaps'
        ldap_hostname: 'annuaire.mycompany.com'
        ldap_port: 636
        ldap_use_trust_store: false
        ldap_auth: 'simple'
        ldap_auth_username: 'cn=mynexus,ou=dsa,dc=mycompany,dc=net'
        ldap_auth_password: "{{ vault_ldap_dsa_password }}" # better keep passwords in an ansible vault
        ldap_search_base: 'dc=mycompany,dc=net'
        ldap_user_base_dn: 'ou=users'
        ldap_user_object_class: 'inetOrgPerson'
        ldap_user_id_attribute: 'uid'
        ldap_user_real_name_attribute: 'cn'
        ldap_user_email_attribute: 'mail'
        ldap_map_groups_as_roles: true
        ldap_group_base_dn: 'ou=groups'
        ldap_group_object_class: 'groupOfNames'
        ldap_group_id_attribute: 'cn'
        ldap_group_member_attribute: 'member'
        ldap_group_member_format: 'uid=${username},ou=users,dc=mycompany,dc=net'
        ldap_group_subtree: false

用于简单身份验证的示例 LDAP 配置(使用 DSA 帐户)+ 动态映射为角色的组:

    nexus_ldap_realm: true
    ldap_connections:
      - ldap_name: 'LDAP config with DSA'
        ldap_protocol: 'ldaps'
        ldap_hostname: 'annuaire.mycompany.com'
        ldap_port: 636
        ldap_use_trust_store: false
        ldap_auth: 'simple'
        ldap_auth_username: 'cn=mynexus,ou=dsa,dc=mycompany,dc=net'
        ldap_auth_password: "{{ vault_ldap_dsa_password }}" # better keep passwords in an ansible vault
        ldap_search_base: 'dc=mycompany,dc=net'
        ldap_user_base_dn: 'ou=users'
        ldap_user_object_class: 'inetOrgPerson'
        ldap_user_id_attribute: 'uid'
        ldap_user_real_name_attribute: 'cn'
        ldap_user_email_attribute: 'mail'
        ldap_map_groups_as_roles: true
        ldap_map_groups_as_roles_type: 'dynamic'
        ldap_user_memberof_attribute: 'memberOf'

特权

    nexus_privileges:
      - name: all-repos-read # used as key to update a privilege
        # type: <one of application, repository-admin, repository-content-selector, repository-view, script or wildcard>
        description: 'Read & Browse access to all repos'
        repository: '*'
        actions: # can be add, browse, create, delete, edit, read or  * (all)
          - read
          - browse
        # pattern: pattern
        # domain: domain
        # script_name: name

特权 用于设置。 查看文档和 GUI 以检查需要根据权限类型设置哪些变量。

这些元素与以下默认值组合:

    _nexus_privilege_defaults:
      type: repository-view
      format: maven2
      actions:
        - read

角色(在 Nexus 内这意味着)

    nexus_roles:
      - id: Developpers # can map to a LDAP group id, also used as a key to update a role
        name: developers
        description: All developers
        privileges:
          - nx-search-read
          - all-repos-read
        roles: [] # references to other role names

角色 用于设置。

用户

    nexus_local_users: []
      # - username: jenkins # used as key to update
      #   state: present # default value if ommited, use 'absent' to remove user
      #   first_name: Jenkins
      #   last_name: CI
      #   email: [email protected]
      #   password: "s3cr3t"
      #   roles:
      #     - developers # role ID

要在 nexus 中创建的本地(非 LDAP)用户/帐户列表。

要在 Nexus 中创建的本地(非 LDAP)用户/帐户列表。

      nexus_ldap_users: []
      # - username: j.doe
      #   state: present
      #   roles:
      #     - "nx-admin"

用户/角色的 LDAP 映射。 状态 absent 将从现有用户中删除角色(如果已存在)。
LDAP 用户不会被删除。 尝试为不存在的用户设置角色将导致错误。

内容选择器

  nexus_content_selectors:
  - name: docker-login
    description: Selector for docker login privilege
    search_expression: format=="docker" and path=~"/v2/"

有关内容选择器的更多信息,请参阅 文档.

要使用内容选择器,请添加新权限 type: repository-content-selector 和相关的contentSelector

- name: docker-login-privilege
  type: repository-content-selector
  contentSelector: docker-login
  description: 'Login to Docker registry'
  repository: '*'
  actions:
  - read
  - browse

Blob 存储区和存储库

    nexus_delete_default_repos: false

从 Nexus 安装初始默认配置中删除存储库。 此步骤仅在首次安装时执行(当 nexus_data_dir 已检测到空)。

从 Nexus 的默认配置中删除存储库。 此步骤仅在第一次安装期间执行(当 nexus_data_dir 空的)。

    nexus_delete_default_blobstore: false

从 Nexus 安装初始默认配置中删除默认 blobstore。 只有在以下情况下才可以这样做: nexus_delete_default_repos: true 并且所有配置的存储库(见下文)都有一个明确的 blob_store: custom。 此步骤仅在首次安装时执行(当 nexus_data_dir 已检测到空)。

默认情况下,初始配置中禁用删除 Blob 存储(二进制项目)。 要删除 blob 存储(二进制工件),请关闭 nexus_delete_default_repos: true。 此步骤仅在第一次安装期间执行(当 nexus_data_dir 空的)。

    nexus_blobstores: []
    # example blobstore item :
    # - name: separate-storage
    #   type: file
    #   path: /mnt/custom/path
    # - name: s3-blobstore
    #   type: S3
    #   config:
    #     bucket: s3-blobstore
    #     accessKeyId: "{{ VAULT_ENCRYPTED_KEY_ID }}"
    #     secretAccessKey: "{{ VAULT_ENCRYPTED_ACCESS_KEY }}"

斑点存储区 创造。 Blobstore 路径和存储库 blobstore 在初始创建后无法更新(重新配置时,此处的任何更新都将被忽略)。

在 S3 上配置 blobstore 是为了方便起见,并不是我们在 travis 上运行的自动化测试的一部分。 请注意,仅建议部署在 AWS 上的实例存储在 S3 上。

创建 斑点存储区。 初始创建后,存储路径和存储库无法更新(再次安装时,此处的任何更新都将被忽略)。

在 S3 上设置 Blob 存储是为了方便起见。 请注意,仅建议对 AWS 上部署的实例使用 S3 存储。

    nexus_repos_maven_proxy:
      - name: central
        remote_url: 'https://repo1.maven.org/maven2/'
        layout_policy: permissive
        # maximum_component_age: -1
        # maximum_metadata_age: 1440
        # negative_cache_enabled: true
        # negative_cache_ttl: 1440
      - name: jboss
        remote_url: 'https://repository.jboss.org/nexus/content/groups/public-jboss/'
        # maximum_component_age: -1
        # maximum_metadata_age: 1440
        # negative_cache_enabled: true
        # negative_cache_ttl: 1440
    # example with a login/password :
    # - name: secret-remote-repo
    #   remote_url: 'https://company.com/repo/secure/private/go/away'
    #   remote_username: 'username'
    #   remote_password: 'secret'
    #   # maximum_component_age: -1
    #   # maximum_metadata_age: 1440
    #   # negative_cache_enabled: true
    #   # negative_cache_ttl: 1440

上面是一个配置示例 代理服务器 马文。

    nexus_repos_maven_hosted:
      - name: private-release
        version_policy: release
        write_policy: allow_once  # one of "allow", "allow_once" or "deny"

Maven的 托管存储库 配置。 负缓存配置是可选的,如果省略,将默认为上述值。

布局 托管存储库 梅文。 负缓存配置(-1)是可选的,如果未指定,将默认为上述值。

    nexus_repos_maven_group:
      - name: public
        member_repos:
          - central
          - jboss

布局 群体 马文。

所有三种存储库类型均与以下默认值相结合:

    _nexus_repos_maven_defaults:
      blob_store: default # Note : cannot be updated once the repo has been created
      strict_content_validation: true
      version_policy: release # release, snapshot or mixed
      layout_policy: strict # strict or permissive
      write_policy: allow_once # one of "allow", "allow_once" or "deny"
      maximum_component_age: -1  # Nexus gui default. For proxies only
      maximum_metadata_age: 1440  # Nexus gui default. For proxies only
      negative_cache_enabled: true # Nexus gui default. For proxies only
      negative_cache_ttl: 1440 # Nexus gui default. For proxies only

Docker、Pypi、Raw、Rubygems、Bower、NPM、Git-LFS 和 yum 存储库类型:
看到 defaults/main.yml 对于这些选项:

默认情况下禁用 Docker、Pypi、Raw、Rubygems、Bower、NPM、Git-LFS 和 yum 存储库:
defaults/main.yml 对于这些选项:

      nexus_config_pypi: false
      nexus_config_docker: false
      nexus_config_raw: false
      nexus_config_rubygems: false
      nexus_config_bower: false
      nexus_config_npm: false
      nexus_config_gitlfs: false
      nexus_config_yum: false

请注意,如果您想使用除 Maven 之外的其他类型的存储库,您可能需要启用某些安全范围。 默认情况下这是错误的

nexus_nuget_api_key_realm: false
nexus_npm_bearer_token_realm: false
nexus_docker_bearer_token_realm: false  # required for docker anonymous access

远程用户领域也可以使用启用

nexus_rut_auth_realm: true

并且可以通过定义来自定义标题

nexus_rut_auth_header: "CUSTOM_HEADER"

计划任务

    nexus_scheduled_tasks: []
    #  #  Example task to compact blobstore :
    #  - name: compact-docker-blobstore
    #    cron: '0 0 22 * * ?'
    #    typeId: blobstore.compact
    #    task_alert_email: [email protected]  # optional
    #    taskProperties:
    #      blobstoreName: {{ nexus_blob_names.docker.blob }} # all task attributes are stored as strings by nexus internally
    #  #  Example task to purge maven snapshots
    #  - name: Purge-maven-snapshots
    #    cron: '0 50 23 * * ?'
    #    typeId: repository.maven.remove-snapshots
    #    task_alert_email: [email protected]  # optional
    #    taskProperties:
    #      repositoryName: "*"  # * for all repos. Change to a repository name if you only want a specific one
    #      minimumRetained: "2"
    #      snapshotRetentionDays: "2"
    #      gracePeriodInDays: "2"
    #    booleanTaskProperties:
    #      removeIfReleased: true
    #  #  Example task to purge unused docker manifest and images
    #  - name: Purge unused docker manifests and images
    #    cron: '0 55 23 * * ?'
    #    typeId: "repository.docker.gc"
    #    task_alert_email: [email protected]  # optional
    #    taskProperties:
    #      repositoryName: "*"  # * for all repos. Change to a repository name if you only want a specific one
    #  #  Example task to purge incomplete docker uploads
    #  - name: Purge incomplete docker uploads
    #    cron: '0 0 0 * * ?'
    #    typeId: "repository.docker.upload-purge"
    #    task_alert_email: [email protected]  # optional
    #    taskProperties:
    #      age: "24"

计划任务 用于设置。 typeId 和具体任务taskProperties/booleanTaskProperties 你可以猜测:

  • 从 Java 类型层次结构 org.sonatype.nexus.scheduling.TaskDescriptorSupport
  • 在浏览器中检查 HTML 任务创建表单
  • 手动设置任务时在浏览器中查看 AJAX 请求。

任务属性必须根据其类型在正确的 yaml 块中声明:

  • taskProperties 对于所有字符串属性(即存储库名称、存储库名称、时间段...)。
  • booleanTaskProperties 对于所有逻辑属性(即主要是 Nexus 创建任务的 GUI 中的复选框)。

备份

      nexus_backup_configure: false
      nexus_backup_cron: '0 0 21 * * ?'  # See cron expressions definition in nexus create task gui
      nexus_backup_dir: '/var/nexus-backup'
      nexus_restore_log: '{{ nexus_backup_dir }}/nexus-restore.log'
      nexus_backup_rotate: false
      nexus_backup_rotate_first: false
      nexus_backup_keep_rotations: 4  # Keep 4 backup rotation by default (current + last 3)

在切换之前不会配置备份 nexus_backup_configure в true.
在这种情况下,计划的脚本任务将配置为在 Nexus 上运行
以指定的间隔 nexus_backup_cron (默认每天21:00)。
有关详细信息,请参阅[此任务的 groovy 模板](templates/backup.groovy.j2)。
该计划任务独立于其他任务 nexus_scheduled_tasks你哪个
在你的剧本中宣布。

如果您想轮换/删除备份,请安装 nexus_backup_rotate: true 并配置您想要保存的备份数量 nexus_backup_keep_rotations (默认 4)。

使用旋转时,如果您想在备份过程中节省额外的磁盘空间,
你可以安装 nexus_backup_rotate_first: true。 这将在备份之前配置预轮换/删除。 默认情况下,创建备份后会发生轮换。 请注意,在这种情况下,旧备份
将在进行当前备份之前删除。

恢复程序

使用参数运行 playbook -e nexus_restore_point=<YYYY-MM-dd-HH-mm-ss>
(例如,2017-12-17-21-00-00 表示 17 年 2017 月 21 日 00:XNUMX

消除联系

警告:这将完全删除您当前的数据。 如有必要请务必提前进行备份

使用变量 nexus_purge如果您需要从头开始并重新安装 Nexus 实例并删除所有数据。

ansible-playbook -i your/inventory.ini your_nexus_playbook.yml -e nexus_purge=true

首次安装后更改管理员密码

    nexus_default_admin_password: 'admin123'

这不应该在你的剧本中改变。 该变量在首次安装时使用默认的 Nexus 管理员密码填充,并确保我们可以将管理员密码更改为 nexus_admin_password.

如果首次安装后想要更改管理员密码,可以通过命令行临时将其更改为旧密码。 改变后 nexus_admin_password 在你的剧本中你可以运行:

ansible-playbook -i your/inventory.ini your_playbook.yml -e nexus_default_admin_password=oldPassword

Nexus Sonatype 上的 Telegram 频道: https://t.me/ru_nexus_sonatype

只有注册用户才能参与调查。 登录拜托

您使用什么工件存储库?

  • Sonatype Nexus 是免费的

  • Sonatype Nexus 付费

  • Artifactory 是免费的

  • 人工付费

  • 港口

  • 纸浆

9 位用户投票。 3 名用户弃权。

来源: habr.com

添加评论