• 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
  • 相关阅读:
    [Visual Studio] [Config] [Transformation] [SlowCheetah] 在非Web工程中使用Transformation
    [SQLSERVER] 把TransactionLog截断
    [Windows] [Firewall] 增加进入规则
    [POWERSHELL] [.net 3.5] [Windows Server] 在Windows Server上安装.NET3.5
    杂碎
    VSCode 使用Settings Sync同步配置(最新版教程,非常简单)
    JavaScript:ES2019 的新特性
    重新认识构造函数、原型和原型链
    如何实现 React 中的状态自动保存?
    深拷贝
  • 原文地址:https://www.cnblogs.com/hseagle/p/5372566.html
Copyright © 2020-2023  润新知