Link Search Menu Expand Document Documentation Menu

Docker

Docker 极大地简化了 OpenSearch 集群的配置和管理过程。您可以从 Docker HubAmazon Elastic Container Registry (Amazon ECR) 拉取官方镜像,并使用 Docker Compose 以及本指南中包含的任何示例 Docker Compose 文件快速部署集群。经验丰富的 OpenSearch 用户可以通过创建自定义 Docker Compose 文件来进一步定制其部署。

Docker 容器具有可移植性,可在任何支持 Docker 的兼容主机(如 Linux、MacOS 或 Windows)上运行。Docker 容器的可移植性优于其他安装方法(如 RPM 或手动 Tarball 安装),后两者在下载和解压后需要额外的配置。

本指南假设您熟悉 Linux 命令行界面 (CLI)。您应该了解如何输入命令、在目录之间导航以及编辑文本文件。有关 DockerDocker Compose 的帮助,请参阅其官方网站上的文档。

安装 Docker 和 Docker Compose

访问 获取 Docker 以获取关于为您的环境安装和配置 Docker 的指导。如果您使用 CLI 安装 Docker Engine,则 Docker 默认情况下不会对可用的主机资源施加任何限制。根据您的环境,您可能希望在 Docker 中配置资源限制。有关信息,请参阅 内存、CPU 和 GPU 的运行时选项

Docker Desktop 用户应通过打开 Docker Desktop 并选择 设置资源,将主机内存使用量设置为至少 4 GB。

Docker Compose 是一个实用程序,允许用户通过单个命令启动多个容器。当您调用 Docker Compose 时,会向其传递一个文件。Docker Compose 读取这些设置并启动请求的容器。Docker Compose 会随 Docker Desktop 自动安装,但在命令行环境中操作的用户必须手动安装 Docker Compose。您可以在官方 Docker Compose GitHub 页面上找到有关安装 Docker Compose 的信息。

如果您需要手动安装 Docker Compose 并且您的主机支持 Python,您可以使用 pip 自动安装 Docker Compose 包

配置重要的主机设置

在使用 Docker 安装 OpenSearch 之前,请配置以下设置。这些是可能影响服务性能的最重要设置,但有关更多信息,请参阅重要系统设置

Linux 设置

对于 Linux 环境,运行以下命令

  1. 禁用主机的内存分页和交换性能以提高性能。
    sudo swapoff -a
    
  2. 增加 OpenSearch 可用的内存映射数量。
    # Edit the sysctl config file
    sudo vi /etc/sysctl.conf
    
    # Add a line to define the desired value
    # or change the value if the key exists,
    # and then save your changes.
    vm.max_map_count=262144
    
    # Reload the kernel parameters using sysctl
    sudo sysctl -p
    
    # Verify that the change was applied by checking the value
    cat /proc/sys/vm/max_map_count
    

Windows 设置

对于通过 Docker Desktop 使用 WSL 的 Windows 工作负载,在终端中运行以下命令以设置 vm.max_map_count

wsl -d docker-desktop
sysctl -w vm.max_map_count=262144

在 Docker 容器中运行 OpenSearch

官方 OpenSearch 镜像托管在 Docker HubAmazon ECR 上。如果您想检查镜像,可以使用 docker pull 单独拉取它们,示例如下。

Docker Hub:

docker pull opensearchproject/opensearch:3

docker pull opensearchproject/opensearch-dashboards:3

Amazon ECR:

docker pull public.ecr.aws/opensearchproject/opensearch:3

docker pull public.ecr.aws/opensearchproject/opensearch-dashboards:3

要下载 OpenSearch 或 OpenSearch Dashboards 的特定版本(而非最新可用版本),请修改引用它的镜像标签(无论是在命令行中还是在 Docker Compose 文件中)。例如,opensearchproject/opensearch:3.1.0 将拉取 OpenSearch 3.1.0 版。要拉取最新版本,请使用 opensearchproject/opensearch:latest。请参阅官方镜像仓库以获取可用版本。

在继续之前,您应该通过在单个容器中部署 OpenSearch 来验证 Docker 是否正常工作。

  1. 运行以下命令
     # This command maps ports 9200 and 9600, sets the discovery type to "single-node" and requests the newest image of OpenSearch
     docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:latest
    

    对于 OpenSearch 2.12 或更高版本,请在安装前使用以下命令设置新的自定义管理员密码

     docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password>" opensearchproject/opensearch:latest
    
  2. 向端口 9200 发送请求。默认用户名和密码为 admin
     curl https://:9200 -ku admin:<custom-admin-password>
    

    • 您应该会收到如下响应:
      {
        "name" : "a937e018cee5",
        "cluster_name" : "docker-cluster",
        "cluster_uuid" : "GLAjAG6bTeWErFUy_d-CLw",
        "version" : {
          "distribution" : "opensearch",
          "number" : <version>,
          "build_type" : <build-type>,
          "build_hash" : <build-hash>,
          "build_date" : <build-date>,
          "build_snapshot" : false,
          "lucene_version" : <lucene-version>,
          "minimum_wire_compatibility_version" : "7.10.0",
          "minimum_index_compatibility_version" : "7.0.0"
        },
        "tagline" : "The OpenSearch Project: https://opensearch.org.cn/"
      }
      
  3. 在停止正在运行的容器之前,显示所有正在运行的容器列表并复制您正在测试的 OpenSearch 节点的容器 ID。在以下示例中,容器 ID 为 a937e018cee5
     $ docker container ls
     CONTAINER ID   IMAGE                                 COMMAND                  CREATED          STATUS          PORTS                                                                NAMES
     a937e018cee5   opensearchproject/opensearch:latest   "./opensearch-docker…"   19 minutes ago   Up 19 minutes   0.0.0.0:9200->9200/tcp, 9300/tcp, 0.0.0.0:9600->9600/tcp, 9650/tcp   wonderful_boyd
    
  4. 通过将容器 ID 传递给 docker stop 来停止正在运行的容器。
     docker stop <containerId>
    

请记住,docker container ls 不会列出已停止的容器。如果您想查看已停止的容器,请使用 docker container ls -a。您可以使用 docker container rm <containerId_1> <containerId_2> <containerId_3> [...] 手动移除不需要的容器(传递所有要停止的容器 ID,用空格分隔),或者如果您想移除所有已停止的容器,可以使用更短的命令 docker container prune

使用 Docker Compose 部署 OpenSearch 集群

虽然技术上可以通过一次一个命令的方式构建 OpenSearch 集群,但将环境定义在 YAML 文件中并让 Docker Compose 管理集群要容易得多。以下部分包含示例 YAML 文件,您可以使用它们启动预定义的 OpenSearch 和 OpenSearch Dashboards 集群。这些示例适用于测试和开发,但不适合生产环境。如果您没有使用 Docker Compose 的经验,您可能希望在对示例中的字典结构进行任何更改之前,查阅 Docker Compose 规范 以获取语法和格式方面的指导。

定义环境的 YAML 文件被称为 Docker Compose 文件。默认情况下,docker-compose 命令将首先在您当前目录中检查与以下任何名称匹配的文件

  • docker-compose.yml
  • docker-compose.yaml
  • compose.yml
  • compose.yaml

如果当前目录中不存在这些文件中的任何一个,docker-compose 命令将失败。

在调用 docker-compose 时,可以使用 -f 标志指定自定义文件位置和名称

# Use a relative or absolute path to the file.
docker compose -f /path/to/your-file.yml up

如果这是您第一次使用 Docker Compose 启动 OpenSearch 集群,请使用以下 docker-compose.yml 示例文件。将其保存在主机的根目录中,并命名为 docker-compose.yml。此文件将创建一个包含三个容器的集群:两个容器运行 OpenSearch 服务,一个容器运行 OpenSearch Dashboards。这些容器通过名为 opensearch-net 的桥接网络进行通信,并使用两个卷,每个 OpenSearch 节点一个。由于此文件未明确禁用演示安全配置,因此将安装自签名 TLS 证书并创建具有默认名称和密码的内部用户。

