玩转大数据

(十二)大数据学习之ElasticSearch

2019-11-23  本文已影响0人  Movle

ElasticSearch

一.全文检索技术简介

1.什么是搜索?

2.如何实现搜索?

select * from employee e where e.name like "%李雷%";
select * from employee e where e.comment like "好%";

3.全文检索

4.倒排索引
(1).传统数据库存储:

id 描述
1 优秀员工
2 销售冠军
3 优秀团队领导
4 优秀项目

(2).倒排索引处理步骤:

关键词 id
优秀 1,3,4
员工 1
销售 2
团队 3
... ...

5.Lucene:全文检索引擎

6.Elasticsearch

7.Elasticsearch特点

二.elasticsearch单节点安装

1.单节点安装
(1)先前条件:

(2)上传到linux:/opt/software
(3)解压

cd /opt/software

tar -zxvf elasticsearch-5.6.2.tar.gz -C /opt/module

(3)新建data,logs文件夹

cd /opt/module/elasticsearch-5.6.2

mkdir data

mkdir logs
image.png

(4)修改配置文件(root用户)

a.修改elasticsearch.yml文件

vi /opt/module/elasticsearch-5.6.2/conf/elasticsearch.yml

修改内容如下:

# ---------------------------------- Cluster -------------------------------------
cluster.name: my-application
# ------------------------------------ Node --------------------------------------
node.name: node-102
# ----------------------------------- Paths ---------------------------------------
path.data: /opt/module/elasticsearch-5.6.1/data
path.logs: /opt/module/elasticsearch-5.6.1/logs
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
# ---------------------------------- Network ------------------------------------
network.host: 192.168.127.121 
# --------------------------------- Discovery ------------------------------------
discovery.zen.ping.unicast.hosts: ["bigdata121"]
image.png

说明:

b.修改limits.conf文件

vi /etc/security/limits.conf

//在文件末尾添加如下内容

* soft nofile 655360
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
image.png

c.修改limits.d文件

vi /etc/security/limits.d/20-nproc.conf

//修改内容如下
*    soft    nproc    1024
//改为
*    soft    nproc    4096
image.png

d.修改配置sysctl.conf

vi /etc/sysctl.conf

//添加内容
vm.max_map_count=655360
image.png

(5)新建linux用户:es不能以root用户启动

useradd kai

passwd kai
输入密码



cd /opt/module/elasticsearch-5.6.2       //进入的elasticsearch目录

chown -R kai:users *      //修改权限

su kai        //切换到kai用户,启动es
image.png

2.启动:

su kai      //切换到kai用户
cd /opt/module/elasticsearch-5.6.2

bin/elasticsearch       //启动
image.png

注意:can not run elasticsearch as root
3.验证:

curl 'http://192.168.127.121:9200'

curl -XGET '192.168.127.121:9200/_cat/health?v&pretty'

image.png

当看到status是green时,证明启动成功

3.当启动es,报错:

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

[2]: max number of threads [1024] for user [hduser] is too low, increase to at least [4096]

