【原创】《从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 ...
随机推荐
- [Bzoj4260]Codechef REBXOR(trie树)
4260: Codechef REBXOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1534 Solved: 669[Submit][Stat ...
- HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和)
HDU 1588 Gauss Fibonacci(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 1588 Gauss Fibonacci 题意: g(i)=k*i+b;i为变量. 给出 ...
- POJ 2545+2591+2247+1338简单水题
[题意简述]:就是有这种一个序列.就拿当p1 = 2,p2 = 3, p3 = 5,来举例.由这三个数为基准组成的序列是: 2,3,4,5,6,8,9,10,12--如今给你这个序列数组的下标,让你求 ...
- hive计算网页停留时长
hive表结构例如以下: create table pv_user_info( session_id string, user_id string, url string, starttime big ...
- android 自己主动拒接后再取消自己主动拒接,该联系人来电界面无图标显示,且点击挂断无反应
1. 设置一个联系人为自己主动拒接 2. 该联系人来电 3. 取消该联系人的自己主动拒接 4. 该联系人来电 Error: 来电界面无头像显示,直接显示黑屏,且点击拒接butt ...
- 怎样在 AutoLayout 中使用 UIScrollView (多个ContentView)
http://codehappily.wordpress.com/2013/11/14/ios-how-to-use-uiscrollview-with-autolayout-pure-autolay ...
- 使用word模板生成pdf文件
使用word模板生成pdf文件 源码:UserWord
- mingw在Dos下升级gnu编译器版本
在dos窗口下输入: mingw-get update mingw-get upgrade gfortran gcc g++ 强烈建议卸载后再安装新版本
- Python爬虫开发【第1篇】【爬虫案例】
案例一:网站模拟登录 # douban.py from selenium import webdriver from selenium.webdriver.common.keys import Key ...
- SQLServer导出导出单表数据
1.SQLServer导出单表数据为TXT文件 数据库--任务--导出数据