Cài đặt và định cấu hình Nexus Sonatype bằng cách sử dụng cơ sở hạ tầng dưới dạng phương pháp tiếp cận mã

Sonatype Nexus là một nền tảng tích hợp thông qua đó các nhà phát triển có thể ủy quyền, lưu trữ và quản lý các phần phụ thuộc Java (Maven), Docker, Python, Ruby, NPM, hình ảnh Bower, gói RPM, gitlfs, Apt, Go, Nuget và phân phối bảo mật phần mềm của họ.

Tại sao bạn cần Sonatype Nexus?

  • Để lưu trữ các hiện vật riêng tư;
  • Đối với các tạo phẩm bộ nhớ đệm được tải xuống từ Internet;

Các thành phần được hỗ trợ trong gói Sonatype Nexus cơ bản:

  • Java, Maven (bình)
  • phu bến tàu
  • Python (pip)
  • Ruby (đá quý)
  • NPM
  • Cung cấp
  • Ngon (vòng/phút)
  • gitlfs
  • Nguyên
  • Apt (deb)
  • Go
  • nuget

Hiện vật được cộng đồng hỗ trợ:

  • sáng tác
  • Conan
  • CPAN
  • EL PA
  • Quản lý
  • P2
  • R

Cài đặt Sonatype Nexus bằng cách sử dụng https://github.com/ansible-ThoTeam/nexus3-oss

Yêu cầu

  • Đọc về cách sử dụng ansible trên Internet.
  • Cài đặt ansible pip install ansible trên máy trạm nơi playbook chạy.
  • Tải về geerlingguy.java trên máy trạm nơi playbook chạy.
  • Tải về geerlingguy.apache trên máy trạm nơi playbook chạy.
  • Vai trò này đã được thử nghiệm trên CentOS 7, Ubuntu Xenial (16.04) và Bionic (18.04), Debian Jessie và Stretch
  • jmespath Thư viện phải được cài đặt trên máy trạm nơi playbook đang chạy. Để cài đặt: sudo pip install -r requirements.txt
  • Lưu tệp playbook (ví dụ bên dưới) vào tệp nexus.yml
  • Chạy cài đặt nexus ansible-playbook -i host nexus.yml

Ví dụ về ansible-playbook để cài đặt nexus mà không cần LDAP với các kho lưu trữ Maven (java), Docker, Python, Ruby, NPM, Bower, RPM và gitlfs.

---
- 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'] }

Ảnh chụp màn hình:

Cài đặt và định cấu hình Nexus Sonatype bằng cách sử dụng cơ sở hạ tầng dưới dạng phương pháp tiếp cận mã

Cài đặt và định cấu hình Nexus Sonatype bằng cách sử dụng cơ sở hạ tầng dưới dạng phương pháp tiếp cận mã

Vai trò thay đổi

Biến vai trò

Các biến có giá trị mặc định (xem default/main.yml):

Biến chung

    nexus_version: ''
    nexus_timezone: 'UTC'

Theo mặc định, vai trò này sẽ cài đặt phiên bản Nexus mới nhất hiện có. Bạn có thể sửa phiên bản bằng cách thay đổi biến nexus_version. Xem các phiên bản có sẵn tại https://www.sonatype.com/download-oss-sonatype.

Nếu bạn thay đổi sang phiên bản mới hơn, vai trò này sẽ cố gắng cập nhật cài đặt Nexus của bạn.

Nếu bạn đang sử dụng phiên bản Nexus cũ hơn phiên bản mới nhất, bạn nên đảm bảo rằng bạn không sử dụng các tính năng không có trong bản phát hành đã cài đặt (ví dụ: kho lưu trữ yum có sẵn cho nexus lớn hơn 3.8.0, git lfs repo đối với Nexus lớn hơn 3.3.0, v.v.)

nexus timezone là tên của múi giờ Java, có thể hữu ích khi kết hợp với các biểu thức cron sau cho các tác vụ nexus_scheduled.

