elasticsearch2.0集群安装配置

来源:互联网 发布:淘宝卖家被处罚的原因 编辑:程序博客网 时间:2024/05/21 10:03

背景

原来项目中我们主要用solr作为hbase的二级索引,这样来增强命中率,现在实时插入solr那一块感觉已经有点扛不住了,而solr集群配置后扩展也是一个问题,而他的一个竞争产品就是而是,原来在做日志分析的时候有尝试用elk,所以现在打算尝试使用一下es,看一下压测下的具体表现,最主要是es的去中心化对我们很有吸引力,动态扩展起来很方便

开始

一切的开始都是从集群的安装配置开始,原来使用elk的时候我配置的是单机,这次由于要做压力测试,所以打算用三台服务器
先解压,进入config目录,进行配置文件的更改,不得不说现在网上的教程大部分还是1.x版本的,2.x版本的教程不算多,而且2.x版本关于局域网内自动加入集群的配置和1.x也不太相同

# ======================== Elasticsearch Configuration =========================## NOTE: Elasticsearch comes with reasonable defaults for most settings.#       Before you set out to tweak and tune the configuration, make sure you#       understand what are you trying to accomplish and the consequences.## The primary way of configuring a node is via this file. This template lists# the most important settings you may want to configure for a production cluster.## Please see the documentation for further information on configuration options:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>## ---------------------------------- Cluster -----------------------------------## Use a descriptive name for your cluster:## cluster.name: my-application## ------------------------------------ Node ------------------------------------## Use a descriptive name for the node:## node.name: node-1## Add custom attributes to the node:## node.rack: r1## ----------------------------------- Paths ------------------------------------## Path to directory where to store the data (separate multiple locations by comma):## path.data: /path/to/data## Path to log files:## path.logs: /path/to/logs## ----------------------------------- Memory -----------------------------------## Lock the memory on startup:## bootstrap.mlockall: true## Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory# available on the system and that the owner of the process is allowed to use this limit.## Elasticsearch performs poorly when the system is swapping the memory.## ---------------------------------- Network -----------------------------------## Set the bind adress to a specific IP (IPv4 or IPv6):## network.host: 192.168.0.1## Set a custom port for HTTP:## http.port: 9200## For more information, see the documentation at:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>## ---------------------------------- Gateway -----------------------------------## Block initial recovery after a full cluster restart until N nodes are started:## gateway.recover_after_nodes: 3## For more information, see the documentation at:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>## --------------------------------- Discovery ----------------------------------## Elasticsearch nodes will find each other via unicast, by default.## Pass an initial list of hosts to perform discovery when new node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]## discovery.zen.ping.unicast.hosts: ["host1", "host2"]## Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):## discovery.zen.minimum_master_nodes: 3## For more information, see the documentation at:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>## ---------------------------------- Various -----------------------------------## Disable starting multiple nodes on a single system:## node.max_local_storage_nodes: 1## Require explicit names when deleting indices:## action.destructive_requires_name: true

这个配置文件中主要要修改的几个参数是:
第一个是cluster.name,这个相当于集群的名字
在同一个集群中应该使用统一的cluster.name
第二个就是区分自己身份的node.name,相当于集群里的的唯一标识
第三个就是最重要的一个,也是和1.x版本有本质区别的参数discovery.zen.ping.unicast.hosts
这个参数主要将集群内所有机器的地址加入进去,这样就可以动态的进行扩展和平衡
第四个参数是对地址的绑定network.host,我们将对应ip绑定到该参数就可以
所以最后我们的配置是
ip机器名映射

ip hostname 192.168.0.1 node1 192.168.0.2 node2 192.168.0.3 node3

配置参数

host cluster.name node.name discovery.zen.ping.unicast.hosts network.host node1 mytest node-1 [“node1”,”node2”,”node3”] 192.168.0.1 node2 mytest node-2 [“node1”,”node2”,”node3”] 192.168.0.2 node3 mytest node-3 [“node1”,”node2”,”node3”] 192.168.0.3

接下来进行启动,为了省事,我是直接以root启动的,不过一个大大的Error告诉我们不能用root启动error root
这类错误解决起来也相当easy,创建一个新的用户es,启动,注意的是要将路径中的data,log的权限也改成es可操作的,最简单的就是将整个文件夹的所有者指定为es,所以说linux就是一只权限狗
chown -R es:es es的安装路径
下面写一个简单的脚本简化启动

#!/bin/bashsu - es -c "espath/bin/elasticserach"

下次我们启动就直接执行脚本了
如果你观察到如下信息,恭喜你,集群已经可以运行了
启动
下面查看集群信息:
在浏览器执行http://localhost:9200/_cat/node?V
注意把localhost换成集群中的任意一台
cluster

我们下面关掉node1,再次查看
kill node1

再次运行,查看
这里写图片描述

发现现在master已经变成了node-3,所以说这个动态的扩展很有吸引力

插件安装

我主要安装一个head插件
执行的命令是
elasticsearch/bin/plugin install mobz/elasticsearch-head
很多教程都写成-install,但我发现其实正确的是install,这种方式是去github上clone项目安装,需要网络,如果我们没有网络,那可以选择离线安装,这里给个传送门
我们查看一下安装的效果,
执行http://localhost:9200/_plugin/head
head

end

后面的一段时间打算仔细研究一下这个技术,在研究后再和大家讨论交流

0 0