centos7下elasticsearch 集群安装、配置及示例

来源:互联网 发布:ubuntu u盘安装工具 编辑:程序博客网 时间:2024/06/05 20:48

简介 
本文是在两台centos7虚拟机下,安装了三个节点。本次搭建es同时实践了两种模式——单机模式和分布式模式。条件允许的话,可以在多台机器上配置es节点,如果你机器性能有限,那么可以在一台虚拟机上完成多节点的配置。 
如图,是本次3个节点的分布。

hostnameIPes节点master192.168.8.100node1、node3slave192.168.8.101node2注:es的主节点是选出来的,它不一定在master 机器上,也就是es主节点不一定非得是node1或node2,也可能是node3.

1、下载

名称版本下载地址elasticsearch6.1.1https://www.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.tar.gz

下载后,放到对应的目录下并解压. 因为我们要配置包含三个节点的集群,可以先将其重命名为elasticsearch-node1。比如存放路径及命名如: /home/zkpk/elasticsearch-node1。

2、修改配置文件

(1) 初步修改 

打开/home/zkpk/elasticsearch-node1/config目录下的elasticsearch.yml 文件 ,修改以下属性值并取消该行的注释:

# ======================== 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 consult the documentation for further information on configuration options:# https://www.elastic.co/guide/en/elasticsearch/reference/index.html## ---------------------------------- Cluster -----------------------------------## Use a descriptive name for your cluster:#cluster.name: elasticsearch## ------------------------------------ Node ------------------------------------## Use a descriptive name for the node:#node.name: es-node3## Add custom attributes to the node:##node.attr.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.memory_lock: true## Make sure that the heap size 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 address to a specific IP (IPv4 or IPv6):#network.host: 192.168.8.100## Set a custom port for HTTP:##http.port: 9200## For more information, consult the network module documentation.## --------------------------------- Discovery ----------------------------------## 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: ["192.168.8.104", "192.168.8.105", "192.168.8.104:9301"]## Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):#discovery.zen.minimum_master_nodes: 2 ## For more information, consult the zen discovery module documentation.## ---------------------------------- Gateway -----------------------------------## Block initial recovery after a full cluster restart until N nodes are started:##gateway.recover_after_nodes: 3## For more information, consult the gateway module documentation.## ---------------------------------- Various -----------------------------------## Require explicit names when deleting indices:##action.destructive_requires_name: truenetwork.bind_host: 192.168.8.104#设置绑定的ip地址,这是master虚拟机的IPnetwork.publish_host: 192.168.8.104#设置其它节点和该节点交互的ip地址

(2) 进一步修改 
拷贝 elasticsearch-node1 整个文件夹,两份,一份elasticsearch-node2,一份elasticsearch-node3. 
将elasticsearch-node2 文件夹copy到另外一台IP为192.168.8.105的机器上。而在 192.168.8.104 机器上有 node1和node3.

对于node3: node3和node1在一台机器上,node1的配置文件里端口默认分别是9300和9200,所以要改一下node3配置文件里的端口,elasticsearch.yml 文件修改如下:

node.name: "es-node3"
# 在配置文件最后添加下面配置信息transport.tcp.port: 9301http.port: 9201


对于node2: 对 elasticsearch.yml 修改如下:
node.name: "es-node2"network.bind_host: 192.168.8.105network.publish_host: 192.168.8.105network.host: 192.168.8.105

二、运行 & 关闭 elasticsearch

1、运行elasticsearch:

前台运行命令:

[lyz@localhost /]$ sh /home/zkpk/elasticsearch-node1/bin/elasticsearc

后台运行命令:

[lyz@localhost /]$ sh /home/zkpk/elasticsearch-node1/bin/elasticsearch -d

2、关闭elasticsearch:

前台运行:可以通过”CTRL+C”组合键来停止运行 
后台运行,可以通过”kill -15 进程号”停止.也可以通过REST API接口:

通过如下语句关闭整个集群:

curl -XPOST http://主机IP:9200/_cluster/nodes/_shutdown
通过如下语句关闭单个节点:
curl -XPOST http://主机IP:9200/_cluster/nodes/节点标示符(如es-node1)/_shutdown

三、错误解决

1、启动es过程这若报以下错误:
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
这是因为elasticsearch默认是不支持用root用户来启动的,会报错。解决方案为添加其他用户:
chown -R lyz:lyz elasticsearch-node1
2、对于以下错误:
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解决方式如下:

ulimit -n 65536 or set nofile to 65536 in /etc/security/limits.conf
3、对如下错误
max number of threads [1024] for user [xxx] is too low, increase to at least [2048]
解决方式:
ulimit -u 2048Or set the nproc value to 2048 or above in /etc/security/limits.conf before starting elasticsearch.
4、对于错误:
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决:
set vm.max_map_count=262144 in /etc/sysctl.conf then do sysctl -p


阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 金鳞岂是池中物候龙涛 金鳞岂是池中物候 金鳞岂是池中之物候耀涛 怎么画二次元小萌物 即物起兴 睹物兴情 触物兴怀 睹物兴悲 即物起兴的读音 即物起兴的意思 物化 物化女性 物化是什么意思 物化第五版上册答案傅献彩 物化劳动和活劳动 活劳动和物化劳动 物华 郑州物华国际 到处皆诗境随时有物华的意思 物哀 正方体物品 私人物品 物品 超级物品 物品的英文 物品图片 中国物品编码中心 物品编码中心 出差必备物品 我能升级物品 我能提升物品等级 正方体物品有哪些 神话物品专卖店 旅游物品清单 旅游必带物品清单2018 旅游必带物品清单 二手闲置物品转让平台 飞机禁带物品清单 重装机兵攻略隐藏物品 重装机兵1攻略隐藏物品 希尔薇商店特殊物品挤奶器