设置自定义管理员密码

从 OpenSearch 2.12 开始,设置演示安全配置需要自定义管理员密码。请执行以下操作之一

  • 在运行 docker-compose.yml 之前,请使用以下命令设置新的自定义管理员密码
    export OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password>
    

  • 在您的 docker-compose.yml 文件所在的文件夹中创建一个 .env 文件,其中包含 OPENSEARCH_INITIAL_ADMIN_PASSWORD 和一个强密码值。

密码要求

OpenSearch 默认强制执行强密码安全性,使用 Dropbox 开发的 zxcvbn 密码强度估算库。

该库根据熵而不是严格的复杂性规则评估密码,遵循以下准则

  • 关注熵,而不仅仅是规则:不仅仅是添加数字或特殊字符,更要优先考虑整体的不可预测性。由随机单词或字符组成的更长密码提供更高的熵,使其比符合传统复杂性规则的短密码更安全。

  • 避免常见模式和字典词zxcvbn 库可以检测常用词、日期、序列(例如,1234qwerty),甚至可预测的字符替换(例如,`E` 用 3)。为确保强大的安全性,请避免在密码中使用这些模式。

  • 长度很重要:更长的密码通常提供更高的安全性。例如,像 correct horse battery staple 这样的密码短语被认为是强大的,因为它长度足够且具有随机性,即使它不包含特殊字符或数字。

  • 不可预测性是关键:无论是选择一串随机字符还是由不相关单词组成的密码短语,密码安全的关键都在于不可预测性。更高的熵会显著增加所需的猜测次数,使密码更能抵抗攻击。

要了解更多关于 zxcvbn,请参阅这篇 Dropbox 博客文章。要测试密码强度,请使用此演示

OpenSearch 使用以下默认密码要求

  • 最小密码长度:8 个字符。
  • 最大密码长度:100 个字符。
  • 对特殊字符、数字或大写字母没有要求。
  • 密码必须使用 zxcvbn 基于熵的计算被评为 strong

您可以通过更新密码集群设置来自定义默认密码要求。

docker-compose.yml 示例

services:
  opensearch-node1: # This is also the hostname of the container within the Docker network (i.e. https://opensearch-node1/)
    image: opensearchproject/opensearch:latest # Specifying the latest available image - modify if you want a specific version
    container_name: opensearch-node1
    environment:
      - cluster.name=opensearch-cluster # Name the cluster
      - node.name=opensearch-node1 # Name the node that will run in this container
      - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligible to serve as cluster manager
      - bootstrap.memory_lock=true # Disable JVM heap memory swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD}    # Sets the demo admin user password when using demo configuration, required for OpenSearch 2.12 and later
    ulimits:
      memlock:
        soft: -1 # Set memlock to unlimited (no soft or hard limit)
        hard: -1
      nofile:
        soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
        hard: 65536
    volumes:
      - opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container
    ports:
      - 9200:9200 # REST API
      - 9600:9600 # Performance Analyzer
    networks:
      - opensearch-net # All of the containers will join the same Docker bridge network
  opensearch-node2:
    image: opensearchproject/opensearch:latest # This should be the same image used for opensearch-node1 to avoid issues
    container_name: opensearch-node2
    environment:
      - cluster.name=opensearch-cluster
      - node.name=opensearch-node2
      - discovery.seed_hosts=opensearch-node1,opensearch-node2
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - opensearch-data2:/usr/share/opensearch/data
    networks:
      - opensearch-net
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:latest # Make sure the version of opensearch-dashboards matches the version of opensearch installed on other nodes
    container_name: opensearch-dashboards
    ports:
      - 5601:5601 # Map host port 5601 to container port 5601
    expose:
      - "5601" # Expose port 5601 for web access to OpenSearch Dashboards
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]' # Define the OpenSearch nodes that OpenSearch Dashboards will query
    networks:
      - opensearch-net