[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

[4]: system call filters failed to install; check the logs and fix your configuration or disable system 

(1)配置linux系统环境:
(2)切换到 root 用户,编辑 limits.conf 添加类似如下内容

vi /etc/security/limits.conf

新增内容如下:

* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096

(3)进入 limits.d 目录下修改配置文件。

vi /etc/security/limits.d/90-nproc.conf

把 * soft nproc 1024 改成4096
(4)修改配置 sysctl.conf

vi /etc/sysctl.conf 

添加内容如下:

vm.max_map_count=655360

执行命令:

sysctl -p

(5)重新登录kai用户,重新启动es,如果还有报错,则需重启虚拟机

curl -XGET 'http://192.168.127.121:9200/_cat/health?v&pretty'
curl -XGET 'ip地址:9200/index名称/_search?pretty' -H 'Content-Type: application/json' -d'

{

  "query": { "match_all": {} }

}'

三.Elasticsearch集群安装:

1.前提:安装好jdk
2.下载安装包:
3.上传到linux
4.解压

5.新建data,logs文件夹

cd /opt/module/elasticsearch-5.6.2

mkdir data

mkdir logs
image.png

6.修改配置文件(root用户)

(1).修改elasticsearch.yml文件

vi /opt/module/elasticsearch-5.6.2/conf/elasticsearch.yml

修改内容如下:

# ---------------------------------- Cluster -------------------------------------
cluster.name: my-application
# ------------------------------------ Node --------------------------------------
node.name: JBS1
# ----------------------------------- Paths ---------------------------------------
path.data: /opt/module/elasticsearch-5.6.2/data
path.logs: /opt/module/elasticsearch-5.6.2/logs
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
# ---------------------------------- Network ------------------------------------
network.host: 192.168.127.121 
# --------------------------------- Discovery ------------------------------------
discovery.zen.ping.unicast.hosts: ["bigdata121","bigdata122","bigdata123"]

node.master: true
node.data: true

说明:

image.png image.png

(2).修改limits.conf文件

vi /etc/security/limits.conf

//在文件末尾添加如下内容

* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
image.png

(3).修改limits.d文件

vi /etc/security/limits.d/20-nproc.conf

//修改内容如下
*    soft    nproc    1024
//改为
*    soft    nproc    4096
image.png

(4).修改配置sysctl.conf

vi /etc/sysctl.conf

//添加内容
vm.max_map_count=655360
image.png

5.新建linux用户:es不能以root用户启动

useradd kai

passwd kai
输入密码



cd /opt/module/elasticsearch-5.6.2       //进入的elasticsearch目录

chown -R kai:users *      //修改权限

su kai        //切换到kai用户,启动es
image.png

6.将elasticsearch发送到bigdata122,bigdata123

cd /opt/module
scp -r elasticsearch-5.6.2/ bigdata122:/opt/module

scp -r elasticsearch-5.6.2/ bigdata123:/opt/module

7.再在bigdata122,bigdata123中修改elasticsearch.yml

# ------------------------------------ Node --------------------------------------
node.name: JBS2
# ---------------------------------- Network ------------------------------------
network.host: 192.168.127.122     //bigdata123改为:192.168.127.123 

node.master: true
node.data: true

其实和单节点安装差不多,只是elasticsearch.yml文件有细微不同

image.png image.png

8.集群安装参照:
【链接】手把手教你搭建一个Elasticsearch集群
https://cloud.tencent.com/developer/article/1189282

三.Elasticsearch head插件安装

1.下载插件:

2.下载nodejs:

3.安装nodejs:
(1)解压
(2)配置环境变量

export NODE_HOME=/usr/local/node-v6.9.2-linux-x64

export PATH=$PATH:$NODE_HOME/bin

(3)查看node和npm版本:

node -v

npm -v

4.解压head插件到/opt/module目录下:

unzip elasticsearch-head-master.zip

5.查看当前head插件目录下有无node_modules/grunt目录:

npm install grunt --save --registry=https://registry.npm.taobao.org

6.安装head插件:

npm install -g cnpm --registry=https://registry.npm.taobao.org

7.安装grunt

npm install -g grunt-cli --registry=https://registry.npm.taobao.org

8.编辑Gruntfile.js

vim Gruntfile.js

文件93行添加:

hostname:'0.0.0.0'

9.检查head根目录下是否存在base文件夹

mkdir base

cp base/* ../base/

10.启动grunt server:

grunt server -d

11.如果提示grunt的模块没有安装:

Local Npm module “grunt-contrib-clean” not found. Is it installed? 

Local Npm module “grunt-contrib-concat” not found. Is it installed? 

Local Npm module “grunt-contrib-watch” not found. Is it installed? 

Local Npm module “grunt-contrib-connect” not found. Is it installed? 

Local Npm module “grunt-contrib-copy” not found. Is it installed? 

Local Npm module “grunt-contrib-jasmine” not found. Is it installed? 

执行命令:

npm install grunt-contrib-clean -registry=https://registry.npm.taobao.org

npm install grunt-contrib-concat -registry=https://registry.npm.taobao.org

npm install grunt-contrib-watch -registry=https://registry.npm.taobao.org 

npm install grunt-contrib-connect -registry=https://registry.npm.taobao.org

npm install grunt-contrib-copy -registry=https://registry.npm.taobao.org 

npm install grunt-contrib-jasmine -registry=https://registry.npm.taobao.org

12.浏览器访问head插件:http://192.168.109.133:9100

上一篇 下一篇

猜你喜欢

热点阅读