Cổng Nexus và đường dẫn ngữ cảnh

    nexus_default_port: 8081
    nexus_default_context_path: '/'

Đường dẫn cổng và ngữ cảnh của quá trình kết nối Java. nexus_default_context_path phải chứa dấu gạch chéo về phía trước khi nó được đặt, ví dụ: nexus_default_context_path: '/nexus/'.

Người dùng và nhóm hệ điều hành Nexus

    nexus_os_group: 'nexus'
    nexus_os_user: 'nexus'

Người dùng và nhóm được sử dụng để sở hữu các tệp Nexus và chạy dịch vụ sẽ được tạo theo vai trò nếu thiếu một tệp.

    nexus_os_user_home_dir: '/home/nexus'

Cho phép thay đổi thư mục gốc mặc định của người dùng Nexus

Thư mục phiên bản Nexus

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

Danh mục Nexus.

  • nexus_installation_dir chứa các tập tin thực thi được cài đặt
  • nexus_data_dir chứa tất cả cấu hình, kho lưu trữ và các tạo phẩm được tải xuống. Đường dẫn blobstore tùy chỉnh nexus_data_dir có thể được tùy chỉnh, xem bên dưới nexus_blobstores.
  • nexus_tmp_dir chứa tất cả các tập tin tạm thời. Đường dẫn mặc định cho redhat đã được chuyển từ /tmp để khắc phục các vấn đề tiềm ẩn với quy trình làm sạch tự động. Xem #168.

Định cấu hình sử dụng bộ nhớ Nexus JVM

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

Đây là cài đặt mặc định cho Nexus. Vui lòng không thay đổi các giá trị này Nếu bạn chưa đọc phần bộ nhớ yêu cầu hệ thống Nexus và không hiểu họ đang làm gì.

Như một lời cảnh báo thứ hai, đây là một đoạn trích từ tài liệu trên:

Không nên tăng bộ nhớ heap JVM vượt quá các giá trị được đề xuất nhằm cố gắng cải thiện hiệu suất. Điều này thực sự có thể có tác dụng ngược, dẫn đến hệ điều hành phải làm việc không cần thiết.

Mật khẩu quản trị viên

    nexus_admin_password: 'changeme'

Mật khẩu tài khoản “quản trị viên” để thiết lập. Điều này chỉ hoạt động trong lần cài đặt mặc định đầu tiên. Vui lòng xem [Thay đổi mật khẩu quản trị viên sau lần cài đặt đầu tiên](# thay đổi mật khẩu quản trị viên sau lần cài đặt đầu tiên) nếu bạn muốn thay đổi mật khẩu sau bằng vai trò.

Chúng tôi thực sự khuyên bạn không nên lưu mật khẩu của mình ở dạng văn bản rõ ràng trong playbook mà nên sử dụng [mã hóa ansible-vault] (https://docs.ansible.com/ansible/latest/user_guide/vault.html) (nội tuyến hoặc trong một tệp riêng biệt được tải bằng ví dụ: include_vars)

Truy cập ẩn danh theo mặc định

    nexus_anonymous_access: false

Quyền truy cập ẩn danh bị tắt theo mặc định. Đọc thêm về truy cập ẩn danh.

Tên máy chủ công cộng

    nexus_public_hostname: 'nexus.vm'
    nexus_public_scheme: https

Tên miền và sơ đồ đủ điều kiện (https hoặc http) mà theo đó phiên bản Nexus sẽ có sẵn cho khách hàng của nó.

Quyền truy cập API cho vai trò này

    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 }}"

Các biến này kiểm soát cách vai trò kết nối với API Nexus để cung cấp.
Chỉ dành cho người dùng nâng cao. Có thể bạn không muốn thay đổi các cài đặt mặc định này

Thiết lập proxy ngược

    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

