Elasticsearch 運維實戰之1 -- 集群規划


規划一個可用於生產環境的elasticsearch集群。

集群節點划分

整個集群的節點分為以下三種主要類型

  1. Master nodes -- 負責維護集群狀態,不保存index數據, 硬件要求: 一般性的機器就可以,給es進程分配16g內存
  2. Data Nodes -- 只保存index的數據,不被選舉為Master nodes 硬件要求: 配置要求越高越好,使用大硬盤,有條件可以上SSD硬盤
  3. Client Nodes -- 主要用於負載均衡,不被選舉為Master node, 也不保存index數據 硬件要求: 24核CPU, 64G內存或更高

一個合理的集群應該包含三個master nodes, 1到多個data nodes, 最少一個client node

安裝與配置

通用配置,以centos為例,使用rpm安裝包

sudo rpm -ivh elasticsearch-version.rpm
sudo chkconfig --add elasticsearch

修改/etc/sysconfig/elasticsearch, 修改ES_HEAP_SIZE和JAVA_OPTS的內容,注意elasticsearch建議使用的最大內存是32G,

ES_HEAP_SIZE=32g
JAVA_OPTS="-Xms32g"

修改/etc/security/limits.conf, 添加如下內容

* hard memlock unlimited
* soft memlock unlimited

/etc/elasticsearch/elasticsearch.yml 內容配置

  • master節點
node.master: true
node.data: false
discovery.zen.ping.unicast.hosts: ["master1","master2","master3"]
network.host: ${HOSTNAME}
  • data節點
node.master: false
node.data: true
discovery.zen.ping.unicast.hosts: ["master1","master2","master3"]
network.host: ${HOSTNAME}

如果為elasticsearch配置了多塊硬盤,可以修改 DATA_DIR 的值,多個目錄使用逗號(,)分開

  • client節點
node.master: false
node.data: false
discovery.zen.ping.unicast.hosts: ["master1","master2","master3"]
network.host: ${HOSTNAME}

啟動elasticsearch

sudo service elasticsearch start

需要注意的是elasticsearch在centos中使用service elasticsearch restart有時不能達到效果,需要分開來做

sudo kill -9 `pgrep -f elasticsearch`
sudo service elasticsearch start

nginx反向代理

為了記錄針對集群的查詢內容,建議使用nginx來做反向代理,nginx安裝在client node上,conf.d/default.conf 最簡單的配置如下

upstream elasticsearch {
        server 127.0.0.1:9200;
}

server {
    gzip on;
    access_log /var/log/nginx/access.log combined;
    listen       80 default_server;

    server_name  _;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass      http://elasticsearch;
    }

   error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

插件安裝

建議安裝如下插件

  • kopf 兼容es 1.x, 2.x

kopf

./elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/{branch|version}
  • head 兼容es 1.x
  • bigdesk 兼容es 1.x


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM