Elasticsearch入门(2)elasticsearch的配置


声明:本文转载自https://my.oschina.net/codingcloud/blog/1615013,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

elasticsearch的配置

先来看一下elasticsearch的配置文件:

# ======================== 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: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 定义该节点的名称,每个节点不可以重复
#node.name: node-1
#
# 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):
# 指定本机IP地址
network.host: 172.19.26.110

# Set a custom port for HTTP:
# 指定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: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# 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: true

 

一、 配置Network部分

 实现局域网内访问elasticsearch服务

在开始之前,我们首先得确保 宿主机和虚拟机的网络是互相可以ping通的,如果没有做过相关配置,建议先移步:https://my.oschina.net/codingcloud/blog/638220 完成配置,然后再继续往下走。

PS:注意关闭宿主机和虚拟机的防火墙哦,不然会遇到各种莫名其妙的问题,关闭防火墙命令可移步:https://my.oschina.net/codingcloud/blog/757515 查找。

通过修改 elasticsearch.yml配置,我们来实现局域网内访问elasticsearch服务,将host和port相应配置修改成局域网的一个固定IP,然后重新启动。

# ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: 172.19.26.110 # # Set a custom port for HTTP: # http.port: 9200 # # For more information, consult the network module documentation. 

执行启动命令 ./bin/elasticsearch 启动后,会发现报2个错,如下:

[2018-01-28T23:51:35,180][INFO ][o.e.t.TransportService   ] [qR5cyzh] publish_address {172.19.26.110:9300}, bound_addresses {172.19.26.110:9300} [2018-01-28T23:51:35,204][INFO ][o.e.b.BootstrapChecks    ] [qR5cyzh] bound or publishing to a non-loopback address, enforcing bootstrap checks ERROR: [2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 

 

1、报错 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]是因为操作系统vm.max_map_count参数设置太小导致的,至于设置多大的数值,我这里就直接参照报错信息的建议直接设置为262144

解决方案一:

切换到root用户下,执行以下命令:

sysctl -w vm.max_map_count=262144

检查配置是否生效

[root@localhost elasticsearch-6.1.2]# sysctl -a | grep "vm.max_map_count" vm.max_map_count = 262144 [root@localhost elasticsearch-6.1.2]# 

如果正常输出262144,则说明修改成功,然后再次启动elasticsearch,输出如下:

[2018-01-29T00:24:36,619][INFO ][o.e.n.Node               ] initialized [2018-01-29T00:24:36,619][INFO ][o.e.n.Node               ] [qR5cyzh] starting ... [2018-01-29T00:24:36,949][INFO ][o.e.t.TransportService   ] [qR5cyzh] publish_address {172.19.26.110:9300}, bound_addresses {172.19.26.110:9300} [2018-01-29T00:24:37,015][INFO ][o.e.b.BootstrapChecks    ] [qR5cyzh] bound or publishing to a non-loopback address, enforcing bootstrap checks ERROR: [1] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2018-01-29T00:24:37,038][INFO ][o.e.n.Node               ] [qR5cyzh] stopping ... [2018-01-29T00:24:37,089][INFO ][o.e.n.Node               ] [qR5cyzh] stopped [2018-01-29T00:24:37,089][INFO ][o.e.n.Node               ] [qR5cyzh] closing ... [2018-01-29T00:24:37,128][INFO ][o.e.n.Node               ] [qR5cyzh] closed 

这时候会发现只有一个错了,说明以上配置处理成功。

解决方案二(推荐):永久性修改

  • 切换到root用户,备份原有配置
[root@localhost elasticsearch-6.1.2]# cd /etc [root@localhost etc]# cp sysctl.conf sysctl.conf.bak  
  • 编辑sysctl.conf,增加如下内容
[root@localhost etc]# vim sysctl.conf  # elasticsearch config start vm.max_map_count=262144 # elasticsearch config end

 

下面我们来解决另一个问题

2、报错max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]是因为操作系统安全检测配置影响的,我们需要切换到root用户下做如下配置:

先做一个配置备份

[root@localhost elasticsearch-6.1.2]# cd /etc/security/ [root@localhost security]# cp limits.conf limits.conf.bak 

然后编辑limits.conf增加如下配置:

# elasticsearch config start * soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096 # elasticsearch config end 

执行启动命令 ./bin/elasticsearch ,会发现指定IP已经配置好了,也正常启动。

publish_address {172.19.26.110:9200}, bound_addresses {172.19.26.110:9200}

[2018-01-29T01:10:58,076][INFO ][o.e.d.DiscoveryModule    ] [qR5cyzh] using discovery type [zen] [2018-01-29T01:10:59,124][INFO ][o.e.n.Node               ] initialized [2018-01-29T01:10:59,125][INFO ][o.e.n.Node               ] [qR5cyzh] starting ... [2018-01-29T01:10:59,441][INFO ][o.e.t.TransportService   ] [qR5cyzh] publish_address {172.19.26.110:9300}, bound_addresses {172.19.26.110:9300} [2018-01-29T01:10:59,448][INFO ][o.e.b.BootstrapChecks    ] [qR5cyzh] bound or publishing to a non-loopback address, enforcing bootstrap checks [2018-01-29T01:11:03,107][INFO ][o.e.c.s.MasterService    ] [qR5cyzh] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{gcZ8nEbmSAGsR8BrJ-f5rw}{172.19.26.110}{172.19.26.110:9300} [2018-01-29T01:11:03,115][INFO ][o.e.c.s.ClusterApplierService] [qR5cyzh] new_master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{gcZ8nEbmSAGsR8BrJ-f5rw}{172.19.26.110}{172.19.26.110:9300}, reason: apply cluster state (from master [master {qR5cyzh}{qR5cyzhRQUix7PbCNFViTw}{gcZ8nEbmSAGsR8BrJ-f5rw}{172.19.26.110}{172.19.26.110:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]]) [2018-01-29T01:11:03,162][INFO ][o.e.h.n.Netty4HttpServerTransport] [qR5cyzh] publish_address {172.19.26.110:9200}, bound_addresses {172.19.26.110:9200} [2018-01-29T01:11:03,162][INFO ][o.e.n.Node               ] [qR5cyzh] started [2018-01-29T01:11:03,242][INFO ][o.e.g.GatewayService     ] [qR5cyzh] recovered [0] indices into cluster_state 

那我们先利用curl在虚拟机本地测试一下,结果如下:

[elasticsearch@localhost ~]$ curl "172.19.26.110:9200" {   "name" : "qR5cyzh",   "cluster_name" : "elasticsearch",   "cluster_uuid" : "I52THkAwTU-oB8GQs_7jhQ",   "version" : {     "number" : "6.1.2",     "build_hash" : "5b1fea5",     "build_date" : "2018-01-10T02:35:59.208Z",     "build_snapshot" : false,     "lucene_version" : "7.1.0",     "minimum_wire_compatibility_version" : "5.6.0",     "minimum_index_compatibility_version" : "5.0.0"   },   "tagline" : "You Know, for Search" } [elasticsearch@localhost ~]$  

虚拟机本地没问题,我们再用宿主机浏览器来一下,没问题!

好了,到此为止我们的network模块的配置就完成了。

二、 配置Cluster 部分

待更新。。。

 

 

参考文档

https://zhuanlan.zhihu.com/p/22241634?refer=dataeye

http://www.chepoo.com/elasticsearch-installation-parameters-configuration-considerations.html

本文发表于2018年01月30日 10:32
(c)注:本文转载自https://my.oschina.net/codingcloud/blog/1615013,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 2187 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1