Elasticsearch 运维实战之1 -- 集群规划

AaliyahBlak 3年前
   <p>来自: <a href="/misc/goto?guid=4959670118584669247" rel="nofollow">http://www.cnblogs.com/hseagle/p/5372566.html</a></p>    <p>规划一个可用于生产环境的elasticsearch集群。</p>    <h2>集群节点划分</h2>    <p>整个集群的节点分为以下三种主要类型</p>    <ol>     <li>Master nodes -- 负责维护集群状态,不保存index数据, 硬件要求: 一般性的机器就可以,给es进程分配16g内存</li>     <li>Data Nodes -- 只保存index的数据,不被选举为Master nodes 硬件要求: 配置要求越高越好,使用大硬盘,有条件可以上SSD硬盘</li>     <li>Client Nodes -- 主要用于负载均衡,不被选举为Master node, 也不保存index数据 硬件要求: 24核CPU, 64G内存或更高</li>    </ol>    <p>一个合理的集群应该包含三个master nodes, 1到多个data nodes, 最少一个client node</p>    <h2>安装与配置</h2>    <p>通用配置,以centos为例,使用rpm安装包</p>    <pre>  sudo rpm -ivh elasticsearch-version.rpm  sudo chkconfig --add elasticsearch</pre>    <p>修改/etc/sysconfig/elasticsearch, 修改ES_HEAP_SIZE和JAVA_OPTS的内容,注意elasticsearch建议使用的最大内存是32G,</p>    <pre>  ES_HEAP_SIZE=32g  JAVA_OPTS="-Xms32g"</pre>    <p>修改/etc/security/limits.conf, 添加如下内容</p>    <pre>  * hard memlock unlimited  * soft memlock unlimited</pre>    <p>/etc/elasticsearch/elasticsearch.yml内容配置</p>    <ul>     <li>master节点</li>    </ul>    <pre>  node.master: true  node.data: false  discovery.zen.ping.unicast.hosts: ["master1","master2","master3"]  network.host: ${HOSTNAME}</pre>    <ul>     <li>data节点</li>    </ul>    <pre>  node.master: false  node.data: true  discovery.zen.ping.unicast.hosts: ["master1","master2","master3"]  network.host: ${HOSTNAME}</pre>    <p>如果为elasticsearch配置了多块硬盘,可以修改 <strong>DATA_DIR</strong> 的值,多个目录使用逗号(,)分开</p>    <ul>     <li>client节点</li>    </ul>    <pre>  node.master: false  node.data: false  discovery.zen.ping.unicast.hosts: ["master1","master2","master3"]  network.host: ${HOSTNAME}</pre>    <h2>启动elasticsearch</h2>    <pre>  sudo service elasticsearch start</pre>    <p>需要注意的是elasticsearch在centos中使用service elasticsearch restart有时不能达到效果,需要分开来做</p>    <pre>  sudo kill -9 `pgrep -f elasticsearch`  sudo service elasticsearch start</pre>    <h2>nginx反向代理</h2>    <p>为了记录针对集群的查询内容,建议使用nginx来做反向代理,nginx安装在client node上, <strong>conf.d/default.conf</strong> 最简单的配置如下</p>    <pre>  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;      }  }</pre>    <h2>插件安装</h2>    <p>建议安装如下插件</p>    <ul>     <li>kopf 兼容es 1.x, 2.x</li>    </ul>    <p><a href="/misc/goto?guid=4959670118666360037" rel="nofollow,noindex">kopf</a></p>    <pre>  ./elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/{branch|version}</pre>    <ul>     <li>head 兼容es 1.x</li>     <li>bigdesk 兼容es 1.x</li>    </ul>