【原创】《从0开始学Elasticsearch》—初识Elasticsearch
目录
1. Elasticsearch 是什么2. Elasticsearch 中基本概念3. Elasticsearch 安装4. 访问 Elasticsearch
1. Elasticsearch 是什么
Elasticsearch 是一个基于 Lucene 的实时的分布式搜索分析引擎,开箱即用,整合了全文检索、结构化搜索、分析三大功能。
为什么不直接用 Lucene ?Lucene 只是一个全文检索引擎的架构,提供了大量可用的 API,但其并不是一个完整的全文检索引擎,使用 Lucene 时,你还需要自己写代码,自己去封装成全文检索引擎。
2. Elasticsearch 中基本概念
- field:字段。
- Document :文档,一条数据,用 json 格式表示。一个Document 包含多个field,json 中的 key 即 field 。
- Type:类型,一个 Document 分组,和 mysql 中的 table 类似,但又不完全相同。一个 Type 包含多个Document,同一个 Type 中的 Document 所拥有的 field 可以不同,但最好保持一致。
- Index :索引,类似于 mysql 中的 database。一个 Index 包含多个 Type。默认情况下,Document 中的所有 field 都会被索引,这样这些 field 才会被搜索到。Elasticsearch 中有一个倒排索引(Inverted Index)的概念,可以实现 mysql 中 B+Tree索引加速检索的目的,后面文章我们会详细介绍倒排索引。
- shard:分片。可以将一个 Index 中的数据切分为多个 shard,然后将之存储在多台服务器上,以增大一个 Index 可以存储的数据量,加速检索能力,提升系统性能。
- replica :副本。replica 与 shard 存储的数据是相同的,replica 起到备份的作用。当 shard 发生故障时,可以从 replica 中读取数据,保证系统不受影响。
- Node:节点,单个 Elasticsearch 实例。节点名称默认随机分配。
- Cluster:集群,一组 Elasticsearch 实例。默认集群名称为 elasticsearch。
3. Elasticsearch 安装
前提条件:系统中已成功安装 jdk8
下载并解压:
cd /usr/local
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.tar.gz
tar -zxvf elasticsearch-6.6.0.tar.gz -C .
查看解压后的目录:
[root@153-215 local]# cd elasticsearch-6.6.0
[root@153-215 elasticsearch-6.6.0]# ls
bin config lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
启动 Elasticsearch:
[root@153-215 elasticsearch-6.6.0]# bin/elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000d4cc0000, 724828160, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 724828160 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid16393.log
遂,查看 Elasticsearch 的启动脚本,看启动时是否对内存大小有要求:
[root@153-215 elasticsearch-6.6.0]# vim bin/elasticsearch
#!/bin/bash
# CONTROLLING STARTUP:
#
# This script relies on a few environment variables to determine startup
# behavior, those variables are:
#
# ES_PATH_CONF -- Path to config directory
# ES_JAVA_OPTS -- External Java Opts on top of the defaults set
#
# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Note that
# the Xms and Xmx lines in the JVM options file must be commented out. Example
# values are "512m", and "10g".
#
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
source "`dirname "$0"`"/elasticsearch-env
ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
JVM_OPTIONS=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"`
ES_JAVA_OPTS="${JVM_OPTIONS//\$\{ES_TMPDIR\}/$ES_TMPDIR} $ES_JAVA_OPTS"
......
发现 Elasticsearch 启动时,读取了 jvm.options 文件,于是查看该文件:
[root@153-215 elasticsearch-6.6.0]# ls config
elasticsearch.yml jvm.options log4j2.properties role_mapping.yml roles.yml users users_roles
[root@153-215 elasticsearch-6.6.0]# cat config/jvm.options
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms1g
-Xmx1g
......
修改 jvm 的最大可用内存和最小可用内存如下:
-Xms256m
-Xmx256m
再次启动 Elasticsearch:
[root@153-215 elasticsearch-6.6.0]# bin/elasticsearch
[2019-02-13T16:42:53,177][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.6.0.jar:6.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.6.0.jar:6.6.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.6.0.jar:6.6.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.6.0.jar:6.6.0]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.6.0.jar:6.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.6.0.jar:6.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.6.0.jar:6.6.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.6.0.jar:6.6.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.6.0.jar:6.6.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.6.0.jar:6.6.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.6.0.jar:6.6.0]
... 6 more
这段报错信息也就是说,不能以 root 用户的身份启动 Elasticsearch,这一要求也是出于系统安全考虑,所以此处我先将 Elasticsearch 目录及目录内文件的拥有者修改为另一个用户,然后再用另一个用户启动:
[root@153-215 elasticsearch-6.6.0]# cd ..
[root@153-215 local]# chown -R lilinru:lilinru elasticsearch-6.6.0
[root@153-215 local]# su lilinru
[lilinru@153-215 local]$ cd elasticsearch-6.6.0
[lilinru@153-215 elasticsearch-6.6.0]$ bin/elasticsearch
....
[2019-02-13T17:10:23,443][INFO ][o.e.n.Node ] [_xV7bTf] starting ...
[2019-02-13T17:10:23,618][INFO ][o.e.t.TransportService ] [_xV7bTf] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2019-02-13T17:10:23,636][WARN ][o.e.b.BootstrapChecks ] [_xV7bTf] max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2019-02-13T17:10:23,636][WARN ][o.e.b.BootstrapChecks ] [_xV7bTf] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
....
发现启动时存在两个问题:
问题一: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]。
解决此问题,我们可以编辑 /etc/security/limits.conf 文件最底端 soft nofile 和 hard nofile 的配置为 65536:
[root@153-215 elasticsearch-6.6.0]# vim /etc/security/limits.conf
...
# End of file
...
* soft nofile 65536
* hard nofile 65536
...
问题二:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]。
解决此问题,我们可以编辑 /etc/sysctl.conf 文件,在文件最底端添加如下配置:
vm.max_map_count=262144
注意添加完该配置,还需要执行一下 sysctl -p 命令,重新加载一下 sysctl.conf 配置文件。
解决完上述两个问题,再次重启 Elasticsearch,发现上述两个问题都木有了,且启动成功~
4. 访问 Elasticsearch
打开另外一个窗口,请求 Elasticsearch:
[root@153-215 ~]# curl localhost:9200
{
"name" : "_xV7bTf",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "i3whIPX_Qx2zvaJVZKQY1g",
"version" : {
"number" : "6.6.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "a9861f4",
"build_date" : "2019-01-24T11:27:09.439740Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
可以看到,Elasticsearch 返回了一个 json 对象,其中包含当前节点名称、集群名称、集群 uuid、版本信息、宣传语。
Elasticsearch 的基本认识就先写到这里,后续我们再一步步深入了解 Elasticsearch,使用 Elasticsearch。
【原创】《从0开始学Elasticsearch》—初识Elasticsearch的更多相关文章
- 0基础学安卓--初识安卓Activity
知识储备:windows+ Android Studio 等环境安装. 安卓中Activity代表页的意思,也就是☞我们手机上当前的整个界面显示,点击按钮等操作可以跳转到另外一个Activity中. ...
- 原创 | 手摸手带您学会 Elasticsearch 单机、集群、插件安装(图文教程)
欢迎关注笔者的公众号: 小哈学Java, 每日推送 Java 领域干货文章,关注即免费无套路附送 100G 海量学习.面试资源哟!! 个人网站: https://www.exception.site/ ...
- 初识ElasticSearch
概述 Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库. 分布式的 ...
- 初识 ElasticSearch
场景:最近有同事分享了ElasticSearch Inverted Index,所以自己也了解一下基于Lucene的ES. 转载自:http://www.jianshu.com/p/05cff7175 ...
- Docker部署ELK 7.0.1集群之Elasticsearch安装介绍
elk介绍这里不再赘述,本系列教程多以实战干货为主,关于elk工作原理介绍,详情查看官方文档. 一.环境规划 主机名 IP 角色 节点名 centos01 10.10.0.10 es node-10 ...
- 02-springboot整合elasticsearch初识
1.ReactiveElasticsearchOperations 根据springboot官网提供的Elasticsearch操作,除了用rest风格的,还有reactiveElasticS ...
- 01-springboot整合elasticsearch初识
1.elasticsearch 1.es简介 Elasticsearch 是一个分布式.高扩展.高实时的搜索与数据分析引擎.它能很方便的使大量数据具有搜索.分析和探索的能力.充分利用Elas ...
- ElasticSearch和ElasticSearch Head环境搭建和数据模拟
首先elasticsearch-6.0.0\bin目录下运行elasticsearch服务 修改elasticsearch-6.0.0\elasticsearch.yml文件 在文件最后加入下面代码, ...
- 启动elasticsearch的时候报出Exception in thread "main" SettingsException[Failed to load settings from /usr/local/elasticsearch/config/elasticsearch.yml]; nested: MarkedYAMLException[while scanning a simple ke
故障现象: [elasticsearch@tiantianml- ~]$ /usr/local/elasticsearch/bin/elasticsearch Exception in thread ...
随机推荐
- 如何解决XML文件中的警告提示“No grammar constraints (DTD or XML Schema) referenced in the document.”
解决方法:加上 <!DOCTYPE xml> <?xml version="1.0" encoding="UTF-8"?> <!D ...
- Javascript标准事件模型
本文为原创,转载请注明出处: cnzt 文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6676913.html 1. 分类 IE -- 冒泡型 现代 ...
- 小心入怀Yaf
http://www.laruence.com/2015/05/14/3021.html, 鸟哥文章 看了这个文章,更加要小心的对待 Yaf Yar 框架了. 不正确 glib 有一定的了解进来就是深 ...
- Linux-百度云之AccleriderMini使用
打开命令行,然后输入: sudo apt-get install mono-devel 最后安装完成时,运行: 示例:mono xx.exe 实例:mono accleridaMini.exe 最后成 ...
- MySQL基础笔记(五) 视图
一.什么是视图 视图是一个虚拟表.也就是说,视图在外观和行为上都类似于表,但它不需要实际的物理存储,只保存了视图定义(查询语句). 视图由select查询所定义 -- 当创建一个视图时,实际上是在数据 ...
- LoadRunner中存储表格参数------关联数组
主要用到 web_reg_save_param_ex函数("Scope=All",), sprintf( CProdNo,"{CProdNo_%d}",i ); ...
- JavaScript-创建第一个自己的类库
通过上一节面向对象和原型的学习. 我们知道了怎样创建一个类,包含类的私有化属性和方法.公有化属性和方法.静态属性和方法.在这里略微回想一下.首先要创建一个类能够通过1.new object().2.利 ...
- What are some advantages of using Node.js over a Flask API?
https://www.quora.com/What-are-some-advantages-of-using-Node-js-over-a-Flask-API Flask is a Python w ...
- V4L学习
http://blog.csdn.net/wangrunmin/article/details/7764768# http://blog.sina.com.cn/s/blog_a44175a90101 ...
- 一些linux嵌入式资源下载地址
linux内核源代码情景分析 非扫描版 上下册合订版 字清楚 带书签 1575页 pdfhttp://download.csdn.net/source/2002579***************** ...