首页 技术 正文
技术 2022年11月9日
0 收藏 794 点赞 2,650 浏览 3348 个字

环境
  虚拟机:VMware 10
  Linux版本:CentOS-6.5-x86_64
  客户端:Xshell4
  FTP:Xftp4
  jdk8
 

一、概念
ElasticSearch:
  基于Lucene全文搜索框架;
  实时的高扩展的分布式的开源搜索引擎;
  Java开发,基于RESTful web接口;

Lucene是一个全文搜索框架,而不是应用产品。核心工作就是给搜索内容定位,使用方式:倒排索引。

何为倒排索引?
举个例子:有个文档,文档有以下两行数据
我是中国人(1)
中国是全球人口最多的国家,中国人也最多(2)

索引如下:
1,我 (1:1){0}:(第1行:出现1次){偏移量0}
2,中国 (1:1) {2},(2:2){0,15}:(第1行:出现1次){偏移量2},(第2行:出现2次){偏移量0和15}

【Elasticsearch学习之一】Elasticsearch

输入源:对于要处理的数据,可以是文本文件,可以是数据库数据,也可以网页,我们将其抽象为Document文档,文档里可以定义多个Field,比如context、size、path等等,每个field都会设置三个设置:是否保存、是否分词、是否索引;
分词处理:根据设置,进行过滤,分词
倒排索引:根据设置,进行索引
存储:根据设置,对于需要保存的数据进行保存,比如文档路径;

ES和关系型数据库的数据对比:

【Elasticsearch学习之一】Elasticsearch

二、ES集群搭建

方案
PCS101 196.168.123.101
PCS101 196.168.123.102
PCS101 196.168.123.103

java版本要求:最低1.7

第一步:创建ES运行用户,ES不允许使用root运行

#创建用户
[root@PCS101 ~]# useradd cluster
#设置用户密码
[root@PCS101 ~]# echo | passwd --stdin cluster
#root创建目录 root 用户创建 /opt/cluster/es(普通用户无法创建)
[root@PCS101 ~]# mkdir -p /opt/cluster/es (注意:此时的目录权限属于root)
#目录权限赋给新用户
在父目录cluster下执行: chown cluster:cluster es

第二步:上传elasticsearch-2.2.1.zip至/usr/local/src
#切换用户 使用cluster用户解压elasticsearch-2.2.1.zip包至es目录,保证es文件属于用户cluster:

[root@PCS101 src]# su cluster
[cluster@PCS101 src]$ unzip /usr/local/src/elasticsearch-2.2..zip -d /opt/cluster/es

第三步:修改配置文件

[cluster@PCS101 es]$ cd /opt/cluster/es/elasticsearch-2.2./config && ll
total
-rw-rw-r--. cluster cluster Jan elasticsearch.yml
-rw-rw-r--. cluster cluster Jan logging.yml
[cluster@PCS101 config]$ vi elasticsearch.yml

修改:

---------------cluster-------------------------
cluster.name: wjy-es
----------------node-------------------------------
node.name: PCS101 (分发后各节点修改)
----------------network--------------------------------
network.host: 196.168.123.101 (分发后修改)
http.port: (放开)#末尾增加防脑裂:
#关闭多播模式 来一台加一台
discovery.zen.ping.multicast.enabled: false
#按照自定义节点清单设置集群
discovery.zen.ping.unicast.hosts: ["196.168.123.101","196.168.123.102", "196.168.123.103"]
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s

分发另外两个节点:

[cluster@PCS101 es]$ scp -r ./elasticsearch-2.2./ cluster@PCS102:`pwd`
[cluster@PCS101 es]$ scp -r ./elasticsearch-2.2./ cluster@PCS103:`pwd`

第四步:启动(ES启动比较慢)

#正常打印日志启动
[cluster@PCS101 bin]$ /opt/cluster/es/elasticsearch-2.2./bin/elasticsearch
#后台运行
[cluster@PCS101 bin]$ /opt/cluster/es/elasticsearch-2.2./bin/elasticsearch -d

验证:

[cluster@PCS101 ~]$ jps
Jps
Elasticsearch

访问三个节点,默认返回的是json串
http://196.168.123.101:9200
http://196.168.123.102:9200
http://196.168.123.103:9200

【Elasticsearch学习之一】Elasticsearch

三、插件
上面访问返回的是json串,不太友好,这里安装图形可视化插件head,重启
第一步:ftp上传head插件包 拷贝至/opt/cluster/es/elasticsearch-2.2.1/下面

[root@PCS101 bin]$ cp -abr /usr/local/src/plugins/ /opt/cluster/es/elasticsearch-2.2./
[root@PCS101 bin]$ cd /opt/cluster/es/elasticsearch-2.2./plugins && chown -R cluster:cluster head

分发至102、103:

[root@PCS101 bin]$ su cluster && cd /opt/cluster/es/elasticsearch-2.2./plugins
[cluster@PCS101 plugins]$ scp -r ./head/ cluster@PCS102:`pwd`
[cluster@PCS101 plugins]$ scp -r ./head/ cluster@PCS103:`pwd`

第二步:重启

[cluster@PCS101 bin]$ /opt/cluster/es/elasticsearch-2.2./bin/elasticsearch -d

验证:
http://196.168.101:9200/_plugin/head?pretty
http://196.168.123.102:9200/_plugin/head?pretty
http://196.168.123.103:9200/_plugin/head?pretty

【Elasticsearch学习之一】Elasticsearch

其他站点插件(以网页形式展现)
BigDesk Plugin (作者 Lukáš Vlček)
简介:这个主要提供的是节点的实时状态监控,包括jvm的情况,linux的情况,elasticsearch的情况
安装bin/plugin install lukas-vlcek/bigdesk
删除bin/plugin remove bigdesk
http://IP:9200/_plugin/bigdesk/
http://ip:9200/_cluster/state?pretty

Paramedic Plugin (作者 Karel Minařík)
简介:es监控插件

SegmentSpy Plugin (作者 Zachary Tong)
简介:查看es索引segment状态的插件

Inquisitor Plugin (作者 Zachary Tong)
简介:这个插件主要用来调试你的查询。

官网文档
elasticsearch详解
Elasticsearch实战干货
Lucene介绍与入门使用

196.168
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903