springboot配置 
       application.xml配置



# Logstath配置
logstash:
   destination: 10.168.31.220:9601

           logback-spring.xml配置
 
    <springProperty scope="context" name="logcenter" source="logstash.destination" />
    <springProperty scope="context" name="applicationName" source="spring.application.name" defaultValue="localhost"/>
    
    <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>${logcenter}</destination>
         <encoder charset="UTF-8"
            class
="net.logstash.logback.encoder.LogstashEncoder" >
             <customFields>{"appname":"${applicationName}"}</customFields>
        </encoder>
    </appender>
    
logstash配置 
input {
       tcp {  
        host => "0.0.0.0"  
        port => 9601  
    #模式選擇為server  
        mode => "server"  
        tags => ["tags"]  

    ##格式json  
        codec => json_lines         
    }  
     file {
        type => "log"
        path => "/home/es/logs/*.log"
        start_position => "beginning"
    }
}
output {
  stdout {
   codec => rubydebug { }
  }
  elasticsearch {
    hosts => "10.168.31.223"
    index => "log-%{+YYYY.MM.dd}"
    或者根據(jù)變量
    index => "logstash-%{[fields][appname]}-%{+YYYY.MM.dd}"
  }
}

啟動
./logstash -f ../config/logstash.conf

kibana配置
#配置es集群url
elasticsearch.url: "http://192.168.252.129:9200"


es安裝

# 安裝部署并運行 Elasticsearch 2.3.0
## centos 7 安裝jdk8
1. 卸載
> 查看已經(jīng)安裝的jdk
```
# rpm -qa|grep jdk
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
```
> 卸載命令
```
# yum -y remove java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
# yum -y remove java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
# yum -y remove java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
# yum -y remove java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
```
> 卸載完成之后Java命令不被識別
```
# java -version
bash: java: command not found...
```
2. 安裝
> 官網(wǎng)下載jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html  
解壓到安裝目錄
```
# tar -zxvf jdk-8u101-linux-x64.tar.gz -C /usr/local/java/
```
>安裝完畢之后在/etc/profile文件末尾添加  
```
# vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_101
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
```
> 使/etc/profile生效
```
# source /etc/profile
```
> 檢測安裝是否成功
```
# java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
```
## centos 7.x 安裝 Elasticsearch 
1. 下載elasticsearch-2.3.0.rpm 安裝包: 
```
# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.0/elasticsearch-2.3.0.rpm
```
2. 直接解壓安裝
```
# rpm -ivh elasticsearch-2.3.0.rpm
# systemctl daemon-reloa
```
3. 啟動并查看安裝狀態(tài)
```
# systemctl start elasticsearch
# systemctl status elasticsearch
```
4. 本地查看版本信息
```
# curl -XGET "127.0.0.1:9200"
{
  "name" : "Centennial",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.0",
    "build_hash" : "8371be8d5fe5df7fb9c0516c474d77b9feddd888",
    "build_timestamp" : "2016-03-29T07:54:48Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}
```
5. 查找elasticsearch 安裝路徑與配置路徑,并且配置
```
# whereis elasticsearch
elasticsearch: /etc/elasticsearch /usr/share/elasticsearch
```
> 修改配置文件
```
vi /etc/elasticsearch/elasticsearch.yml
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.0.120
#
# Set a custom port for HTTP:
#
http.port: 9200
```
> 保存退出后重啟elasticsearch  
外部訪問:http://192.168.0.120:9200/
6. 安裝 elasticsearch-head  
> ElasticSearch-Head 是一個與Elastic集群(Cluster)相交互的Web前臺。
- 查找elasticsearch安裝的bin目錄
```
# rpm -ql elasticsearch
/etc/elasticsearch
/etc/elasticsearch/elasticsearch.yml
/etc/elasticsearch/logging.yml
/etc/elasticsearch/scripts
/etc/init.d/elasticsearch
/etc/sysconfig/elasticsearch
/usr/lib/sysctl.d
/usr/lib/sysctl.d/elasticsearch.conf
/usr/lib/systemd/system/elasticsearch.service
/usr/lib/tmpfiles.d
/usr/lib/tmpfiles.d/elasticsearch.conf
/usr/share/elasticsearch/LICENSE.txt
/usr/share/elasticsearch/NOTICE.txt
/usr/share/elasticsearch/README.textile
/usr/share/elasticsearch/bin
...
```
- 安裝
```
 /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
```
- 訪問
> http://192.168.0.120:9200/_plugin/head/
7. 安裝 ElasticSearch-Kopf
> Kopf是一個ElasticSearch的管理工具,它也提供了對ES集群操作的API。
```
/usr/share/elasticsearch/plugin install lmenezes/elasticsearch-kopf/v2.1.1
```  
- 訪問
 > http://192.168.0.120:9200/_plugin/kopf  
 
