zoukankan      html  css  js  c++  java
  • 使用elasticsearch7.3版本在一台主机上部署多个实例组建集群

    系统:centos 7.4 x64
    主机ip:192.168.0.160
    软件包:elasticsearch-7.3.0-linux-x86_64.tar.gz

    配置步骤

    vim /etc/security/limits.conf
    * soft nofile 65537
    * hard nofile 65537
    * soft nproc 65537
    * hard nproc 65537
    
    vim /etc/sysctl.conf
    vm.max_map_count = 262144
    net.core.somaxconn = 65535
    net.ipv4.ip_forward = 1
    
    cd /usr/local/src
    tar -zxv -f elasticsearch-7.3.0-linux-x86_64.tar.gz -C /usr/local/
    cd /usr/local/
    cp elasticsearch-7.3.0 elasticsearch-7.3.0_node1
    cp elasticsearch-7.3.0 elasticsearch-7.3.0_node2
    cp elasticsearch-7.3.0 elasticsearch-7.3.0_node3
    useradd elastic
    chown -R elastic:elastic elasticsearch-7.3.0_node1
    chown -R elastic:elastic elasticsearch-7.3.0_node2
    chown -R elastic:elastic elasticsearch-7.3.0_node3
    
    # 如下是每个节点的配置文件内容
    # 1
    cluster.name: my-application
    node.name: node-1
    
    # 主节点
    node.master: true
    # 数据节点
    node.data: true 
    
    network.host: 192.168.0.160
    http.port: 9200
    transport.port: 9300
    
    discovery.seed_hosts: ["192.168.0.160:9300", "192.168.0.160:9301","192.168.0.160:9302"]
    cluster.initial_master_nodes: ["node-1"] # 确保当前节点是主节点
    
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    
    # 2
    cluster.name: my-application
    node.name: node-2
    
    node.master: false
    node.data: true 
    
    network.host: 192.168.0.160
    http.port: 9201
    transport.port: 9301
    
    discovery.seed_hosts: ["192.168.0.160:9300", "192.168.0.160:9301","192.168.0.160:9302"]
    cluster.initial_master_nodes: ["node-1", "node-2","node3"]
    
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    # 3
    cluster.name: my-application
    node.name: node-3
    
    node.master: false
    node.data: true 
    
    network.host: 192.168.0.160
    http.port: 9202
    transport.port: 9302
    
    discovery.seed_hosts: ["192.168.0.160:9300", "192.168.0.160:9301","192.168.0.160:9302"]
    cluster.initial_master_nodes: ["node-1","node-2","node-3"]
    
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    

    若报错说找不到主节点,可以先启动主节点,等主节点集群建立后,再启动从节点,观察从节点日志输出,确保从节点加入集群。

    分别启动的话需要先切换到elastic普通用户,然后运行/usr/local/elasticsearch-7.3.0-cluster-node1/bin/elasticsearch

    可以先分别启动查看状态,待配置无误后再用脚本启动

    启动脚本

    #!/bin/bash
    
    /usr/bin/su - elastic -c '/usr/local/elasticsearch-7.3.0-cluster-node1/bin/elasticsearch -p /tmp/elasticsearch_9200_pid -d'
    /usr/bin/su - elastic -c '/usr/local/elasticsearch-7.3.0-cluster-node2/bin/elasticsearch -p /tmp/elasticsearch_9201_pid -d'
    /usr/bin/su - elastic -c '/usr/local/elasticsearch-7.3.0-cluster-node3/bin/elasticsearch -p /tmp/elasticsearch_9202_pid -d'
    

    关闭脚本

    #!/bin/bash
    
    kill -9 `ps -u elastic|awk '{print $1}'`
    

    测试

    查看集群主从分配

    http://192.168.0.160:9200/_cat/nodes?v

    ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
    192.168.0.160           35          97   0    0.04    0.23     0.22 di        -      node-3
    192.168.0.160           15          97   0    0.04    0.23     0.22 dim       *      node-1
    192.168.0.160           31          97   0    0.04    0.23     0.22 di        -      node-2
    
    

    查看集群状态

    http://192.168.0.160:9200/_cluster/health?pretty

    {
      "cluster_name": "my-application",
      "status": "green",
      "timed_out": false,
      "number_of_nodes": 3,
      "number_of_data_nodes": 3,
      "active_primary_shards": 0,
      "active_shards": 0,
      "relocating_shards": 0,
      "initializing_shards": 0,
      "unassigned_shards": 0,
      "delayed_unassigned_shards": 0,
      "number_of_pending_tasks": 0,
      "number_of_in_flight_fetch": 0,
      "task_max_waiting_in_queue_millis": 0,
      "active_shards_percent_as_number": 100.0
    }
    

    其他部署方式

    还有一种部署方式是创建不同的配置文件路径来进行启动,比较麻烦就不实验了

  • 相关阅读:
    占位
    提高班整风带给我的思考
    Servlet笔记
    CommandArgument传多个值
    asp.net中怎么判断request的一个值是否为空
    asp.net中cookie中文乱码的解决
    datatable的手工构造过程
    .net c#日期时间函数大全
    【转载】[.net程序员面试题]
    javascript自动生成表格行
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/11433741.html
Copyright © 2011-2022 走看看