Elasticsearch 運維實戰之1 -- 集羣規劃

規劃一個可用於生產環境的elasticsearch集羣。html

集羣節點劃分

整個集羣的節點分爲如下三種主要類型node

  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 nodenginx

安裝與配置

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

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

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

ES_HEAP_SIZE=32g
JAVA_OPTS="-Xms32g"

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

* hard memlock unlimited
* soft memlock unlimited

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

  • 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有時不能達到效果,須要分開來作elasticsearch

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
相關文章
相關標籤/搜索