---
# Elasticsearch壓縮包安裝
1. 訪問:https://www.elastic.co/downloads/past-releases/elasticsearch-2-3-1
下載elasticsearch-2.3.1.zip 
復制elasticsearch-2.3.1.zip到centos7指定目錄  
> 例如 :
```
[root@localhost local]# pwd elasticsearch-2.3.1.zip
/usr/local
```
2. 解壓elasticsearch-2.3.1.zip 
```
[root@localhost local]# unzip elasticsearch-2.3.1.zip
```
3. 修改文件夾名稱
```
[root@localhost local]# mv elasticsearch-2.3.1 elasticsearch
```
4. 創(chuàng)建elsearch用戶組及elsearch用戶
>這是出于系統(tǒng)安全考慮設置的條件。由于ElasticSearch可以接收用戶輸入的腳本并且執(zhí)行,為了系統(tǒng)安全考慮, 
建議創(chuàng)建一個單獨的用戶用來運行ElasticSearch
```
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
```
5. 更改elasticsearch文件夾及內(nèi)部文件的所屬用戶及組為elsearch:elsearch
```
cd /opt
chown -R elsearch:elsearch  elasticsearch
```
6. 切換到elsearch用戶再啟動
```
su elsearch 
cd elasticsearch/bin
./elasticsearch 
```
7. 后臺運行
```
./elasticsearch -d
```
8. 增加中文分詞
- 復制analysis-ik到 /usr/local/elasticsearch/plugins目錄下
- 修改配置文件
```
cat /usr/local/elasticsearch/config/elasticsearch.yml 
----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# bootstrap.mlockall: true
#
# Make sure that the `ES_HEAP_SIZE` environment variable 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.0.129
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- 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 nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true
 index.analysis.analyzer.default.type: ik
```
9. 重啟服務
```
 ./bin/elasticsearch
```
10. 安裝ElasticSearch-head
```
bin/plugin install mobz/elasticsearch-head
```
- 訪問
> http://192.168.0.120:9200/_plugin/head/
---
 
