ElasticSearch的介绍及安装

一、ElasticSearch的介绍

1、简介(官网:https://www.elastic.co/)

    ElasticSearch是一款基于Luncene的实时分布式搜索和分析引擎。采用java编写,目标是让全文搜索变得简单(应用倒排索引),还可以进行大规模的横向扩展,支持PB级的结构化和非结构化海量数据的处理。(支持json格式文件)

2、ElasticSearch与MySQL对比

MySQLElasticSearch
database(数据库)index(s索引库)
table(表)type(类型)
row(行)document(文档)
column(列)field(字段)

   3、Rest简介

        REST全称Representational State Transfer。是一种软件的架构风格,而不是标准,只是提供了一组设计原则和约束条件。它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制。

其实说白了就是类似HTTP的访问,和HTTP非常的相似。

REST操作:

               GET:获取对象的当前状态;

               PUT:改变对象的状态;

               POST:创建对象;

               DELETE:删除对象;

               HEAD:获取头信息。

资源

一组资源的URI,比如:

http://example.com/res/

单个资源的URI,比如:

http://example.com/res/123

GET

列出URI,以及该资源组中每个资源的详细信息(后者可选)

获取指定的资源的详细信息,格式可以自选一个合适的网络媒体类型(比如:XML、JSON等)

PUT

使用给定的一组资源替换当前整组资源

替换/创建指定的资源。并将其追加到相应的资源组中。

POST

在本组资源中创建/追加一个新的资源。该操作往往返回新的URL

把指定的资源当做一个资源组,并在其下创建/追加一个新的元素,使其隶属于当前资源。

DELETE

删除整组资源

删除指定的元素

4、CURL简介

     curl是利用URL语法在命令行方式下工作的开源文件传输工具,使用curl可以简单实现常见的get/post请求。简单的认为是可以在命令行下面访问url的一个工具。

curl:

          -X 指定http的请求方法 有HEAD GET POST PUT DELETE

          -d 指定要传输的数据

         -H 指定http请求头信息

基本命令:

1、创建索引库(相当于创建数据库)

curl -XPUT 'http://qyl01:9200/qyl'

 2、创建索引

1)创建index=1的数据(post方式)
curl -H "Content-Type:application/json" -XPOST 
 'http://qyl01:9200/qyl/product/1' -d 
 '{"name" : "hadoop", "author" : "Doug Cutting","version":"2.7.6"}'

2)创建index=2的数据(put方式)
  curl -H "Content-Type:application/json" -XPUT 
	   'http://qyl01:9200/qyl/product/2' -d
	  '{"name" : "hive", "author" : "qyl","version":"100.100.100"}'

   put和post的区别

1)put是幂等方法,post不是,所以put用于用户数据更新,post用于新增比较合适

2)创建操作可以使用post,也可以使用Put,区别就在于post是作用的一个集合资源之上的,而Put操作是作用在一个具体资源之上的,比如说很多资源使用数据库自增主键作为标识信息,这个时候就需要使用Put了。

3、查询

1)查询qyl索引库下,类型为product的index=1的数据

 curl -XGET  http://qyl01:9200/qyl/product/1?pretty

2)检索文档中的一部分,显示特定的字段内容

 curl -XGET 'http://qyl01:9200/qyl/product/1?_source=name,author&pretty'

   3)获取source的数据

curl -XGET 'http://qyl01:9200/qyl/product/1/_source?pretty'

4)查询所有

curl -XGET 'http://qyl01:9200/qyl/product/_search?pretty'

4、更新

1)局部更新 :(如果存在就会替换原来的_source中的数据,_version会加1 )

curl -H "Content-Type:application/json" -XPOS  
 http://qyl01:9200/qyl/product/1 -d'{"name" : "apache-hadoop"}‘

2)真正的局部更新

 curl   -H "Content-Type:application/json" 
 -XPOST http://qyl01:9200/qyl/product/1/_update 
 -d'{"doc":{"name" : "hadoop", "author" : "qyl","version":"2.7.6"}}'

5、删除

curl   -H "Content-Type:application/json" -XDELETE  
http://qyl01:9200/qyl/product/3/

6、查看数据

curl -H "Content-Type:application/json"  -XGET 
   'http://qyl01:9200/account/bank/_search?pretty'

 

二、ElasticSearch的安装

1、流程

  前提:必须要安装在普通用户下面,在2.0x之后不支持root安装!

1)解压     

tar -zxvf soft/elasticsearch-6.2.0.tar.gz -c app/

2)重命名

mv elasticsearch-6.2.0/ elasticsearch

3)修改配置文件  $ES_HOME/conf/elasticsearch.yml

 cluster.name: qyl-1807
	  node.name: hadoop
	  node.attr.rack: rack-1805
	  path.data: /home/qyl/data/elasticsearch
	  path.logs: /home/qyl/logs/elasticsearch
	  bootstrap.memory_lock: false
	  bootstrap.system_call_filter: false
	  network.host: qyl01

4)启动

bin/elasticsearch -d

2、出现的问题

1)内核版本不行:解决方案,修改内核版本

a.查看内核 : uname -a

b.升级nss  : yum -y update nss

c.导入pubic key:    sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

d.升级内核版本:  sudo rpm -Uvh https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

e.编辑grub.conf文件: sudo vim /etc/grub.conf

f.重启虚拟机: reboot

 

2)启动时,提示内存不够

a. 在limits.conf 添加类似如下内容

sudo vim /etc/security/limits.conf
   * soft nofile 65536
   * hard nofile 131072
   * soft nproc 2048
   * hard nproc 4096

 b.进入/etc/security/limits.d/目录下修改配置文件  90-nproc.conf

c.修改sudo vim /etc/sysctl.conf

添加如下内容: vm.max_map_count=262144

d.生效  : sudo sysctl -p

 

3.启动集群

1.集群的配置:

     修改$ES/config/elasticsearch.yml 文件(每个节点都得改)

# limit.
bootstrap.system_call_filter: false
# Elasticsearch performs poorly when the system is swapping the me
mory.
#
# ---------------------------------- Network ---------------------
--------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: qyl01
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery --------------------
--------------
#
# Pass an initial list of hosts to perform discovery when new node
 is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]

node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["qyl01", "qyl02", "qyl03"]

#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
"elasticsearch.yml" 92L, 2997C                  59,1          70%
# on the system and that the owner of the process is allowed to use this
# limit.
bootstrap.system_call_filter: false
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: qyl01
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]

node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["qyl01", "qyl02", "qyl03"]

#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
                                                                                 

   2、启动集群(用elasticSearch-head插件)

 

 

 

  

 

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
很抱歉,目前最新版本Elasticsearch 是 7.15.1,没有 8.5.3 版本。不过我可以为您介绍一下 Elasticsearch 的单机安装部署步骤。 1. 下载 Elasticsearch:您可以从 Elasticsearch 官方网站(https://www.elastic.co/downloads/elasticsearch)下载适合您操作系统的安装包。 2. 解压安装包:将下载的安装包解压到您选择的目录中。 3. 配置 Elasticsearch:进入解压后的目录,找到 `config` 文件夹,编辑 `elasticsearch.yml` 文件。您可以根据需要修改以下配置项: - `cluster.name`:集群名称,默认为 "elasticsearch"。 - `node.name`:节点名称,默认为随机生成的唯一标识。 - `path.data`:数据存储路径,默认为 "data" 文件夹。 - `path.logs`:日志存储路径,默认为 "logs" 文件夹。 4. 启动 Elasticsearch:在命令行中进入 Elasticsearch 的 bin 目录,执行以下命令启动 Elasticsearch: - Windows:`.\elasticsearch.bat` - Linux/MacOS:`./elasticsearch` 5. 验证安装:打开浏览器,访问 `http://localhost:9200`,如果看到类似以下信息表示 Elasticsearch 已成功启动: ``` { "name" : "your_node_name", "cluster_name" : "your_cluster_name", "cluster_uuid" : "your_cluster_uuid", "version" : { "number" : "7.15.1", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "unknown", "build_date" : "2021-10-07T21:56:19.031608185Z", "build_snapshot" : false, "lucene_version" : "8.9.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } ``` 这样就完成了 Elasticsearch 的单机安装部署。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值