Tải về Proxy ngược SSL.
Để làm được điều này bạn cần cài đặt httpd. Lưu ý: khi nào cho httpd_setup_enable đặt giá trịtrue, do đó, liên hệ của Nexus 127.0.0.1:8081 không có thể truy cập trực tiếp qua cổng HTTP 8081 từ địa chỉ IP bên ngoài.

Tên máy chủ mặc định được sử dụng là nexus_public_hostname. Nếu bạn cần tên khác vì lý do nào đó, bạn có thể đặt httpd_server_name với một ý nghĩa khác.

С httpd_copy_ssl_files: true (theo mặc định) các chứng chỉ trên sẽ tồn tại trong thư mục playbook của bạn và sẽ được sao chép vào máy chủ và được định cấu hình trong apache.

Nếu bạn muốn sử dụng các chứng chỉ hiện có trên máy chủ, hãy cài đặt httpd_copy_ssl_files: false và cung cấp các biến sau:

    # 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 là tùy chọn và không được đặt nếu bạn không muốn tùy chỉnh tệp chuỗi

    httpd_default_admin_email: "[email protected]"

Đặt địa chỉ email quản trị viên mặc định

Cấu hình LDAP

Kết nối LDAP và lĩnh vực bảo mật bị tắt theo mặc định

    nexus_ldap_realm: false
    ldap_connections: []

Kết nối LDAP, mỗi phần tử trông như thế này:

    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

Ví dụ về cấu hình LDAP để xác thực ẩn danh (ràng buộc ẩn danh), đây cũng là cấu hình "tối thiểu":

    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'

Ví dụ về cấu hình LDAP để xác thực đơn giản (sử dụng tài khoản 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

Ví dụ về cấu hình LDAP để xác thực đơn giản (sử dụng tài khoản DSA) + các nhóm được ánh xạ dưới dạng vai trò:

    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

Ví dụ về cấu hình LDAP để xác thực đơn giản (sử dụng tài khoản DSA) + các nhóm được ánh xạ động dưới dạng vai trò:

    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'

Đặc quyền

    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

Danh sách đặc quyền cho các cài đặt. Xem tài liệu và GUI để kiểm tra xem biến nào cần được đặt tùy thuộc vào loại đặc quyền.

Các phần tử này được kết hợp với các giá trị mặc định sau:

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

Vai trò (có nghĩa là bên trong 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

Danh sách vai trò cho các cài đặt.

Thành viên

    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

Danh sách người dùng/tài khoản cục bộ (không phải LDAP) để tạo trong mối quan hệ.

Danh sách người dùng/tài khoản cục bộ (không phải LDAP) cần tạo trong Nexus.

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

Ánh xạ Ldap của người dùng/vai trò. Tình trạng absent sẽ xóa vai trò khỏi người dùng hiện tại nếu người dùng đã tồn tại.
Người dùng Ldap không bị xóa. Việc cố gắng đặt vai trò cho người dùng không tồn tại sẽ dẫn đến lỗi.

Bộ chọn nội dung

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

Để biết thêm thông tin về bộ chọn nội dung, hãy xem Tài liệu.

Để sử dụng bộ chọn nội dung, hãy thêm đặc quyền mới với type: repository-content-selector và có liên quancontentSelector

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

Blobstores và kho lưu trữ

    nexus_delete_default_repos: false

Xóa các kho lưu trữ khỏi cấu hình mặc định ban đầu của cài đặt Nexus. Bước này chỉ được thực hiện khi cài đặt lần đầu (khi nexus_data_dir đã được phát hiện trống rỗng).

Xóa kho lưu trữ khỏi cấu hình mặc định mặc định cho Nexus. Bước này chỉ được thực hiện trong lần cài đặt đầu tiên (khi nexus_data_dir trống).

    nexus_delete_default_blobstore: false

Xóa blobstore mặc định khỏi cấu hình mặc định ban đầu của bản cài đặt Nexus. Điều này chỉ có thể được thực hiện nếu nexus_delete_default_repos: true và tất cả các kho lưu trữ được định cấu hình (xem bên dưới) đều có thông tin rõ ràng blob_store: custom. Bước này chỉ được thực hiện khi cài đặt lần đầu (khi nexus_data_dir đã được phát hiện trống rỗng).

Theo mặc định, việc xóa bộ nhớ blob (tạo tác nhị phân) bị tắt khỏi cấu hình ban đầu. Để xóa bộ nhớ blob (tạo tác nhị phân), hãy tắt nexus_delete_default_repos: true. Bước này chỉ được thực hiện trong lần cài đặt đầu tiên (khi nexus_data_dir trống).

    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 }}"

