什么是 ElasticSearch?
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。
我们建立一个网站或应用程序,并要添加搜索功能,但是想要完成搜索工作的创建是非常困难的。我们希望搜索解决方案要运行速度快,我们希望能有一个零配置和一个完全免费的搜索模式,我们希望能够简单地使用JSON通过HTTP来索引数据,我们希望我们的搜索服务器始终可用,我们希望能够从一台开始并扩展到数百台,我们要实时搜索,我们要简单的多租户,我们希望建立一个云的解决方案。因此我们利用Elasticsearch来解决所有这些问题及可能出现的更多其它问题。
server1 充当master
[root@server1 elk]# yum install elasticsearch-2.3.3.rpm
[root@server1 ~]# yum install jdk-8u121-linux-x64.rpm
[root@server1 ~]# cd /etc/elasticsearch/
[root@server1 elasticsearch]# ls
elasticsearch.yml logging.yml scripts
存放数据的位置
[root@server1 elasticsearch]# cd /var/lib/elasticsearch/
[root@server1 elasticsearch]# ls
存放日志
[root@server1 elasticsearch]# cd /var/log/elasticsearch/
[root@server1 elasticsearch]# pwd
/var/log/elasticsearch
[root@server1 elasticsearch]# cd /etc/elasticsearch/
[root@server1 elasticsearch]# vim elasticsearch.yml
cluster.name: my-es
node.name: server1
path.data: /var/lib/elasticsearch/
bootstrap.mlockall: true 锁定内存
network.host: 172.25.23.1
http.port: 9200
[root@server1 elasticsearch]# /etc/init.d/elasticsearch start
Starting elasticsearch: [ OK ]
[root@server1 bin]# pwd
/usr/share/elasticsearch/bin
[root@server1 bin]# ./plugin list
Installed plugins in /usr/share/elasticsearch/plugins:
- No plugin detected
[root@server1 elk]# /usr/share/elasticsearch/bin/plugin install file:/root/elk/elasticsearch-head-master.zip
[root@server1 elk]# /usr/share/elasticsearch/bin/plugin list
Installed plugins in /usr/share/elasticsearch/plugins:
- head
浏览器输入
http://172.25.23.1:9200/_plugin/head
辅助分片
健康值的评判:
黄色:主分片未丢失
红色:已经丢失
[root@server1 elasticsearch]# vim elasticsearch.yml
node.matser: true 表示为master节点
node.data: false 数据节点为假
node.enabled: true 处理查询请求
discovery.zen.ping.unicast.hosts: ["server1", "server2","server3"]
[root@server1 elasticsearch]# /etc/init.d/elasticsearch reload
Stopping elasticsearch: [ OK ]
Starting elasticsearch: [ OK ]
[root@server1 elasticsearch]# scp elasticsearch.yml server2:/etc/elasticsearch/
root@server2's password:
elasticsearch.yml 100% 3198 3.1KB/s 00:00
[root@server1 elasticsearch]# scp elasticsearch.yml server3:/etc/elasticsearch/
root@server3's password:
elasticsearch.yml 100% 3198 3.1KB/s 00:00
server2.3雷同server1下载安装配置环境
[root@server2 ]# yum install elasticsearch-2.3.3.rpm
[root@server2 ~]# yum install jdk-8u121-linux-x64.rpm
[root@server2 elasticsearch]# vim elasticsearch.yml
node.name: server2
node.matser: false
node.data: true
node.enabled: true
path.data: /var/lib/elasticsearc
path.logs: /var/log/elasticsearch
http.port: 9200
network.host: 172.25.23.2
bootstrap.mlockall: true
node.matser: false
node.data: true
node.enabled: true
discovery.zen.ping.unicast.hosts: ["server1", "server2","server3"
[root@server2 elasticsearch]# /etc/init.d/elasticsearch start
Starting elasticsearch: [ OK ]
测试集群:
浏览器输入:172.25.23.1
查询你的集群健康信息
[root@server1 elasticsearch]# curl -XGET 'http://172.25.23.1:9200/_cluster/health?pretty=true'
{
"cluster_name" : "my-es",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 2,
"active_primary_shards" : 5,
"active_shards" : 10,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
删除之前所建立的索引:
[root@server1 elasticsearch]# curl -XDELETE 'http://172.25.23.1:9200/index.demo'
{"acknowledged":true}[root@server1 elasticsearch]#