1. 程式人生 > 其它 >Elasticsearch7.13.3叢集搭建(三節點)

Elasticsearch7.13.3叢集搭建(三節點)

準備

  • 三臺機器

    IP HOSTANME OS 是否是主節點
    172.16.241.2 linux1 centos8
    172.16.241.3 linux2 centos8
    172.16.241.4 linux3 centos8
  • Es不允許使用root啟動,故而建立使用者和組(三臺機器)

    groupadd es
    useradd es -g es -p es
    su es
    
  • 設定系統配置(切換root使用者)

    vi /etc/sysctl.conf
    #設定如下
    vm.max_map_count=262144
    #執行生效
    sysctl -p 
    
    
    vi /etc/security/limits.conf
    #增加如下內容
    # * 代表所有,可以修改為使用者es
    *  soft nproc  4096 
    *  hard nproc  4096
    
    
  • 開啟linux1機器,進入/home/es/目錄,執行如下指令:

    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.3-linux-x86_64.tar.gz
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.3-linux-x86_64.tar.gz.sha512
    shasum -a 512 -c elasticsearch-7.13.3-linux-x86_64.tar.gz.sha512 // 如找不到指令,使用yum install -y perl-Digest-SHA 安裝
    tar -xzf elasticsearch-7.13.3-linux-x86_64.tar.gz
    
  • 使用scp指令分發elasticsearch-7.13.3到其他機器上

    1. scp傳檔案到linux2,linux3

      scp -r elasticsearch-7.13.3 root@linux2:/home/es
      
      
      scp -r elasticsearch-7.13.3 root@linux2:/home/es
      

配置

  • 修改config下的elasticsearch.yaml檔案

    1. linux1(master)
    #叢集配置
    cluster:
      name: xpp-es-cluster
      initial_master_nodes:
        - linux1
    path:
      data: /home/es/elasticsearch-7.13.3/data
      logs: /home/es/elasticsearch-7.13.3/data
    node:
      name: linux1
    network:
      host: linux1
    discovery.seed_hosts:
      - linux1:9300
      - linux2:9300
      - linux3:9300
    
    1. linux2

      #叢集配置
      cluster:
        name: xpp-es-cluster
        initial_master_nodes:
          - linux1
      path:
        data: /home/es/elasticsearch-7.13.3/data
        logs: /home/es/elasticsearch-7.13.3/data
      node:
        name: linux2
        roles: [data]
      network:
        host: linux2
      discovery.seed_hosts:
        - linux1:9300
        - linux2:9300
        - linux3:9300
      
    2. linux3

      #叢集配置
      cluster:
        name: xpp-es-cluster
        initial_master_nodes:
          - linux1
      path:
        data: /home/es/elasticsearch-7.13.3/data
        logs: /home/es/elasticsearch-7.13.3/data
      node:
        name: linux3
        roles: [data]
      network:
        host: linux3
      discovery.seed_hosts:
        - linux1:9300
        - linux2:9300
        - linux3:9300
      
  • 先啟動linux1下的es,再啟動linux2, linux3

    ./elasticsearch -d

  • 訪問http://linux1:9200

    使用chrome外掛elasticsearch head外掛訪問如圖:

  • 建立索引book, user, shopping

    curl --location --request PUT 'http://linux1:9200/book'
    curl --location --request PUT 'http://linux1:9200/user'
    curl --location --request PUT 'http://linux1:9200/shopping'
    
  • 檢視叢集狀態

    索引已經建立,並且資料分片沒有問題。綠色代表健康。

  • 建立Doc

    curl --location --request POST 'http://linux1:9200/shopping/_doc/' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "title":"華為手機魅藍",
        "category":"華為",
        "images":"http://www.gulixueyuan.com/xm.jpg",
        "price": 4999.00
    }'
    
  • 返回結果

    {
        "_index": "shopping",
        "_type": "_doc",
        "_id": "XtfNw3oBpJTUlLZO2-rD",
        "_version": 1,
        "result": "created",
        "_shards": {
            "total": 2,
            "successful": 2,
            "failed": 0
        },
        "_seq_no": 0,
        "_primary_term": 1
    }
    

三節點的叢集搭建完畢,該叢集有什麼問題?如果master掛掉還能否正常提供服務?

本文來自部落格園,作者:皮皮1109,轉載請註明原文連結:https://www.cnblogs.com/pipi1109/p/15036765.html