转自大数据学习平台-大讲台:
http://www.dajiangtai.com/course/search.do?search=elastic
一、分片(shards)
- 一个索引库默认有5个分片,如果想更改分片数,必须在创建索引库的时候指定
POST /{indexname} -d {"settings":{"shards":5}}
例:
curl -XPOST http://hadoop01:9200/djtshards -d '{"settings":{"shards":5}}'
- 默认一个分片可以存储2,147,483,519条数据。
- 分片可以使得节点的压力均衡
二、副本(replactions)
- 默认一个分片有一个副本,可以在创建索引库的时候指定副本数量
-d {"settings":{"number_of_replacations":2}}
也可以在索引库已经存在的情况下更新副本数量
PUT /{indexname}/_settings -d {"index":"number_of_replacations":1}}
- 分片可以提高系统的容错性,主分片和副本一定式分布在不同的节点上的。
三、Recover
- es在有节点加入或者退出时,会重新分配分片及副本的分布。
- es集群节点地位平等,不存在单点故障,有两种发现机制:Zen和Ec2
- Zen配置:
#集群节点发现机制配置
#不使用默认的组播方式,改用单播方式(Point to Point)
discovery.zen.ping.multicast.enables: false
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
#单播的目标节点的ip或者hostname
discovery.zen.ping.unicast.hosts: ["192.168.174.20", "192.168.174.21", "192.168.174.22"]
四、gateway(数据持久化)
- hdfs方式
首先要安装插件,在github上查看下es于es-hdfs插件对应的版本
—————————————————————–
| Hadoop Plugin | ElasticSearch | Embedded Hadoop Version |
-----------------------------------------------------------------
| master | 0.21 -> master | 0.20.204.0 |
-----------------------------------------------------------------
| 1.2.0 | 0.19 -> 0.20 | 0.20.204.0 |
-----------------------------------------------------------------
| 1.1.0 | 0.19 -> 0.20 | 0.20.204.0 |
-----------------------------------------------------------------
| 1.0.0 | 0.18 | 0.20.204.0 |
-----------------------------------------------------------------
bin/plugin install elasticsearch/elasticsearch-repository-hdfs/2.2.0
修改配置文件 config/elasticsearch.yml
gateway:
type: hdfs
gateway:
hdfs:
uri: hdfs://cluster1/
五、mapping(索引)
- 即为索引类型的定义,类型的名称,类型有哪些属性(字段)
- 查看某个索引库的索引信息:
GET /{indexname}/_mapping?pretty
{
"djt" : {
"mappings" : {
"user" : {
"properties" : {
"age" : {
"type" : "long"
},
"name" : {
"type" : "string"
}
}
}
}
}
}
- 创建mapping
PUT /{indexname}/ -d {"mappings":{"user":{"properties":{"name":{"type":"string"}}}}}
- 更新mapping
POST /{indexname}/{typename} -d {"properties":{"name":{"type":"string"}}}