#  windows10 安裝 Elasticsearch
## 安裝jdk并且設置環(huán)境變量
> 詳情參考:https://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html
## 安裝 Elasticsearch
> 訪問:https://www.elastic.co/downloads/past-releases/elasticsearch-2-3-0 下載ZIP包  
解壓到目標目錄  
進入到elasticsearch目錄
例如,本機的安裝目錄為D:\worksoft\elasticsearch-2.3.0
用命令行進入到D:\worksoft\elasticsearch-2.3.0下邊
- 安裝服務
```
> D:\worksoft\elasticsearch-2.3.0\bin>service.bat install
```
- 刪除服務
```
D:\worksoft\elasticsearch-2.3.0\bin>service.bat remove
```
- 啟動服務
```
D:\worksoft\elasticsearch-2.3.0\bin>service.bat start
```
- 停止服務
```
D:\worksoft\elasticsearch-2.3.0\bin>service.bat stop
```
- 安裝 elasticsearch-head 
> 進入到安裝目錄下的bin目錄下
```
D:\worksoft\elasticsearch-2.3.0\bin>plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading ...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed head into D:\worksoft\elasticsearch-2.3.0\plugins\head
```
>訪問:http://localhost:9200/_plugin/head/
- 安裝 ElasticSearch-Kopf
> 進入到安裝目錄下的bin目錄下
```
D:\worksoft\elasticsearch-2.3.0\bin>plugin install lmenezes/elasticsearch-kopf/v2.1.1
-> Installing lmenezes/elasticsearch-kopf/v2.1.1...
Trying https://download.elastic.co/lmenezes/elasticsearch-kopf/elasticsearch-kopf-v2.1.1.zip ...
Trying https://search.maven.org/remotecontent?filepath=lmenezes/elasticsearch-kopf/v2.1.1/elasticsearch-kopf-v2.1.1.zip ...
Trying https://oss.sonatype.org/service/local/repositories/releases/content/lmenezes/elasticsearch-kopf/v2.1.1/elasticsearch-kopf-v2.1.1.zip ...
Trying https://github.com/lmenezes/elasticsearch-kopf/archive/v2.1.1.zip ...
Downloading ................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
Verifying https://github.com/lmenezes/elasticsearch-kopf/archive/v2.1.1.zip checksums if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed kopf into D:\worksoft\elasticsearch-2.3.0\plugins\kopf
```
>訪問:http://localhost:9200/_plugin/kopf/
# Elasticsearch 配置文件詳解
> centos 7 的配置文件目錄 /etc/elasticsearch ;windows下的配置文件目錄 elasticsearch-2.3.0\config
##  配置文件elasticsearch.yml
## 基本概念
### 接近實時(NRT)
> Elasticsearch 是一個接近實時的搜索平臺。這意味著,從索引一個文檔直到這個文檔能夠被搜索到有一個很小的延遲(通常是 1 秒)。
### 集群(cluster)
> 代表一個集群,集群中有多個節(jié)點(node),其中有一個為主節(jié)點,這個主節(jié)點是可以通過選舉產(chǎn)生的,主從節(jié)點是對于集群內(nèi)部來說的。es的一個概念就是去中心化,字面上理解就是無中心節(jié)點,這是對于集群外部來說的,因為從外部來看es集群,在邏輯上是個整體,你與任何一個節(jié)點的通信和與整個es集群通信是等價的。
### 索引(index)
>ElasticSearch將它的數(shù)據(jù)存儲在一個或多個索引(index)中。用SQL領域的術語來類比,索引就像數(shù)據(jù)庫,可以向索引寫入文檔或者從索引中讀取文檔,并通過ElasticSearch內(nèi)部使用Lucene將數(shù)據(jù)寫入索引或從索引中檢索數(shù)據(jù)。
### 文檔(document)
>文檔(document)是ElasticSearch中的主要實體。對所有使用ElasticSearch的案例來說,他們最終都可以歸結為對文檔的搜索。文檔由字段構成。
### 映射(mapping)
>所有文檔寫進索引之前都會先進行分析,如何將輸入的文本分割為詞條、哪些詞條又會被過濾,這種行為叫做映射(mapping)。一般由用戶自己定義規(guī)則。
### 類型(type)
>每個文檔都有與之對應的類型(type)定義。這允許用戶在一個索引中存儲多種文檔類型,并為不同文檔提供類型提供不同的映射。
### 分片(shards)
>代表索引分片,es可以把一個完整的索引分成多個分片,這樣的好處是可以把一個大的索引拆分成多個,分布到不同的節(jié)點上。構成分布式搜索。分片的數(shù)量只能在索引創(chuàng)建前指定,并且索引創(chuàng)建后不能更改。5.X默認不能通過配置文件定義分片
### 副本(replicas)
>代表索引副本,es可以設置多個索引的副本,副本的作用一是提高系統(tǒng)的容錯性,當個某個節(jié)點某個分片損壞或丟失時可以從副本中恢復。二是提高es的查詢效率,es會自動對搜索請求進行負載均衡。
### 數(shù)據(jù)恢復(recovery)
>代表數(shù)據(jù)恢復或叫數(shù)據(jù)重新分布,es在有節(jié)點加入或退出時會根據(jù)機器的負載對索引分片進行重新分配,掛掉的節(jié)點重新啟動時也會進行數(shù)據(jù)恢復。
GET /_cat/health?v   #可以看到集群狀態(tài)
### 數(shù)據(jù)源(River)
>代表es的一個數(shù)據(jù)源,也是其它存儲方式(如:數(shù)據(jù)庫)同步數(shù)據(jù)到es的一個方法。它是以插件方式存在的一個es服務,通過讀取river中的數(shù)據(jù)并把它索引到es中,官方的river有couchDB的,RabbitMQ的,Twitter的,Wikipedia的,river這個功能將會在后面的文件中重點說到。
### 網(wǎng)關(gateway)
>代表es索引的持久化存儲方式,es默認是先把索引存放到內(nèi)存中,當內(nèi)存滿了時再持久化到硬盤。當這個es集群關閉再重新啟動時就會從gateway中讀取索引數(shù)據(jù)。es支持多種類型的gateway,有本地文件系統(tǒng)(默認),分布式文件系統(tǒng),Hadoop的HDFS和amazon的s3云存儲服務。
### 自動發(fā)現(xiàn)(discovery.zen)
>代表es的自動發(fā)現(xiàn)節(jié)點機制,es是一個基于p2p的系統(tǒng),它先通過廣播尋找存在的節(jié)點,再通過多播協(xié)議來進行節(jié)點之間的通信,同時也支持點對點的交互。
5.X關閉廣播,需要自定義
### 通信(Transport)
>代表es內(nèi)部節(jié)點或集群與客戶端的交互方式,默認內(nèi)部是使用tcp協(xié)議進行交互,同時它支持http協(xié)議(json格式)、thrift、servlet、memcached、zeroMQ等的傳輸協(xié)議(通過插件方式集成)。
節(jié)點間通信端口默認:9300-9400
分片和復制(shards and replicas)
>  一個索引可以存儲超出單個結點硬件限制的大量數(shù)據(jù)。比如,一個具有10億文檔的索引占據(jù)1TB的磁盤空間,而任一節(jié)點可能沒有這樣大的磁盤空間來存儲或者單個節(jié)點處理搜索請求,響應會太慢。
>為了解決這個問題,Elasticsearch提供了將索引劃分成多片的能力,這些片叫做分片。當你創(chuàng)建一個索引的時候,你可以指定你想要的分片的數(shù)量。每個分片本身也是一個功能完善并且獨立的“索引”,這個“索引” 可以被放置到集群中的任何節(jié)點上。
>分片之所以重要,主要有兩方面的原因:
允許你水平分割/擴展你的內(nèi)容容量
允許你在分片(位于多個節(jié)點上)之上進行分布式的、并行的操作,進而提高性能/吞吐量 
至于一個分片怎樣分布,它的文檔怎樣聚合回搜索請求,是完全由Elasticsearch管理的,對于作為用戶的你來說,這些都是透明的。
在一個網(wǎng)絡/云的環(huán)境里,失敗隨時都可能發(fā)生。在某個分片/節(jié)點因為某些原因處于離線狀態(tài)或者消失的情況下,故障轉移機制是非常有用且強烈推薦的。為此, Elasticsearch允許你創(chuàng)建分片的一份或多份拷貝,這些拷貝叫做復制分片,或者直接叫復制。
復制之所以重要,有兩個主要原因:
在分片/節(jié)點失敗的情況下,復制提供了高可用性。復制分片不與原/主要分片置于同一節(jié)點上是非常重要的。因為搜索可以在所有的復制上并行運行,復制可以擴展你的搜索量/吞吐量
總之,每個索引可以被分成多個分片。一個索引也可以被復制0次(即沒有復制) 或多次。一旦復制了,每個索引就有了主分片(作為復制源的分片)和復制分片(主分片的拷貝)。
分片和復制的數(shù)量可以在索引創(chuàng)建的時候指定。在索引創(chuàng)建之后,你可以在任何時候動態(tài)地改變復制的數(shù)量,但是你不能再改變分片的數(shù)量。
5.X默認5:1   5個主分片,1個復制分片
默認情況下,Elasticsearch中的每個索引分配5個主分片和1個復制。這意味著,如果你的集群中至少有兩個節(jié)點,你的索引將會有5個主分片和另外5個復制分片(1個完全拷貝),這樣每個索引總共就有10個分片。
## Elasticsearch . yml 詳解
```
##################### Elasticsearch Configuration Example ##################### 
#
# 只是挑些重要的配置選項進行注釋,其實自帶的已經(jīng)有非常細致的英文注釋了!
# https://www.elastic.co/guide/en/elasticsearch/reference/current/modules.html
#
################################### Cluster ################################### 
# 代表一個集群,集群中有多個節(jié)點,其中有一個為主節(jié)點,這個主節(jié)點是可以通過選舉產(chǎn)生的,主從節(jié)點是對于集群內(nèi)部來說的. 
# es的一個概念就是去中心化,字面上理解就是無中心節(jié)點,這是對于集群外部來說的,因為從外部來看es集群,在邏輯上是個整體,你與任何一個節(jié)點的通信和與整個es集群通信是等價的。 
# cluster.name可以確定你的集群名稱,當你的elasticsearch集群在同一個網(wǎng)段中elasticsearch會自動的找到具有相同cluster.name的elasticsearch服務. 
# 所以當同一個網(wǎng)段具有多個elasticsearch集群時cluster.name就成為同一個集群的標識. 
# cluster.name: elasticsearch 
#################################### Node ##################################### 
# https://www.elastic.co/guide/en/elasticsearch/reference/5.1/modules-node.html#master-node
# 節(jié)點名稱同理,可自動生成也可手動配置. 
# node.name: node-1
# 允許一個節(jié)點是否可以成為一個master節(jié)點,es是默認集群中的第一臺機器為master,如果這臺機器停止就會重新選舉master. 
# node.master: true 
# 允許該節(jié)點存儲數(shù)據(jù)(默認開啟) 
# node.data: true 
# 配置文件中給出了三種配置高性能集群拓撲結構的模式,如下: 
# 1. 如果你想讓節(jié)點從不選舉為主節(jié)點,只用來存儲數(shù)據(jù),可作為負載器 
# node.master: false 
# node.data: true 
# node.ingest: true  #默認true
# 2. 如果想讓節(jié)點成為主節(jié)點,且不存儲任何數(shù)據(jù),并保有空閑資源,可作為協(xié)調(diào)器 
# node.master: true 
# node.data: false
# node.ingest: true
# 3. 如果想讓節(jié)點既不稱為主節(jié)點,又不成為數(shù)據(jù)節(jié)點,那么可將他作為搜索器,從節(jié)點中獲取數(shù)據(jù),生成搜索結果等 
# node.master: false 
# node.data: false 
# node.ingest: true
#
# 4. 僅作為協(xié)調(diào)器 
# node.master: false 
# node.data: false
# node.ingest: false
# 監(jiān)控集群狀態(tài)有一下插件和API可以使用: 
# Use the Cluster Health API [http://localhost:9200/_cluster/health], the 
# Node Info API [http://localhost:9200/_nodes] or GUI tools # such as <http://www.elasticsearch.org/overview/marvel/>, 
# A node can have generic attributes associated with it, which can later be used 
# for customized shard allocation filtering, or allocation awareness. An attribute 
# is a simple key value pair, similar to node.key: value, here is an example: 
# 每個節(jié)點都可以定義一些與之關聯(lián)的通用屬性,用于后期集群進行碎片分配時的過濾
# node.rack: rack314 
# 默認情況下,多個節(jié)點可以在同一個安裝路徑啟動,如果你想讓你的es只啟動一個節(jié)點,可以進行如下設置
# node.max_local_storage_nodes: 1 
#################################### Index #################################### 
# 設置索引的分片數(shù),默認為5 
#index.number_of_shards: 5 
# 設置索引的副本數(shù),默認為1: 
#index.number_of_replicas: 1 
# 配置文件中提到的最佳實踐是,如果服務器夠多,可以將分片提高,盡量將數(shù)據(jù)平均分布到大集群中去
# 同時,如果增加副本數(shù)量可以有效的提高搜索性能 
# 需要注意的是,"number_of_shards" 是索引創(chuàng)建后一次生成的,后續(xù)不可更改設置 
# "number_of_replicas" 是可以通過API去實時修改設置的 
#################################### Paths #################################### 
# 配置文件存儲位置 
# path.conf: /path/to/conf 
# 數(shù)據(jù)存儲位置(單個目錄設置) 
# path.data: /path/to/data 
# 多個數(shù)據(jù)存儲位置,有利于性能提升 
# path.data: /path/to/data1,/path/to/data2 
# 臨時文件的路徑 
# path.work: /path/to/work 
# 日志文件的路徑 
# path.logs: /path/to/logs 
# 插件安裝路徑 
# path.plugins: /path/to/plugins 
#################################### Plugin ################################### 
# 設置插件作為啟動條件,如果一下插件沒有安裝,則該節(jié)點服務不會啟動 
# plugin.mandatory: mapper-attachments,lang-groovy 
################################### Memory #################################### 
# 當JVM開始寫入交換空間時(swapping)ElasticSearch性能會低下,你應該保證它不會寫入交換空間 
# 設置這個屬性為true來鎖定內(nèi)存,同時也要允許elasticsearch的進程可以鎖住內(nèi)存,linux下可以通過 `ulimit -l unlimited` 命令 
# bootstrap.mlockall: true 
# 確保 ES_MIN_MEM 和 ES_MAX_MEM 環(huán)境變量設置為相同的值,以及機器有足夠的內(nèi)存分配給Elasticsearch 
# 注意:內(nèi)存也不是越大越好,一般64位機器,最大分配內(nèi)存別才超過32G 
############################## Network And HTTP ############################### 
# 設置綁定的ip地址,可以是ipv4或ipv6的,默認為0.0.0.0 
# network.bind_host: 192.168.0.1   #只有本機可以訪問http接口
# 設置其它節(jié)點和該節(jié)點交互的ip地址,如果不設置它會自動設置,值必須是個真實的ip地址 
# network.publish_host: 192.168.0.1 
# 同時設置bind_host和publish_host上面兩個參數(shù) 
# network.host: 192.168.0.1    #綁定監(jiān)聽IP
# 設置節(jié)點間交互的tcp端口,默認是9300 
# transport.tcp.port: 9300 
# 設置是否壓縮tcp傳輸時的數(shù)據(jù),默認為false,不壓縮
# transport.tcp.compress: true 
# 設置對外服務的http端口,默認為9200 
# http.port: 9200 
# 設置請求內(nèi)容的最大容量,默認100mb 
# http.max_content_length: 100mb 
# 使用http協(xié)議對外提供服務,默認為true,開啟 
# http.enabled: false 
###################### 使用head等插件監(jiān)控集群信息,需要打開以下配置項 ###########
# http.cors.enabled: true
# http.cors.allow-origin: "*"
# http.cors.allow-credentials: true
################################### Gateway ################################### 
# gateway的類型,默認為local即為本地文件系統(tǒng),可以設置為本地文件系統(tǒng) 
# gateway.type: local 
# 下面的配置控制怎樣以及何時啟動一整個集群重啟的初始化恢復過程 
# (當使用shard gateway時,是為了盡可能的重用local data(本地數(shù)據(jù))) 
# 一個集群中的N個節(jié)點啟動后,才允許進行恢復處理 
# gateway.recover_after_nodes: 1 
# 設置初始化恢復過程的超時時間,超時時間從上一個配置中配置的N個節(jié)點啟動后算起 
# gateway.recover_after_time: 5m 
# 設置這個集群中期望有多少個節(jié)點.一旦這N個節(jié)點啟動(并且recover_after_nodes也符合), 
# 立即開始恢復過程(不等待recover_after_time超時) 
# gateway.expected_nodes: 2
 ############################# Recovery Throttling ############################# 
# 下面這些配置允許在初始化恢復,副本分配,再平衡,或者添加和刪除節(jié)點時控制節(jié)點間的分片分配 
# 設置一個節(jié)點的并行恢復數(shù) 
# 1.初始化數(shù)據(jù)恢復時,并發(fā)恢復線程的個數(shù),默認為4 
# cluster.routing.allocation.node_initial_primaries_recoveries: 4 
# 2.添加刪除節(jié)點或負載均衡時并發(fā)恢復線程的個數(shù),默認為2 
# cluster.routing.allocation.node_concurrent_recoveries: 2 
# 設置恢復時的吞吐量(例如:100mb,默認為0無限制.如果機器還有其他業(yè)務在跑的話還是限制一下的好) 
# indices.recovery.max_bytes_per_sec: 20mb 
# 設置來限制從其它分片恢復數(shù)據(jù)時最大同時打開并發(fā)流的個數(shù),默認為5 
# indices.recovery.concurrent_streams: 5 
# 注意: 合理的設置以上參數(shù)能有效的提高集群節(jié)點的數(shù)據(jù)恢復以及初始化速度 
################################## Discovery ################################## 
# 設置這個參數(shù)來保證集群中的節(jié)點可以知道其它N個有master資格的節(jié)點.默認為1,對于大的集群來說,可以設置大一點的值(2-4) 
# discovery.zen.minimum_master_nodes: 1 
# 探查的超時時間,默認3秒,提高一點以應對網(wǎng)絡不好的時候,防止腦裂 
# discovery.zen.ping.timeout: 3s 
# For more information, see 
# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html> 
# 設置是否打開多播發(fā)現(xiàn)節(jié)點.默認是true. 
# 當多播不可用或者集群跨網(wǎng)段的時候集群通信還是用單播吧 
# discovery.zen.ping.multicast.enabled: false 
# 這是一個集群中的主節(jié)點的初始列表,當節(jié)點(主節(jié)點或者數(shù)據(jù)節(jié)點)啟動時使用這個列表進行探測 
# discovery.zen.ping.unicast.hosts: ["host1", "host2:port"] 
# Slow Log部分與GC log部分略,不過可以通過相關日志優(yōu)化搜索查詢速度 
################  X-Pack ###########################################
# 官方插件 相關設置請查看此處
# https://www.elastic.co/guide/en/x-pack/current/xpack-settings.html
############## Memory(重點需要調(diào)優(yōu)的部分) ################ 
# Cache部分: 
# es有很多種方式來緩存其內(nèi)部與索引有關的數(shù)據(jù).其中包括filter cache 
# filter cache部分: 
# filter cache是用來緩存filters的結果的.默認的cache type是node type.node type的機制是所有的索引內(nèi)部的分片共享filter cache.node type采用的方式是LRU方式.即:當緩存達到了某個臨界值之后,es會將最近沒有使用的數(shù)據(jù)清除出filter cache.使讓新的數(shù)據(jù)進入es. 
# 這個臨界值的設置方法如下:indices.cache.filter.size 值類型:eg.:512mb 20%。默認的值是10%。 
# out of memory錯誤避免過于頻繁的查詢時集群假死 
# 1.設置es的緩存類型為Soft Reference,它的主要特點是據(jù)有較強的引用功能.只有當內(nèi)存不夠的時候,才進行回收這類內(nèi)存,因此在內(nèi)存足夠的時候,它們通常不被回收.另外,這些引用對象還能保證在Java拋出OutOfMemory異常之前,被設置為null.它可以用于實現(xiàn)一些常用圖片的緩存,實現(xiàn)Cache的功能,保證最大限度的使用內(nèi)存而不引起OutOfMemory.在es的配置文件加上index.cache.field.type: soft即可. 
# 2.設置es最大緩存數(shù)據(jù)條數(shù)和緩存失效時間,通過設置index.cache.field.max_size: 50000來把緩存field的最大值設置為50000,設置index.cache.field.expire: 10m把過期時間設置成10分鐘. 
# index.cache.field.max_size: 50000 
# index.cache.field.expire: 10m 
# index.cache.field.type: soft 
# field data部分&&circuit breaker部分: 
# 用于fielddata緩存的內(nèi)存數(shù)量,主要用于當使用排序,faceting操作時,elasticsearch會將一些熱點數(shù)據(jù)加載到內(nèi)存中來提供給客戶端訪問,但是這種緩存是比較珍貴的,所以對它進行合理的設置. 
# 可以使用值:eg:50mb 或者 30%(節(jié)點 node heap內(nèi)存量),默認是:unbounded #indices.fielddata.cache.size: unbounded 
# field的超時時間.默認是-1,可以設置的值類型: 5m #indices.fielddata.cache.expire: -1 
# circuit breaker部分: 
# 斷路器是elasticsearch為了防止內(nèi)存溢出的一種操作,每一種circuit breaker都可以指定一個內(nèi)存界限觸發(fā)此操作,這種circuit breaker的設定有一個最高級別的設定:indices.breaker.total.limit 默認值是JVM heap的70%.當內(nèi)存達到這個數(shù)量的時候會觸發(fā)內(nèi)存回收
# 另外還有兩組子設置: 
#indices.breaker.fielddata.limit:當系統(tǒng)發(fā)現(xiàn)fielddata的數(shù)量達到一定數(shù)量時會觸發(fā)內(nèi)存回收.默認值是JVM heap的70% 
#indices.breaker.fielddata.overhead:在系統(tǒng)要加載fielddata時會進行預先估計,當系統(tǒng)發(fā)現(xiàn)要加載進內(nèi)存的值超過limit * overhead時會進行進行內(nèi)存回收.默認是1.03 
#indices.breaker.request.limit:這種斷路器是elasticsearch為了防止OOM(內(nèi)存溢出),在每次請求數(shù)據(jù)時設定了一個固定的內(nèi)存數(shù)量.默認值是40% 
#indices.breaker.request.overhead:同上,也是elasticsearch在發(fā)送請求時設定的一個預估系數(shù),用來防止內(nèi)存溢出.默認值是1 
# Translog部分: 
# 每一個分片(shard)都有一個transaction log或者是與它有關的預寫日志,(write log),在es進行索引(index)或者刪除(delete)操作時會將沒有提交的數(shù)據(jù)記錄在translog之中,當進行flush 操作的時候會將tranlog中的數(shù)據(jù)發(fā)送給Lucene進行相關的操作.一次flush操作的發(fā)生基于如下的幾個配置 
#index.translog.flush_threshold_ops:當發(fā)生多少次操作時進行一次flush.默認是 unlimited #index.translog.flush_threshold_size:當translog的大小達到此值時會進行一次flush操作.默認是512mb 
#index.translog.flush_threshold_period:在指定的時間間隔內(nèi)如果沒有進行flush操作,會進行一次強制flush操作.默認是30m #index.translog.interval:多少時間間隔內(nèi)會檢查一次translog,來進行一次flush操作.es會隨機的在這個值到這個值的2倍大小之間進行一次操作,默認是5s 
#index.gateway.local.sync:多少時間進行一次的寫磁盤操作,默認是5s 
```
# HEAD 使用
> elasticsearch-head是一個elasticsearch的集群管理工具,它是完全由html5編寫的獨立網(wǎng)頁程序,你可以通過插件把它集成到es
## 1.打開http://localhost:9200/_plugin/head/
> 在地址欄輸入es服務器的ip地址和端口點connect就可以連接到集群。下面是連接后的視圖。這是主界面,在這里可以看到es集群的基本信息(如:節(jié)點情況,索引情況)。
![image](http://img.my.csdn.net/uploads/201211/17/1353133910_8134.jpg)
>主分片與副本的區(qū)別是粗細邊框
界面的右邊有些按鈕,如:node stats, cluster nodes,這些是直接請求es的相關狀態(tài)的api,返回結果為json,如下圖:
![image](http://img.my.csdn.net/uploads/201211/17/1353133911_9624.jpg)
>在索引下面有info和action兩個按鈕。info是可以查看索引的狀態(tài)和mapping的定義。action是對索引進行操作,如:添加別名、刷新、關閉索引,刪除索引等。  
![image](http://img.my.csdn.net/uploads/201211/17/1353134135_5729.jpg)![image](http://img.my.csdn.net/uploads/201211/17/1353134135_7264.jpg)
> browser瀏覽界面,這個界面可以同時查看多個索引的數(shù)據(jù),也可以查詢指定字段的數(shù)據(jù)  
![image](http://img.my.csdn.net/uploads/201211/17/1353133911_8912.jpg)  
> Structured Query查詢界面,這個界面可以對某個索引進行一些復雜查詢,如下面這個例子是查詢product索引,構造boolquery,title字段里查詢“產(chǎn)品”關鍵詞,price范圍為10到100的記錄。  
![image](http://img.my.csdn.net/uploads/201211/17/1353133912_7352.jpg)  
> Any Request任意請求界面,這個界面可以說是個rest的客戶端,可以通過它來對es進行一些請求操作或測試api接口,下面這個例子是把product索引的副本數(shù)設置為1,更多的api可以到es官網(wǎng)查詢。
![image](http://img.my.csdn.net/uploads/201211/17/1353133912_7587.jpg)