Cửa hàng Blobstore để tạo ra. Không thể cập nhật đường dẫn blobstore và kho lưu trữ blobstore sau lần tạo đầu tiên (mọi cập nhật ở đây sẽ bị bỏ qua khi cấp lại).

Việc định cấu hình blobstore trên S3 được cung cấp nhằm mục đích thuận tiện và không nằm trong các thử nghiệm tự động mà chúng tôi chạy trên travis. Xin lưu ý rằng việc lưu trữ trên S3 chỉ được khuyến nghị cho các phiên bản được triển khai trên AWS.

Sự sáng tạo Cửa hàng Blobstore. Đường dẫn lưu trữ và kho lưu trữ không thể được cập nhật sau lần tạo đầu tiên (mọi cập nhật ở đây sẽ bị bỏ qua khi cài đặt lại).

Việc thiết lập bộ nhớ blob trên S3 được cung cấp để thuận tiện. Xin lưu ý rằng bộ lưu trữ S3 chỉ được khuyến nghị cho các phiên bản được triển khai trên AWS.

    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

Trên đây là cấu hình ví dụ máy chủ proxy maven.

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

Maven kho lưu trữ được lưu trữ cấu hình. Cấu hình bộ đệm âm là tùy chọn và sẽ mặc định về các giá trị trên nếu bị bỏ qua.

Cấu hình kho lưu trữ được lưu trữ Maven. Cấu hình bộ đệm âm (-1) là tùy chọn và sẽ mặc định về các giá trị trên nếu không được chỉ định.

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

Cấu hình Nhóm maven.

Tất cả ba loại kho lưu trữ được kết hợp với các giá trị mặc định sau:

    _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

Các loại kho lưu trữ Docker, Pypi, Raw, Rubygems, Bower, NPM, Git-LFS và yum:
xem defaults/main.yml cho các tùy chọn này:

Các kho lưu trữ Docker, Pypi, Raw, Rubygems, Bower, NPM, Git-LFS và yum bị tắt theo mặc định:
thấy defaults/main.yml cho các tùy chọn này:

      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

Xin lưu ý rằng bạn có thể cần kích hoạt một số phạm vi bảo mật nhất định nếu bạn muốn sử dụng các loại kho lưu trữ khác ngoài maven. Điều này mặc định là sai

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

Vương quốc người dùng từ xa cũng có thể được kích hoạt bằng cách sử dụng

nexus_rut_auth_realm: true

và tiêu đề có thể được tùy chỉnh bằng cách xác định

nexus_rut_auth_header: "CUSTOM_HEADER"

Nhiệm vụ theo lịch trình

    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"

Nhiệm vụ theo lịch trình cho các cài đặt. typeId và nhiệm vụ cụ thểtaskProperties/booleanTaskProperties bạn có thể đoán:

  • từ hệ thống phân cấp kiểu Java org.sonatype.nexus.scheduling.TaskDescriptorSupport
  • kiểm tra biểu mẫu tạo tác vụ HTML trong trình duyệt của bạn
  • xem các yêu cầu AJAX trong trình duyệt khi thiết lập tác vụ theo cách thủ công.