volumes:
  opensearch-data1:
  opensearch-data2:

networks:
  opensearch-net:

如果您在 Compose 文件中使用环境变量覆盖 opensearch_dashboards.yml 设置,请使用所有大写字母并将句点替换为下划线(例如,对于 opensearch.hosts,请使用 OPENSEARCH_HOSTS)。此行为与覆盖 opensearch.yml 设置不一致,后者仅是将赋值运算符更改(例如,opensearch.yml 中的 discovery.type: single-nodedocker-compose.yml 中定义为 discovery.type=single-node)。

在主机的根目录(包含 docker-compose.yml)中,以分离模式创建并启动容器

docker compose up -d

验证服务容器是否已正确启动

docker compose ps

如果容器启动失败,您可以查看服务日志

# If you don't pass a service name, docker compose will show you logs from all of the nodes
docker compose logs <serviceName>

通过从浏览器连接到 https://:5601 来验证对 OpenSearch Dashboards 的访问。对于 OpenSearch 2.12 及更高版本,您必须使用您配置的用户名和密码。对于早期版本,默认用户名和密码是 admin。除非您已自定义部署的安全配置,否则我们不建议在可从公共互联网访问的主机上使用此配置。

请记住,localhost 无法远程访问。如果您要将这些容器部署到远程主机,则需要建立网络连接并将 localhost 替换为与该主机对应的 IP 或 DNS 记录。

停止集群中正在运行的容器

docker compose down

docker compose down 将停止正在运行的容器,但不会删除主机上存在的 Docker 卷。如果您不关心这些卷的内容,请使用 -v 选项删除所有卷,例如,docker compose down -v

配置 OpenSearch

与需要大量安装后配置的 OpenSearch RPM 分发版不同,使用 Docker 运行 OpenSearch 集群允许您在容器创建之前定义环境。无论是使用 Docker 还是 Docker Compose,这都是可能的。

例如,请看以下命令

docker run \
  -p 9200:9200 -p 9600:9600 \
  -e "discovery.type=single-node" \
  -v /path/to/custom-opensearch.yml:/usr/share/opensearch/config/opensearch.yml \
  opensearchproject/opensearch:latest

通过查看命令的每个部分,您可以看到它

  • 映射端口 92009600HOST_PORT:CONTAINER_PORT)。
  • discovery.type 设置为 single-node,以便此单节点部署的引导检查不会失败。
  • 使用-v 标志 将名为 custom-opensearch.yml 的本地文件传递给容器,替换映像中包含的 opensearch.yml 文件。
  • 从 Docker Hub 请求 opensearchproject/opensearch:latest 映像。
  • 运行容器。

如果您将此命令与`docker-compose.yml` 示例文件进行比较,您可能会注意到一些常见的设置,例如端口映射和映像引用。但是,此命令仅部署运行 OpenSearch 的单个容器,并且不会为 OpenSearch Dashboards 创建容器。此外,如果您想使用自定义 TLS 证书、用户或角色,或定义额外的卷和网络,那么这个“一行”命令会迅速变得不切实际。这就是 Docker Compose 变得有用的地方。

当您使用 Docker Compose 构建 OpenSearch 集群时,您可能会发现从主机向容器传递自定义配置文件比在 docker-compose.yml 中列举每个单独的设置更容易。与示例 docker run 命令使用 -v 标志从主机挂载卷到容器类似,Compose 文件可以将卷指定为相应服务的子选项进行挂载。以下截断的 YAML 文件演示了如何将文件或目录挂载到容器。有关卷使用和语法的全面信息,请参阅 Docker 官方文档中的部分。

services:
  opensearch-node1:
    volumes:
      - opensearch-data1:/usr/share/opensearch/data
      - ./custom-opensearch.yml:/usr/share/opensearch/config/opensearch.yml
  opensearch-node2:
    volumes:
      - opensearch-data2:/usr/share/opensearch/data
      - ./custom-opensearch.yml:/usr/share/opensearch/config/opensearch.yml
  opensearch-dashboards:
    volumes:
      - ./custom-opensearch_dashboards.yml:/usr/share/opensearch-dashboards/config/opensearch_dashboards.yml

用于开发的 Docker Compose 示例文件

如果您想从示例构建自己的 Compose 文件,请查看以下示例 docker-compose.yml 文件。此示例文件创建两个 OpenSearch 节点和一个 OpenSearch Dashboards 节点,并禁用了安全插件。在查看配置基本安全设置时,您可以使用此示例文件作为起点。

services:
  opensearch-node1:
    image: opensearchproject/opensearch:latest
    container_name: opensearch-node1
    environment:
      - cluster.name=opensearch-cluster # Name the cluster
      - node.name=opensearch-node1 # Name the node that will run in this container
      - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligibile to serve as cluster manager
      - bootstrap.memory_lock=true # Disable JVM heap memory swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
      - "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch
      - "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin
    ulimits:
      memlock:
        soft: -1 # Set memlock to unlimited (no soft or hard limit)
        hard: -1
      nofile:
        soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
        hard: 65536
    volumes:
      - opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container
    ports:
      - 9200:9200 # REST API
      - 9600:9600 # Performance Analyzer
    networks:
      - opensearch-net # All of the containers will join the same Docker bridge network
  opensearch-node2:
    image: opensearchproject/opensearch:latest
    container_name: opensearch-node2
    environment:
      - cluster.name=opensearch-cluster # Name the cluster
      - node.name=opensearch-node2 # Name the node that will run in this container
      - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
      - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligibile to serve as cluster manager
      - bootstrap.memory_lock=true # Disable JVM heap memory swapping
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
      - "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch
      - "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin
    ulimits:
      memlock:
        soft: -1 # Set memlock to unlimited (no soft or hard limit)
        hard: -1
      nofile:
        soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
        hard: 65536
    volumes:
      - opensearch-data2:/usr/share/opensearch/data # Creates volume called opensearch-data2 and mounts it to the container
    networks:
      - opensearch-net # All of the containers will join the same Docker bridge network
  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:latest
    container_name: opensearch-dashboards
    ports:
      - 5601:5601 # Map host port 5601 to container port 5601
    expose:
      - "5601" # Expose port 5601 for web access to OpenSearch Dashboards
    environment:
      - 'OPENSEARCH_HOSTS=["http://opensearch-node1:9200","http://opensearch-node2:9200"]'
      - "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true" # disables security dashboards plugin in OpenSearch Dashboards
    networks:
      - opensearch-net

volumes:
  opensearch-data1:
  opensearch-data2:

networks:
  opensearch-net:

配置基本安全设置

在将 OpenSearch 集群提供给外部主机之前,最好检查部署的安全配置。您可能还记得第一个`docker-compose.yml` 示例文件,除非通过设置 DISABLE_SECURITY_PLUGIN=true 禁用,否则捆绑脚本将向集群中的节点应用默认的演示安全配置。由于此配置用于演示目的,因此默认用户名和密码是已知的。因此,我们建议您创建自己的安全配置文件并使用 volumes 将这些文件传递给容器。有关 OpenSearch 安全设置的具体指导,请参阅安全配置

要在配置中使用您自己的证书,请将所有必要的证书添加到 Compose 文件的 volumes 部分

volumes:
  - ./root-ca.pem:/usr/share/opensearch/config/root-ca.pem
  - ./admin.pem:/usr/share/opensearch/config/admin.pem
  - ./admin-key.pem:/usr/share/opensearch/config/admin-key.pem
  - ./node1.pem:/usr/share/opensearch/config/node1.pem
  - ./node1-key.pem:/usr/share/opensearch/config/node1-key.pem

当您使用 Docker Compose 卷向 OpenSearch 节点添加 TLS 证书时,您还应该包含一个定义这些证书的自定义 opensearch.yml 文件。例如

