一 基础概念(官网地址:https://www.elastic.co/guide/en/elasticsearch/reference/6.0/getting-started.html)
near real (准实时搜索):秒级搜索
集群(cluster):多个node节点组合提供搜索服务
索引分片(shards):
`It allows you to horizontally split/scale your content volume`:他能水平切分你的内容,进行存储
`It allows you to distribute and parallelize operations across shards (potentially on multiple nodes) thus increasing performance/throughput`:他能让你可以在多个分片之间平行操作,来增加系统的吞吐量
- 副本(replicas):分片副本,解决系统索引的高可用问题(和kafka的副本类似)
It provides high availability in case a shard/node fails. For this reason, it is important to note that a replica shard is never allocated on the same node as the original/primary shard that it was copied from.
他提供了节点的高可用性.因此,原有节点和他的副本节点不要分配到相同的服务节点上,防止服务节点挂了,副本和原节点都不能使用
It allows you to scale out your search volume/throughput since searches can be executed on all replicas in parallel.
他使你可以水平扩展你的服务节点,提升系统的吞吐量
- rebalance概念:和kafka中概念类似,当集群中节点增加或减少时,进行重新分配shard在集群中的分布
二 安装
官网介绍es至少需要jdk8,且需要oracle jdk版本.所以如果安装的是open jdk需要卸载重装,可以参考:https://blog.csdn.net/wen524/article/details/88104688
第二步就是下载解压就好了:
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.1.tar.gz
在服务器建目录
mkdir es
useradd es 添加个es用户,因为es不允许用root启动
chown -R es 需要赋权限的目录
su es 用es用户登陆
tar -xvf elasticsearch-6.0.1.tar.gz 解压文件
cd elasticsearch-6.0.1/bin
nohup ./elasticsearch-6.0.1/bin/elasticsearch >nohup.log 2>&1 & 后台启动es
cat /es/nohup.log 查看启动日志
三 测试:
可以通过_cat命令查看es的状态:
cat是es提供的一套api,在kibana中可以直接GET 等方法使用,但我们用的比较多的还是rest接口形式,比如用curl命令:
[es@localhost bin]$ curl -X PUT "localhost:9200/customer?pretty&pretty"
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "customer"
}
[es@localhost bin]$ curl -X GET "localhost:9200/_cat/indices?v&pretty"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer 1U-ugoCHRbGnKrShYXKyzg 5 1 0 0 466b 466b
常用命令:
通过 curl localhost:9200/_cat 查看
[es@localhost bin]$ curl localhost:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates