elasticsearch 配置文件

elasticsearch的config文件夹里面有两个配置文件:elasticsearch.yml和logging.yml,第一个是es的基本配置文件,第二个是日志配置文件,es也是使用log4j来记录日志的,所以logging.yml里的设置按普通log4j配置文件来设置就行了。下面主要讲解下elasticsearch.yml这个文件中可配置的东西。 

配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。 

Java代码  

  1. cluster.name: elasticsearch  

节点名,默认随机指定一个name列表中名字,该列表在es的jar包中config文件夹里name.txt文件中,其中有很多作者添加的有趣名字。 

Java代码  

  1. node.name: "Franz Kafka"  

指定该节点是否有资格被选举成为node,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master。 

Java代码  

  1. node.master: true  

指定该节点是否存储索引数据,默认为true。 

Java代码  

  1. node.data: true  

设置默认索引分片个数,默认为5片。 

Java代码  

  1. index.number_of_shards: 5  

设置默认索引副本个数,默认为1个副本。 

Java代码  

  1. index.number_of_replicas: 1  

设置配置文件的存储路径,默认是es根目录下的config文件夹。 

Java代码  

  1. path.conf: /path/to/conf  

设置索引数据的存储路径,默认是es根目录下的data文件夹 

Java代码  

  1. path.data: /path/to/data  

可以设置多个存储路径,用逗号隔开,例: 

Java代码  

  1. path.data: /path/to/data1,/path/to/data2  

设置临时文件的存储路径,默认是es根目录下的work文件夹。 

Java代码  

  1. path.work: /path/to/work  

设置日志文件的存储路径,默认是es根目录下的logs文件夹 

Java代码  

  1. path.logs: /path/to/logs  

设置插件的存放路径,默认是es根目录下的plugins文件夹 

Java代码  

  1. path.plugins: /path/to/plugins  

强制所有内存锁定,不要搞什么swap的来影响性能 
设置为true来锁住内存。因为当jvm开始swapping时es的效率会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过`ulimit
-l unlimited`命令。 

Java代码  

  1. bootstrap.mlockall: true  

设置绑定的ip地址,可以是ipv4或ipv6的,默认为0.0.0.0。 

Java代码  

  1. network.bind_host: 192.168.0.1  

设置其它节点和该节点交互的ip地址,如果不设置它会自动判断,值必须是个真实的ip地址。 

Java代码  

  1. network.publish_host: 192.168.0.1  

这个参数是用来同时设置bind_host和publish_host上面两个参数。 

Java代码  

  1. network.host: 192.168.0.1  

设置节点间交互的tcp端口,默认是9300。 

Java代码  

  1. transport.tcp.port: 9300  

设置是否压缩tcp传输时的数据,默认为false,不压缩。 

Java代码  

  1. transport.tcp.compress: true  

设置对外服务的http端口,默认为9200。 

Java代码  

  1. http.port: 9200  

设置内容的最大容量,默认100mb 

Java代码  

  1. http.max_content_length: 100mb  

是否使用http协议对外提供服务,默认为true,开启。 

Java代码  

  1. http.enabled: false  

网络配置 

Java代码  

  1. #network.tcp.keep_alive : true  
  2. #network.tcp.send_buffer_size : 8192  
  3. #network.tcp.receive_buffer_size : 8192  

自动发现相关配置 

Java代码  

  1. #discovery.zen.fd.connect_on_network_disconnect : true  
  2. #discovery.zen.initial_ping_timeout : 10s  
  3. #discovery.zen.fd.ping_interval : 2s  
  4. #discovery.zen.fd.ping_retries  : 10  

The gateway snapshot interval (only applies to shared gateways). 

Java代码  

  1. #index.gateway.snapshot_interval : 1s  

分片异步刷新时间间隔 

Java代码  

  1. #index.refresh_interval : -1  

Set to an actual value (like 0-all) or false to disable it. 

Java代码  

  1. index.auto_expand_replicas  

Set to true to have the index read only. false to allow writes and metadata changes. 

Java代码  

  1. index.blocks.read_only  

Set to true to disable read operations against the index. 

Java代码  

  1. index.blocks.read  

Set to true to disable write operations against the index. 

Java代码  

  1. index.blocks.write  

Set to true to disable metadata operations against the index. 

Java代码  

  1. index.blocks.metadata  

Lucene index term间隔,仅用于新创建的doc 

Java代码  

  1. index.term_index_interval  

Lucene reader term index divisor 

Java代码  

  1. index.term_index_divisor  

When to flush based on operations. 

Java代码  

  1. index.translog.flush_threshold_ops  

When to flush based on translog (bytes) size. 

Java代码  

  1. index.translog.flush_threshold_size  

When to flush based on a period of not flushing. 

Java代码  

  1. index.translog.flush_threshold_period  

Disables flushing. Note, should be set for a short interval and then enabled. 

Java代码  

  1. index.translog.disable_flush  

The maximum size of filter cache (per segment in shard). Set to -1 to disable. 

Java代码  

  1. index.cache.filter.max_size  

The expire after access time for filter cache. Set to -1 to disable. 

Java代码  

  1. index.cache.filter.expire  

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. 

Java代码  

  1. index.routing.allocation.include.*  

A node matching any rule will NOT be allowed to host shards from the index.

Java代码  

  1. index.routing.allocation.exclude.*  

Only nodes matching all rules will be allowed to host shards from the index.

Java代码  

  1. index.routing.allocation.require.*  

Controls the total number of shards allowed to be allocated on a single node. Defaults to unbounded (-1). 

Java代码  

  1. index.routing.allocation.total_shards_per_node  

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. 

Java代码  

  1. index.recovery.initial_shards  

Disables temporarily the purge of expired docs. 

Java代码  

  1. index.ttl.disable_purge  

默认索引合并因子 

Java代码  

  1. #index.merge.policy.merge_factor : 100  
  2. #index.merge.policy.min_merge_docs : 1000  
  3. #index.merge.policy.use_compound_file : true  
  4. #indices.memory.index_buffer_size : 5%  

Gateway相关配置 
当集群期望节点达不到的时候,集群就会处于block,无法正常索引和查询,说明集群中某个节点未能正常启动,这正是我们期望的效果,block住,避免照成数据的不一致。 
gateway的类型,默认为local即为本地文件系统,可以设置为本地文件系统,分布式文件系统,hadoop的HDFS,和amazon的s3服务器,其它文件系统的设置方法下次再详细说。 

Java代码  

  1. gateway.type: local  

设置集群中N个节点启动时进行数据恢复,默认为1。 

Java代码  

  1. gateway.recover_after_nodes: 1  

设置初始化数据恢复进程的超时时间,默认是5分钟。 

Java代码  

  1. gateway.recover_after_time: 5m  

设置这个集群中节点的数量,默认为2,一旦这N个节点启动,就会立即进行数据恢复。 

Java代码  

  1. gateway.expected_nodes: 2  

初始化数据恢复时,并发恢复线程的个数,默认为4。 

Java代码  

  1. cluster.routing.allocation.node_initial_primaries_recoveries: 4  

添加删除节点或负载均衡时并发恢复线程的个数,默认为4。 

Java代码  

  1. cluster.routing.allocation.node_concurrent_recoveries: 2  

设置数据恢复时限制的带宽,如入100mb,默认为0,即无限制。 

Java代码  

  1. indices.recovery.max_size_per_sec: 0  

设置这个参数来限制从其它分片恢复数据时最大同时打开并发流的个数,默认为5。 

Java代码  

  1. indices.recovery.concurrent_streams: 5  

设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)。 

Java代码  

  1. discovery.zen.minimum_master_nodes: 1  

设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。 

Java代码  

  1. discovery.zen.ping.timeout: 3s  

Java代码  

  1. discovery.zen.ping.multicast.enabled: false  

设置是否打开多播发现节点,默认是true。 
当禁用multcast广播的时候,可以手动设置集群的节点ip 

设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。 

Java代码  

  1. discovery.zen.ping.unicast.hosts: ["host1", "host2:port", "host3[portX-portY]"]  

下面是一些查询时的慢日志参数设置 

Java代码  

  1. index.search.slowlog.level: TRACE  
  2. index.search.slowlog.threshold.query.warn: 10s  
  3. index.search.slowlog.threshold.query.info: 5s  
  4. index.search.slowlog.threshold.query.debug: 2s  
  5. index.search.slowlog.threshold.query.trace: 500ms  
  6.   
  7. index.search.slowlog.threshold.fetch.warn: 1s  
  8. index.search.slowlog.threshold.fetch.info: 800ms  
  9. index.search.slowlog.threshold.fetch.debug:500ms  
  10. index.search.slowlog.threshold.fetch.trace: 200ms  

1.设置cache大小和过期时间。 
  

Java代码  

  1. index.cache.field.max_size  
  2.    index.cache.field.expire  

例如设置: 
  //index中每个segment中可包含的最大的entries数目 
 

Java代码  

  1. index.cache.field.max_size: 50000   

  //过期时间为10分钟 
 

Java代码  

  1. index.cache.field.expire: 10m   

2.改变cache类型。 

Java代码  

  1. index.cache.field.type: soft  

默认类型为resident, 字面意思是常驻(居民), 一直增加,直到内存 耗尽。 改为soft就是当内存不足的时候,先clear掉 占用的,然后再往内存中放。设置为soft后,相当于设置成了相对的内存大小。resident的话,除非内存够大。 

3.对数据进行处理。 
文章中提到的是减小字段值长度,如将大写转成小写。 
这点上,实际中可能将数据精炼。当然, 也可以把要做facet的字段做一个转化,用int型代替。 
关于string转化int呢, 可以参考M大神的: https://github.com/medcl/elasticsearch-analysis-string2int

时间: 2024-09-19 12:55:14

elasticsearch 配置文件的相关文章

elasticsearch 2.3.4 java API 连接,ik分词器,设置集群节点,创建index,mapping的几种方式

1.默认集群连接 Client client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300)); 2.自定义集群连接 Settings settings = Settings.settingsBuilder().put("cluster.name", &qu

Nginx+Logstash+Elasticsearch+Kibana搭建网站日志分析

前言   流程,nignx格式化日志成json,通过logstash直接采集到elasticsearch,然后通过kibana gui界面展示分析 要点nignx日志成json格式,避免nignx默认日志是空格,需要正则匹配,导致logstash占过多cpuelasticsearch机配置防火墙,只让指定的logstash机访问kibana只监听本地127.0.0.1使用nignx方向代理,nginx中配置Http Basic Auth账号密码登陆 比较粗略的笔记,备忘安装java um ins

《深入理解ElasticSearch》——3.4 准实时、提交、更新及事务日志

3.4 准实时.提交.更新及事务日志 一个理想的搜索解决方案中,新索引的数据应该能立即搜索到.ElasticSearch给人的第一印象仿佛就是如此工作的,即使是在多服务器环境下,然而事实并非如此(至少不是任何场景都能保证新索引的数据能被实时检索到),原因我们后面会讲解.接下来的案例中,我们将使用下面的命令将一篇文档索引到新创建的索引中: https://yqfile.alicdn.com/c54c8d453ea72d83a223728253c1fd6162c44e66.png" > 现在,

Ubuntu 16.04下部署Graylog日志服务器

Graylog 是一个开源的日志管理系统,集中式收集.索引.分析其它服务器发来的日志.它是由 Java 语言编写的,能够接收 TCP.UDP.AMQP 协议发送的日志信息,并且使用 Mongodb 做为后台数据库.它还有一个使用 Ruby 编写的 Web 管理接口,可以轻松管理 Graylog 和查询日志. Graylog 可以收集监控多种不同应用的日志.本文只是会为了示范说明,会把用到的组件全部安装到一个单独的服务器上.对于大型.生产系统你可以把组件分开安装在不同的服务器上,这样可以提高效率.

linux中搭建ElasticSearch-2.x Logstash-2.x Kibana-4.5.x Kafka为消息中心的ELK日志平台

介绍 ELK是业界标准的日志采集,存储索引,展示分析系统解决方案 logstash提供了灵活多样的插件支持不同的input/output 主流使用redis/kafka作为日志/消息的中间环节 如果已有kafka的环境了,使用kafka比使用redis更佳 以下是一个最简化的配置做个笔记,elastic官网提供了非常丰富的文档 不要用搜索引擎去搜索,没多少结果的,请直接看官网文档 采用的ELK/kafka版本 elasticsearch-2.x logstash-2.3 kibana-4.5.1

Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询

摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 预见未来最好的方式就是亲手创造未来 – <史蒂夫·乔布斯传> 』 运行环境:JDK 7 或 8,Maven 3.0+技术栈:SpringBoot 1.5+,ElasticSearch 2.3.2 本文提纲 一.ES 的使用场景 二.运行 springboot-elasticsearch 工程 三.springboot-elasticsearch 工程代码详解 一.ES 的使用场景 简

表格存储结合Elasticsearch进行搜索的场景分析和实践

表格存储结合Elasticsearch进行搜索的场景分析和实践 表格存储(TableStore)是什么 TableStore是一个构建在阿里云飞天分布式系统上的Nosql数据库服务,熟悉阿里云的同学肯定听说过飞天5K,飞天是一个可以管理5000台机器的分布式系统,TableStore作为构建在其上的一个Nosql数据库,可以承载海量(单表几百TB)的数据存储,同时数据有三份拷贝,数据安全性有极高的保证. TableStore的数据是以行进行组织的,每行包含多个主键列和多个属性列,主键列的列名和类

安全日志收集与分析——抢先体验阿里云 ElasticSearch

10月13日,云栖大会上阿里云与Elastic公司联合发布阿里云Elasticsearch产品.根据官方介绍,阿里云提供基于开源Elasticsearch及商业版X-Pack插件,致力于数据分析.数据搜索等场景服务.在开源Elasticsearch基础上提供企业级权限管控.安全监控告警.自动报表生成等功能. Elasticsearch(ES)是中小企业安全日志分析的必备工具.团队在获得试用资格后,随即开展了产品试用工作,抢先体验这款"新产品". 申请开通服务 访问网址:https://

ElasticSearch的基本用法与集群搭建

一.简介 ElasticSearch和Solr都是基于Lucene的搜索引擎,不过ElasticSearch天生支持分布式,而Solr是4.0版本后的SolrCloud才是分布式版本,Solr的分布式支持需要ZooKeeper的支持. 这里有一个详细的ElasticSearch和Solr的对比:http://solr-vs-elasticsearch.com/ 二.基本用法 Elasticsearch集群可以包含多个索引(indices),每一个索引可以包含多个类型(types),每一个类型包含