volumes:
  - ./root-ca.pem:/usr/share/opensearch/config/root-ca.pem
  - ./admin.pem:/usr/share/opensearch/config/admin.pem
  - ./admin-key.pem:/usr/share/opensearch/config/admin-key.pem
  - ./node1.pem:/usr/share/opensearch/config/node1.pem
  - ./node1-key.pem:/usr/share/opensearch/config/node1-key.pem
  - ./custom-opensearch.yml:/usr/share/opensearch/config/opensearch.yml

请记住,您在 Compose 文件中指定的证书必须与您的自定义 opensearch.yml 文件中定义的证书相同。您应该用您自己的证书替换根证书、管理员证书和节点证书。有关更多信息,请参阅配置 TLS 证书

plugins.security.ssl.transport.pemcert_filepath: node1.pem
plugins.security.ssl.transport.pemkey_filepath: node1-key.pem
plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem
plugins.security.ssl.http.pemcert_filepath: node1.pem
plugins.security.ssl.http.pemkey_filepath: node1-key.pem
plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem
plugins.security.authcz.admin_dn:
  - CN=admin,OU=SSL,O=Test,L=Test,C=DE

配置安全设置后,您的自定义 opensearch.yml 文件可能类似于以下示例,它添加了 TLS 证书和管理员证书的专有名称 (DN),定义了一些权限,并启用了详细的审计日志记录

plugins.security.ssl.transport.pemcert_filepath: node1.pem
plugins.security.ssl.transport.pemkey_filepath: node1-key.pem
plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem
plugins.security.ssl.transport.enforce_hostname_verification: false
plugins.security.ssl.http.enabled: true
plugins.security.ssl.http.pemcert_filepath: node1.pem
plugins.security.ssl.http.pemkey_filepath: node1-key.pem
plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem
plugins.security.allow_default_init_securityindex: true
plugins.security.authcz.admin_dn:
  - CN=A,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA
plugins.security.nodes_dn:
  - 'CN=N,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'
plugins.security.audit.type: internal_opensearch
plugins.security.enable_snapshot_restore_privilege: true
plugins.security.check_snapshot_restore_write_privileges: true
plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access"]
cluster.routing.allocation.disk.threshold_enabled: false
opendistro_security.audit.config.disabled_rest_categories: NONE
opendistro_security.audit.config.disabled_transport_categories: NONE

有关设置的完整列表,请参阅安全

使用相同的过程在 /usr/share/opensearch/config/opensearch-security/config.yml 中指定后端配置,以及在其各自的 YAML 文件中指定新的内部用户、角色、映射、操作组和租户。

在替换证书并创建自己的内部用户、角色、映射、操作组和租户后,使用 Docker Compose 启动集群

docker compose up -d

使用插件

要将 OpenSearch 映像与自定义插件一起使用,您必须首先创建 Dockerfile。有关创建 Dockerfile 的信息,请查阅 Docker 官方文档。

FROM opensearchproject/opensearch:latest
RUN /usr/share/opensearch/bin/opensearch-plugin install --batch <pluginId>

然后运行以下命令

# Build an image from a Dockerfile
docker build --tag=opensearch-custom-plugin .
# Start the container from the custom image
docker run -p 9200:9200 -p 9600:9600 -v /usr/share/opensearch/data opensearch-custom-plugin

或者,您可能希望在部署映像之前从其中删除插件。此 Dockerfile 示例会删除安全插件

FROM opensearchproject/opensearch:latest
RUN /usr/share/opensearch/bin/opensearch-plugin remove opensearch-security

您还可以使用 Dockerfile 传递您自己的证书,以便与安全插件一起使用

FROM opensearchproject/opensearch:latest
COPY --chown=opensearch:opensearch opensearch.yml /usr/share/opensearch/config/
COPY --chown=opensearch:opensearch my-key-file.pem /usr/share/opensearch/config/
COPY --chown=opensearch:opensearch my-certificate-chain.pem /usr/share/opensearch/config/
COPY --chown=opensearch:opensearch my-root-cas.pem /usr/share/opensearch/config/