Thuộc tính tác vụ phải được khai báo trong khối yaml chính xác tùy thuộc vào loại của chúng:

  • taskProperties cho tất cả các thuộc tính chuỗi (ví dụ: tên kho lưu trữ, tên kho lưu trữ, khoảng thời gian ...).
  • booleanTaskProperties cho tất cả các thuộc tính logic (tức là chủ yếu là các hộp kiểm trong GUI của tác vụ tạo mối quan hệ).

Sao lưu

      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)

Sao lưu sẽ không được cấu hình cho đến khi bạn chuyển đổi nexus_backup_configure в true.
Trong trường hợp này, tác vụ tập lệnh đã lên lịch sẽ được định cấu hình để chạy trên Nexus
tại khoảng thời gian được chỉ định trong nexus_backup_cron (mặc định là 21h hàng ngày).
Xem [mẫu Groovy cho tác vụ này](templates/backup.groovy.j2) để biết chi tiết.
Nhiệm vụ theo lịch trình này độc lập với những nhiệm vụ khác nexus_scheduled_tasksmà bạn
thông báo trong playbook của bạn.

Nếu bạn muốn xoay/xóa bản sao lưu, hãy cài đặt nexus_backup_rotate: true và định cấu hình số lượng bản sao lưu bạn muốn lưu bằng cách sử dụng nexus_backup_keep_rotations (mặc định 4).

Khi sử dụng chế độ xoay, nếu bạn muốn tiết kiệm thêm dung lượng ổ đĩa trong quá trình sao lưu,
Bạn có thể cài đặt nexus_backup_rotate_first: true. Điều này sẽ cấu hình xoay/xóa trước khi sao lưu. Theo mặc định, quá trình xoay diễn ra sau khi tạo bản sao lưu. Xin lưu ý rằng trong trường hợp này các bản sao lưu cũ
sẽ bị xóa trước khi bản sao lưu hiện tại được thực hiện.

Quy trình phục hồi

Chạy playbook với tham số -e nexus_restore_point=<YYYY-MM-dd-HH-mm-ss>
(ví dụ: 2017-12-17-21-00-00 cho ngày 17 tháng 2017 năm 21 lúc 00:XNUMX

Đang xóa mối quan hệ

Cảnh báo: Thao tác này sẽ xóa hoàn toàn dữ liệu hiện tại của bạn. Hãy chắc chắn tạo bản sao lưu sớm hơn nếu cần thiết

Sử dụng một biến nexus_purgenếu bạn cần khởi động lại từ đầu và cài đặt lại phiên bản Nexus với tất cả dữ liệu đã bị xóa.

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

Thay đổi mật khẩu quản trị viên sau khi cài đặt lần đầu

    nexus_default_admin_password: 'admin123'

Điều này không nên thay đổi trong playbook của bạn. Biến này được điền bằng mật khẩu quản trị viên Nexus mặc định khi cài đặt lần đầu và đảm bảo rằng chúng tôi có thể thay đổi mật khẩu quản trị viên thành nexus_admin_password.

Nếu bạn muốn thay đổi mật khẩu quản trị viên sau lần cài đặt đầu tiên, bạn có thể tạm thời thay đổi mật khẩu đó thành mật khẩu cũ từ dòng lệnh. Sau khi thay đổi nexus_admin_password trong playbook của bạn, bạn có thể chạy:

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

Kênh Telegram trên Nexus Sonatype: https://t.me/ru_nexus_sonatype

Chỉ những người dùng đã đăng ký mới có thể tham gia khảo sát. Đăng nhập, xin vui lòng.

Bạn sử dụng kho lưu trữ hiện vật nào?

  • Sonatype Nexus miễn phí

  • Sonatype Nexus đã trả phí

  • Artifactory là miễn phí

  • Artifactory đã trả tiền

  • Harbor

  • Pulp

9 người dùng bình chọn. 3 người dùng bỏ phiếu trắng.

Nguồn: www.habr.com

Thêm một lời nhận xét