使用基礎架構即程式碼方法安裝和設定 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
  • 的NuGet

社區支援的工件:

  • 作曲家
  • 柯南
  • 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 名用戶棄權。

來源: www.habr.com

添加評論