elasticsearch的config文件夹里面有两个配置文件:elasticsearch.yml和logging.yml,第一个是es的基本 配置文件,第二个是日志配置文件,es也是使用log4j来记录日志的,因此logging.yml里的设置按普通log4j配置文件来设置就好了。node
下面 主要讲解下elasticsearch.yml这个文件中可配置的东西。
配置es的集群名称,默认是elasticsearch,es会自动发如今同一网段下的es,若是在同一网段下有多个集群,就能够用这个属性来区分不一样的集群。 linux
节点名,默认随机指定一个name列表中名字,该列表在es的jar包中config文件夹里name.txt文件中,其中有不少做者添加的有趣名字。 git
指定该节点是否有资格被选举成为node,默认是true,es是默认集群中的第一台机器为master,若是这台机挂了就会从新选举master。 github
指定该节点是否存储索引数据,默认为true。 bootstrap
设置默认索引分片个数,默认为5片。 服务器
设置默认索引副本个数,默认为1个副本。 网络
设置配置文件的存储路径,默认是es根目录下的config文件夹。 并发
设置索引数据的存储路径,默认是es根目录下的data文件夹 app
能够设置多个存储路径,用逗号隔开,例: 负载均衡
设置临时文件的存储路径,默认是es根目录下的work文件夹。
设置日志文件的存储路径,默认是es根目录下的logs文件夹
设置插件的存放路径,默认是es根目录下的plugins文件夹
强制全部内存锁定,不要搞什么swap的来影响性能
设置为true来锁住内存。由于当jvm开始swapping时es的效率会下降,因此要保证它不swap,能够把ES_MIN_MEM和 ES_MAX_MEM两个环境变量设置成同一个值,而且保证机器有足够的内存分配给es。同时也要容许elasticsearch的进程能够锁住内 存,linux下能够经过`ulimit -l unlimited`命令。
设置绑定的ip地址,能够是ipv4或ipv6的,默认为0.0.0.0。
设置其它节点和该节点交互的ip地址,若是不设置它会自动判断,值必须是个真实的ip地址。
这个参数是用来同时设置bind_host和publish_host上面两个参数。
设置节点间交互的tcp端口,默认是9300。
设置是否压缩tcp传输时的数据,默认为false,不压缩。
设置对外服务的http端口,默认为9200。
设置内容的最大容量,默认100mb
是否使用http协议对外提供服务,默认为true,开启。
网络配置
自动发现相关配置
The gateway snapshot interval (only applies to shared gateways).
分片异步刷新时间间隔
Set to an actual value (like 0-all) or false to disable it.
Set to true to have the index read only. false to allow writes and metadata changes.
Set to true to disable read operations against the index.
Set to true to disable write operations against the index.
Set to true to disable metadata operations against the index.
Lucene index term间隔,仅用于新建立的doc
Lucene reader term index divisor
When to flush based on operations.
When to flush based on translog (bytes) size.
When to flush based on a period of not flushing.
Disables flushing. Note, should be set for a short interval and then enabled.
The maximum size of filter cache (per segment in shard). Set to -1 to disable.
The expire after access time for filter cache. Set to -1 to disable.
merge policy
All the settings for the merge policy currently configured. A different merge policy can’t be set.
A node matching any rule will be allowed to host shards from the index.
A node matching any rule will NOT be allowed to host shards from the index.
Only nodes matching all rules will be allowed to host shards from the index.
Controls the total number of shards allowed to be allocated on a single node. Defaults to unbounded (-1).
When using local gateway a particular shard is recovered only if there can be allocated quorum shards in the cluster. It can be set to quorum (default), quorum-1 (or half), full and full-1. Number values are also supported, e.g. 1.
Disables temporarily the purge of expired docs.
默认索引合并因子
Gateway相关配置
当集群指望节点达不到的时候,集群就会处于block,没法正常索引和查询,说明集群中某个节点未能正常启动,这正是咱们指望的效果,block住,避免照成数据的不一致。
gateway的类型,默认为local即为本地文件系统,能够设置为本地文件系统,分布式文件系统,hadoop的HDFS,和amazon的s3服务器,其它文件系统的设置方法下次再详细说。
设置集群中N个节点启动时进行数据恢复,默认为1。
设置初始化数据恢复进程的超时时间,默认是5分钟。
设置这个集群中节点的数量,默认为2,一旦这N个节点启动,就会当即进行数据恢复。
初始化数据恢复时,并发恢复线程的个数,默认为4。
添加删除节点或负载均衡时并发恢复线程的个数,默认为4。
设置数据恢复时限制的带宽,如入100mb,默认为0,即无限制。
设置这个参数来限制从其它分片恢复数据时最大同时打开并发流的个数,默认为5。
设置这个参数来保证集群中的节点能够知道其它N个有master资格的节点。默认为1,对于大的集群来讲,能够设置大一点的值(2-4)。
设置集群中自动发现其它节点时ping链接超时时间,默认为3秒,对于比较差的网络环境能够高点的值来防止自动发现时出错。
设置是否打开多播发现节点,默认是true。
当禁用multcast广播的时候,能够手动设置集群的节点ip
设置集群中master节点的初始列表,能够经过这些节点来自动发现新加入集群的节点。
下面是一些查询时的慢日志参数设置
1.设置cache大小和过时时间。
例如设置:
//index中每一个segment中可包含的最大的entries数目
//过时时间为10分钟
2.改变cache类型。
默认类型为resident, 字面意思是常驻(居民), 一直增长,直到内存 耗尽。 改成soft就是当内存不足的时候,先clear掉 占用的,而后再往内存中放。设置为soft后,至关于设置成了相对的内存大小。resident的话,除非内存够大。 3.对数据进行处理。 文章中提到的是减少字段值长度,如将大写转成小写。 这点上,实际中可能将数据精炼。固然, 也能够把要作facet的字段作一个转化,用int型代替。 关于string转化int呢, 能够参考M大神的: https://github.com/medcl/elasticsearch-analysis-string2int