第三节 elasticsearch搭建

来源:互联网 发布:亚马逊大还是淘宝大 编辑:程序博客网 时间:2024/06/04 18:59

一 Elasticsearch安装以及配置简介
安装elasticsearch
 [root@xadev03 elk]# wget      https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-2.0.0.tar.gz
 [root@xadev03 elk]# tar –zvxf  elasticsearch-2.0.0.tar.gz
 [root@xadev03 elk]# cd elasticsearch-2.0.0
 [root@xadev03 elk]# vi  config/elasticsearch.yml
 做如下修改:
 




root@xadev03 elk]# bin/elasticsearch &      --启动elasticsearch 服务 如下图


分别在192.168.100.212 上  按照上述步骤安装elasticsearch 服务。
  elasticsearch 有3个比较常用的插件分别为:elasticsearch-head,elasticsearch-kopf,
  elasticsearch-bigdesk
二 Elasticsearch常用插件安装
 elasticsearch-head的作用是展现elasticSearch集群的拓扑结构,并且通过它来进行索引以及节点级别的操作;它提供一组针对集群的查询API,并将结果以JSON 和表格的形式返回;它提供一些快捷菜单,用于展示集群的各种状态。
     访问方式:http://localhost:9200/_plugin/head/
elasticsearch-kopf是elasticSearch的管理工具,也提供了对ES集群操作的API
     访问方式: http://localhost:9200/_plugin/kopf
bigdesk 监控集群的各种状态,如:cpu、内存使用情况,索引数据、搜索情况,http连接数等
     访问方式: http://localhost:9200/_plugin/bigdesk/ 
 [root@xadev03 elk]# bin/plugin install mobz/elasticsearch-head   --在线安装head插件
 [root@xadev03 elk]# bin/plugin install lmenezes/elasticsearch-kopf   --在线安装kopf插件
 [root@xadev03 elk]# bin/plugin -install lukas-vlcek/bigdesk   --在线安装bigdesk插件(注 意:bigdesk 暂时只支持elasticsearch1.3.x 的版本)
安装elasticsearch-analysis-ik分词器
 [root@xadev03 elk]# wget  
 https://codeload.github.com/medcl/elasticsearch-analysis-ik/zip/v1.5.0
 [root@xadev03 elk]# unzip elasticsearch-analysis-ik-master.zip  
 [root@xadev03 elk]#  cd  elasticsearch-analysis-ik-master
 [root@xadev03 elk]#  mvn clean package
目录结构


打开config目录如下 把ik复制到elasticsearch 的config目录下


 编译完成后,将 target/release/ik**.zip 复制到elasticsearch的 plugins/ik 目录下并解压,如果不存在ik 自己创建一个;然后重启elasticsearch 服务。
 分别在192.168.100.212 服务器上按照上述步骤安装插件和中文分词器。
 访问:http://localhost:9200/_plugin/head/   如图:


 如图:集群健康值yellow(8/12)意思是:集群中所有索引共有分片和副本12 个,当前用到的只有8个(每个索引默认有5个分片和一个副本)。   node1 和node2 分别代表集群中的两个节点。
  访问:http://192.168.100.211:9200/_plugin/kopf 如图:


如图:实现集群的管理。以及各种配置参数的查阅。
由于bigdesk  插件只支持elasticsearch1.3.x版本,故此不做详述。
三Elasticsearch集群单点故障以及常用命令
以下三个常用命令:
 curl '192.168.100.212:9200/_cat/health?v'         --检查集群是否健康
 curl '192.168.100.212:9200/_cat/nodes?v'         --获取集群中的节点列表
 curl '192.168.100.212:9200/_cat/indices?v'        --列出集群中的所有索引
 [root@xadev03 elk]# curl '192.168.100.212:9200/_cat/health?v'  


[root@xadev03 elk]# curl '192.168.100.212:9200/_cat/nodes?v'  


[root@xadev03 elk]# curl '192.168.100.212:9200/_cat/indices?v'


从图中可以看出node2 为主节点,node1和node2 为从节点
停止node1,elasticsearch 集群自动选择主节点,如图:


es集群自动选择node1 为主节点提供服务
停止node2 ,如图所示:
      es集群自动选择node1为主节点提供服务


  Elasticsearch常用命令:
curl -XPUT 'localhost:9200/customer?pretty' --创建一个名字叫customer 的索引
curl -XPUT ‘localhost:9200/customer/external/1?pretty’ -d ‘{“name”: “John Doe”}‘—给索引为customer,type为external 添加json 格式的数据
curl -XGET 'localhost:9200/customer/external/1?pretty' --用get获取数据
curl -XPUT ‘localhost:9200/customer/external/1?pretty’ -d ‘{“name”: “John Doe”}‘—修改索引数据
curl -XDELETE 'localhost:9200/customer?pretty' -- 删除索引
curl -XPOST 'localhost:9200/customer?/_bulk?pretty' --data-binary @mydata.json --批量导入
     XPUT 和xPOST 区别:XPUT 导入小量数据,XPOST 导入大量数据

0 0
原创粉丝点击