Centos安装OpenSearch、OpenSearch-Dashboards

1,004 阅读3分钟

参考安装文档

1、背景

OpenSearch官方推荐使用Docker-Compose进行安装,在Centos服务器上使用官方提供的docker-compose.yml进行安装。

version: '3'
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
    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"
    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:

在服务器上执行docker-compose up -d命令安装OpenSearch,安装完成后提示:CPU does not support x86-64-v2,在Github上查找解决方法都未能成功。使用官方RPM进行OpenSearch安装。

2、RPM安装OpenSearch

按照官方提供的文档进行安装(本文记录一下安装时遇到的问题和解决方法)

OpenSearch安装步骤:

# 1、使用 YUM repository安装

# 2、OpenSearch 创建本地存储库文件
curl -SL https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/opensearch-2.x.repo -o /etc/yum.repos.d/opensearch-2.x.repo

# 3、列出可用版本
yum list opensearch --showduplicates

# 4、选择安装版本 不添加版本号默认安装最新版OpenSearch
yum install opensearch

# 5、运行OpenSearch
systemctl start opensearch

# 6、查看OpenSearch状态
systemctl status opensearch

OpenSearch环境配置:

  • OpenSearch绑定到主机上IP或网络接口

vim /etc/opensearch/opensearch.yml打开opensearch.yml配置文件,添加network.hostdiscovery.typeplugins.security.disabled信息,wq保存修改。

# 将OpenSearch绑定到正确的网络接口。使用0.0.0.0 包括所有可用接口或指定IP地址分配给特定的接口。
network.host: 0.0.0.0

# 如果已经配置群集,单节点安装需要将discovery.type为单个节点否则会引导集群检查
discovery.type: single-node

plugins.security.disabled: false
  • 指定初始JVM 堆大小

vim /etc/opensearch/jvm.options打开jvm.options配置文件,修改JVM大小。

-Xms4g
-Xmx4g

重启OpenSearch服务。

3、RPM安装OpenSearch-Dashboards

OpenSearch-Dashboard安装步骤:

# 1、创建本地存储库文件
curl -SL https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/2.x/opensearch-dashboards-2.x.repo -o /etc/yum.repos.d/opensearch-dashboards-2.x.repo

# 2、选择安装版本 不添加版本号默认安装最新版OpenSearch-dashboard
yum install opensearch-dashboards

# 3、启动opensearch-dashboards
systemctl start opensearch-dashboards

OpenSearch-dashboards环境配置:

  • OpenSearch-Dashboards放开端口

vim /etc/opensearch-dashboards/opensearch_dashboards.yml打开opensearch_dashboards.yml文件修改server.host配置。

 server.host: 0.0.0.0
  • 重启OpenSearch-Dashboards
systemctl restart opensearch-dashboards

4、安装验证

本地浏览器输入https://IP:9200/ElasticSearch端口一致,第一次访问需要输入账户和密码。默认账户和密码都是admin。访问显示下面这串JSON即为安装成功

本地浏览器输入https://IP:5601/app/home#/,第一次访问需要输入账户和密码。默认账户和密码都是admin

接下来可以尽情创建自己的面板和数据: