ElasticSearch分布式搜索配置文件詳解
Elasticsearch是一個(gè)開源的分布式實(shí)時(shí)搜索與分析引擎,支持云服務(wù)。它是基于 Apache Lucene搜索引擎的類庫創(chuàng)建的,提供了全文搜索能力、多語言支持、專門的查詢語言、支持地理位置服務(wù)、基于上下文的搜索建議、自動(dòng)完成以及搜索片段(snippet)的能力。Elasticsearch支持RESTful的API,可以使用JSON通過HTTP調(diào)用它的各種功能,包括搜索、分析與監(jiān)控。下面是講述了elasticsearch分布式搜索配置文件各類參數(shù)的具體含義。
elasticsearch的 config文件夾里面有兩個(gè)配置文件:elasticsearch.yml和logging.yml,***個(gè)是es的基本配置文件,第二個(gè)是日志配置文件,es也是使用log4j來記錄日志的,所以logging.yml里的設(shè)置按普通log4j配置文件來設(shè)置就行了。下面主要講解下 elasticsearch.yml這個(gè)文件中可配置的東西。
- cluster.name: elasticsearch
配置es的集群名稱,默認(rèn)是elasticsearch,es會(huì)自動(dòng)發(fā)現(xiàn)在同一網(wǎng)段下的es,如果在同一網(wǎng)段下有多個(gè)集群,就可以用這個(gè)屬性來區(qū)分不同的集群。
- node.name: "Franz Kafka"
節(jié)點(diǎn)名,默認(rèn)隨機(jī)指定一個(gè)name列表中名字,該列表在es的jar包中config文件夾里name.txt文件中,其中有很多作者添加的有趣名字。
- node.master: true
指定該節(jié)點(diǎn)是否有資格被選舉成為node,默認(rèn)是true,es是默認(rèn)集群中的***臺(tái)機(jī)器為master,如果這臺(tái)機(jī)掛了就會(huì)重新選舉master。
- node.data: true
指定該節(jié)點(diǎn)是否存儲(chǔ)索引數(shù)據(jù),默認(rèn)為true。
- index.number_of_shards: 5
設(shè)置默認(rèn)索引分片個(gè)數(shù),默認(rèn)為5片。
- index.number_of_replicas: 1
設(shè)置默認(rèn)索引副本個(gè)數(shù),默認(rèn)為1個(gè)副本。
- path.conf: /path/to/conf
設(shè)置配置文件的存儲(chǔ)路徑,默認(rèn)是es根目錄下的config文件夾。
- path.data: /path/to/data
設(shè)置索引數(shù)據(jù)的存儲(chǔ)路徑,默認(rèn)是es根目錄下的data文件夾,可以設(shè)置多個(gè)存儲(chǔ)路徑,用逗號(hào)隔開,例:
- path.data: /path/to/data1,/path/to/data2
- path.work: /path/to/work
設(shè)置臨時(shí)文件的存儲(chǔ)路徑,默認(rèn)是es根目錄下的work文件夾。
- path.logs: /path/to/logs
設(shè)置日志文件的存儲(chǔ)路徑,默認(rèn)是es根目錄下的logs文件夾
- path.plugins: /path/to/plugins
設(shè)置插件的存放路徑,默認(rèn)是es根目錄下的plugins文件夾
- bootstrap.mlockall: true
設(shè)置為true來鎖住內(nèi)存。因?yàn)楫?dāng)jvm開始swapping時(shí)es的效率會(huì)降低,所以要保證它不swap,可以把ES_MIN_MEM和 ES_MAX_MEM兩個(gè)環(huán)境變量設(shè)置成同一個(gè)值,并且保證機(jī)器有足夠的內(nèi)存分配給es。同時(shí)也要允許elasticsearch的進(jìn)程可以鎖住內(nèi)存,linux下可以通過`ulimit -l unlimited`命令。
- network.bind_host: 192.168.0.1
設(shè)置綁定的ip地址,可以是ipv4或ipv6的,默認(rèn)為0.0.0.0。
- network.publish_host: 192.168.0.1
設(shè)置其它節(jié)點(diǎn)和該節(jié)點(diǎn)交互的ip地址,如果不設(shè)置它會(huì)自動(dòng)判斷,值必須是個(gè)真實(shí)的ip地址。
- network.host: 192.168.0.1
這個(gè)參數(shù)是用來同時(shí)設(shè)置bind_host和publish_host上面兩個(gè)參數(shù)。
- transport.tcp.port: 9300
設(shè)置節(jié)點(diǎn)間交互的tcp端口,默認(rèn)是9300。
- transport.tcp.compress: true
設(shè)置是否壓縮tcp傳輸時(shí)的數(shù)據(jù),默認(rèn)為false,不壓縮。
- http.port: 9200
設(shè)置對(duì)外服務(wù)的http端口,默認(rèn)為9200。
- http.max_content_length: 100mb
設(shè)置內(nèi)容的***容量,默認(rèn)100mb
- http.enabled: false
是否使用http協(xié)議對(duì)外提供服務(wù),默認(rèn)為true,開啟。
- gateway.type: local
gateway的類型,默認(rèn)為local即為本地文件系統(tǒng),可以設(shè)置為本地文件系統(tǒng),分布式文件系統(tǒng),hadoop的HDFS,和amazon的s3服務(wù)器,其它文件系統(tǒng)的設(shè)置方法下次再詳細(xì)說。
- gateway.recover_after_nodes: 1
設(shè)置集群中N個(gè)節(jié)點(diǎn)啟動(dòng)時(shí)進(jìn)行數(shù)據(jù)恢復(fù),默認(rèn)為1。
- gateway.recover_after_time: 5m
設(shè)置初始化數(shù)據(jù)恢復(fù)進(jìn)程的超時(shí)時(shí)間,默認(rèn)是5分鐘。
- gateway.expected_nodes: 2
設(shè)置這個(gè)集群中節(jié)點(diǎn)的數(shù)量,默認(rèn)為2,一旦這N個(gè)節(jié)點(diǎn)啟動(dòng),就會(huì)立即進(jìn)行數(shù)據(jù)恢復(fù)。
- cluster.routing.allocation.node_initial_primaries_recoveries: 4
初始化數(shù)據(jù)恢復(fù)時(shí),并發(fā)恢復(fù)線程的個(gè)數(shù),默認(rèn)為4。
- cluster.routing.allocation.node_concurrent_recoveries: 2
添加刪除節(jié)點(diǎn)或負(fù)載均衡時(shí)并發(fā)恢復(fù)線程的個(gè)數(shù),默認(rèn)為4。
- indices.recovery.max_size_per_sec: 0
設(shè)置數(shù)據(jù)恢復(fù)時(shí)限制的帶寬,如入100mb,默認(rèn)為0,即無限制。
- indices.recovery.concurrent_streams: 5
設(shè)置這個(gè)參數(shù)來限制從其它分片恢復(fù)數(shù)據(jù)時(shí)***同時(shí)打開并發(fā)流的個(gè)數(shù),默認(rèn)為5。
- discovery.zen.minimum_master_nodes: 1
設(shè)置這個(gè)參數(shù)來保證集群中的節(jié)點(diǎn)可以知道其它N個(gè)有master資格的節(jié)點(diǎn)。默認(rèn)為1,對(duì)于大的集群來說,可以設(shè)置大一點(diǎn)的值(2-4)
- discovery.zen.ping.timeout: 3s
設(shè)置集群中自動(dòng)發(fā)現(xiàn)其它節(jié)點(diǎn)時(shí)ping連接超時(shí)時(shí)間,默認(rèn)為3秒,對(duì)于比較差的網(wǎng)絡(luò)環(huán)境可以高點(diǎn)的值來防止自動(dòng)發(fā)現(xiàn)時(shí)出錯(cuò)。
- discovery.zen.ping.multicast.enabled: false
設(shè)置是否打開多播發(fā)現(xiàn)節(jié)點(diǎn),默認(rèn)是true。
- discovery.zen.ping.unicast.hosts: ["host1", "host2:port", "host3[portX-portY]"]
設(shè)置集群中master節(jié)點(diǎn)的初始列表,可以通過這些節(jié)點(diǎn)來自動(dòng)發(fā)現(xiàn)新加入集群的節(jié)點(diǎn)。
下面是一些查詢時(shí)的慢日志參數(shù)設(shè)置,如下
- index.search.slowlog.level: TRACE
- index.search.slowlog.threshold.query.warn: 10s
- index.search.slowlog.threshold.query.info: 5s
- index.search.slowlog.threshold.query.debug: 2s
- index.search.slowlog.threshold.query.trace: 500ms
- index.search.slowlog.threshold.fetch.warn: 1s
- index.search.slowlog.threshold.fetch.info: 800ms
- index.search.slowlog.threshold.fetch.debug:500ms
- index.search.slowlog.threshold.fetch.trace: 200ms
原文鏈接:http://www.open-open.com/lib/view/open1397003561934.html