Elasticsearch全文检索学习
ElasticSearch官方网址:https://www.elastic.co
ElasticSearch官方网址(中文):https://www.elastic.co/cn/
Elasticsearch 权威指南(中文版文档,在线观看):https://es.xiaoleilu.com/
1、ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。ElasticSearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。
2、Elastic Stack生态(简称ELK Stack,包括 Elasticsearch、Kibana、Beats 和 Logstash)。Elasticsearch是与名为Logstash的数据收集和日志解析引擎以及名为Kibana的分析和可视化平台一起开发的。
a、Elasticsearch 是一个分布式的 RESTful 搜索和分析引擎,可用来集中存储您的数据,以便您对形形色色、规模不一的数据进行搜索、索引和分析。Elasticsearch 是一个基于 JSON 的分布式搜索和分析引擎。
b、Logstash 是一个开源的数据采集引擎,具有实时管道传输功能。Logstash 能够将来自单独数据源的数据动态集中到一起,对这些数据加以标准化并传输到您所选的地方。清理并民主化您的全部数据,将其用于多样化的高级下游分析和可视化用例。Logstash 是动态数据收集管道,拥有可扩展的插件生态系统。
c、Kibana,您可以对自己的 Elasticsearch 进行可视化,还可以在 Elastic Stack 中进行导航,这样您便可以进行各种操作了,从跟踪查询负载,到理解请求如何流经您的整个应用,都能轻松完成。Kibana 可谓 Elastic Stack 的窗户。探索数据并管理堆栈。
d、Beats 是一个面向轻量型采集器的平台,这些采集器可从边缘机器发送数据。Beats 平台集合了多种单一用途数据采集器。它们从成百上千或成千上万台机器和系统向 Logstash 或 Elasticsearch 发送数据。
3、ElasticSearch的下载安装。这里使用elasticsearch-5.4.3.tar.gz,使用CentOS7进行安装。版本进行学习,其实截至目前,Elasticsearch已经发布到Elasticsearch 7.4.0版本了。
将下载好的elasticsearch-5.4.3.tar.gz开始进行安装。
1 [root@slaver4 package]# tar -zxvf elasticsearch-5.4.3.tar.gz -C /home/hadoop/soft/
可以查看其目录结构信息,如下所示:
1 [root@slaver4 soft]# ls 2 elasticsearch-5.4.3 3 [root@slaver4 soft]# cd elasticsearch-5.4.3/ 4 [root@slaver4 elasticsearch-5.4.3]# ls 5 bin config lib LICENSE.txt modules NOTICE.txt plugins README.textile 6 [root@slaver4 elasticsearch-5.4.3]# ll 7 total 224 8 drwxr-xr-x. 2 root root 4096 Oct 9 22:06 bin #启动脚本目录 9 drwxr-xr-x. 2 root root 75 Jun 22 2017 config #配置文件目录 10 drwxr-xr-x. 2 root root 4096 Jun 22 2017 lib #依赖jar包目录 11 -rw-r--r--. 1 root root 11358 Jun 22 2017 LICENSE.txt 12 drwxr-xr-x. 12 root root 217 Jun 22 2017 modules #模块目录 13 -rw-r--r--. 1 root root 194187 Jun 22 2017 NOTICE.txt 14 drwxr-xr-x. 2 root root 6 Jun 22 2017 plugins #第三方插件的目录 15 -rw-r--r--. 1 root root 9548 Jun 22 2017 README.textile 16 [root@slaver4 elasticsearch-5.4.3]#
启动ElasticSearch,如下所示:
启动过程中我的报错了,分析一下错误原因。
1 [root@slaver4 elasticsearch-5.4.3]# sh ./bin/elasticsearch 2 Java HotSpot(TM) Server VM warning: INFO: os::commit_memory(0x6ac00000, 2080374784, 0) failed; error='Cannot allocate memory' (errno=12) 3 # 4 # There is insufficient memory for the Java Runtime Environment to continue. 5 # Native memory allocation (mmap) failed to map 2080374784 bytes for committing reserved memory. 6 # An error report file with more information is saved as: 7 # /home/hadoop/soft/elasticsearch-5.4.3/hs_err_pid11491.log
由于elasticsearch5.x版本默认分配jvm空间大小为2g,修改jvm空间分配。(备注:我的虚拟机给了1G的内存,如果硬件较好,可以多给内存)。
再次启动报如下所示错误:
1 [root@slaver4 elasticsearch-5.4.3]# sh ./bin/elasticsearch 2 [2019-10-09T22:29:26,389][WARN ][o.e.b.Natives ] unable to load JNA native support library, native methods will be disabled. 3 java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/linux-x86/libjnidispatch.so) not found in resource path ([file:/home/hadoop/soft/elasticsearch-5.4.3/lib/elasticsearch-5.4.3.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-core-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-analyzers-common-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-backward-codecs-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-grouping-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-highlighter-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-join-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-memory-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-misc-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-queries-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-queryparser-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-sandbox-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-spatial-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-spatial-extras-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-spatial3d-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/lucene-suggest-6.5.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/securesm-1.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/jopt-simple-5.0.2.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/hppc-0.7.1.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/joda-time-2.9.5.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/snakeyaml-1.15.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/jackson-core-2.8.6.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/jackson-dataformat-smile-2.8.6.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/jackson-dataformat-yaml-2.8.6.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/jackson-dataformat-cbor-2.8.6.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/t-digest-3.0.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/HdrHistogram-2.1.9.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/spatial4j-0.6.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/jts-1.13.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/log4j-api-2.8.2.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/log4j-core-2.8.2.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/log4j-1.2-api-2.8.2.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/jna-4.4.0.jar, file:/home/hadoop/soft/elasticsearch-5.4.3/lib/java-version-checker-5.4.3.jar]) 4 at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:962) ~[jna-4.4.0.jar:4.4.0 (b0)] 5 at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922) ~[jna-4.4.0.jar:4.4.0 (b0)] 6 at com.sun.jna.Native.<clinit>(Native.java:190) ~[jna-4.4.0.jar:4.4.0 (b0)] 7 at java.lang.Class.forName0(Native Method) ~[?:1.8.0_191] 8 at java.lang.Class.forName(Class.java:264) ~[?:1.8.0_191] 9 at org.elasticsearch.bootstrap.Natives.<clinit>(Natives.java:45) [elasticsearch-5.4.3.jar:5.4.3] 10 at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) [elasticsearch-5.4.3.jar:5.4.3] 11 at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) [elasticsearch-5.4.3.jar:5.4.3] 12 at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:350) [elasticsearch-5.4.3.jar:5.4.3] 13 at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) [elasticsearch-5.4.3.jar:5.4.3] 14 at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) [elasticsearch-5.4.3.jar:5.4.3] 15 at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) [elasticsearch-5.4.3.jar:5.4.3] 16 at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) [elasticsearch-5.4.3.jar:5.4.3] 17 at org.elasticsearch.cli.Command.main(Command.java:88) [elasticsearch-5.4.3.jar:5.4.3] 18 at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.4.3.jar:5.4.3] 19 at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.4.3.jar:5.4.3] 20 [2019-10-09T22:29:26,399][WARN ][o.e.b.Natives ] cannot check if running as root because JNA is not available 21 [2019-10-09T22:29:26,399][WARN ][o.e.b.Natives ] cannot install system call filter because JNA is not available 22 [2019-10-09T22:29:26,400][WARN ][o.e.b.Natives ] cannot register console handler because JNA is not available 23 [2019-10-09T22:29:26,401][WARN ][o.e.b.Natives ] cannot getrlimit RLIMIT_NPROC because JNA is not available 24 [2019-10-09T22:29:26,401][WARN ][o.e.b.Natives ] cannot getrlimit RLIMIT_AS beacuse JNA is not available 25 [2019-10-09T22:29:26,764][INFO ][o.e.n.Node ] [] initializing ... 26 [2019-10-09T22:29:26,884][INFO ][o.e.e.NodeEnvironment ] [rYUCm8s] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.9gb], net total_space [17.7gb], spins? [unknown], types [rootfs] 27 [2019-10-09T22:29:26,884][INFO ][o.e.e.NodeEnvironment ] [rYUCm8s] heap size [505.6mb], compressed ordinary object pointers [unknown] 28 [2019-10-09T22:29:26,886][INFO ][o.e.n.Node ] node name [rYUCm8s] derived from node ID [rYUCm8sMRzaXu84zRj3duQ]; set [node.name] to override 29 [2019-10-09T22:29:26,886][INFO ][o.e.n.Node ] version[5.4.3], pid[11871], build[eed30a8/2017-06-22T00:34:03.743Z], OS[Linux/3.10.0-957.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_191/25.191-b12] 30 [2019-10-09T22:29:26,887][INFO ][o.e.n.Node ] JVM arguments [-Xms512m, -Xmx512m, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/home/hadoop/soft/elasticsearch-5.4.3] 31 [2019-10-09T22:29:29,878][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [aggs-matrix-stats] 32 [2019-10-09T22:29:29,878][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [ingest-common] 33 [2019-10-09T22:29:29,878][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-expression] 34 [2019-10-09T22:29:29,878][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-groovy] 35 [2019-10-09T22:29:29,878][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-mustache] 36 [2019-10-09T22:29:29,878][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-painless] 37 [2019-10-09T22:29:29,878][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [percolator] 38 [2019-10-09T22:29:29,879][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [reindex] 39 [2019-10-09T22:29:29,879][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [transport-netty3] 40 [2019-10-09T22:29:29,879][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [transport-netty4] 41 [2019-10-09T22:29:29,879][INFO ][o.e.p.PluginsService ] [rYUCm8s] no plugins loaded 42 [2019-10-09T22:29:34,820][INFO ][o.e.d.DiscoveryModule ] [rYUCm8s] using discovery type [zen] 43 [2019-10-09T22:29:36,045][INFO ][o.e.n.Node ] initialized 44 [2019-10-09T22:29:36,045][INFO ][o.e.n.Node ] [rYUCm8s] starting ... 45 [2019-10-09T22:29:36,285][INFO ][o.e.t.TransportService ] [rYUCm8s] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300} 46 [2019-10-09T22:29:36,341][WARN ][o.e.b.BootstrapChecks ] [rYUCm8s] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] 47 [2019-10-09T22:29:36,341][WARN ][o.e.b.BootstrapChecks ] [rYUCm8s] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 48 [2019-10-09T22:29:36,341][WARN ][o.e.b.BootstrapChecks ] [rYUCm8s] system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk 49 [2019-10-09T22:29:39,434][INFO ][o.e.c.s.ClusterService ] [rYUCm8s] new_master {rYUCm8s}{rYUCm8sMRzaXu84zRj3duQ}{NzmJVJKWRTaua11gn8v4Tw}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) 50 [2019-10-09T22:29:39,542][INFO ][o.e.g.GatewayService ] [rYUCm8s] recovered [0] indices into cluster_state 51 [2019-10-09T22:29:39,559][INFO ][o.e.h.n.Netty4HttpServerTransport] [rYUCm8s] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200} 52 [2019-10-09T22:29:39,585][INFO ][o.e.n.Node ] [rYUCm8s] started
解决方法如下所示:
直接删除或备份Elasticsearch-a.b.c/lib目录下面的jna文件:
然后在/home/hadoop/soft/elasticsearch-5.4.3/lib目录下载这个包,wget http://repo1.maven.org/maven2/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar。
1 [root@slaver4 lib]# mv jna-4.4.0.jar jna-4.4.0.jar.bak 2 [root@slaver4 lib]# wget http://repo1.maven.org/maven2/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar 3 --2019-10-09 22:36:07-- http://repo1.maven.org/maven2/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar 4 Resolving repo1.maven.org (repo1.maven.org)... 151.101.24.209 5 Connecting to repo1.maven.org (repo1.maven.org)|151.101.24.209|:80... connected. 6 HTTP request sent, awaiting response... 200 OK 7 Length: 1091208 (1.0M) [application/java-archive] 8 Saving to: ‘jna-4.4.0.jar’ 9 10 100%[==========================================================================================>] 1,091,208 129KB/s in 7.0s 11 12 2019-10-09 22:36:15 (151 KB/s) - ‘jna-4.4.0.jar’ saved [1091208/1091208] 13 14 [root@slaver4 lib]#
再次启动ElasticSearch,报了如下所示的错误。
1 [root@slaver4 elasticsearch-5.4.3]# sh ./bin/elasticsearch 2 [2019-10-09T22:36:38,150][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main] 3 org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root 4 at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:127) ~[elasticsearch-5.4.3.jar:5.4.3] 5 at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.4.3.jar:5.4.3] 6 at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.4.3.jar:5.4.3] 7 at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.4.3.jar:5.4.3] 8 at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.4.3.jar:5.4.3] 9 at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.4.3.jar:5.4.3] 10 at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.4.3.jar:5.4.3] 11 Caused by: java.lang.RuntimeException: can not run elasticsearch as root 12 at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.4.3.jar:5.4.3] 13 at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.4.3.jar:5.4.3] 14 at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:350) ~[elasticsearch-5.4.3.jar:5.4.3] 15 at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.4.3.jar:5.4.3] 16 ... 6 more 17 [root@slaver4 elasticsearch-5.4.3]#
这应该是ElasticSearch不允许使用root用户进行启动。所以先创建一个用户组elsearch,再创建用户elsearch,再将解压缩后的目录权限赋予这个新用户即可。更改elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch。切换到elsearch用户再启动。
1 [root@slaver4 ~]# groupadd elsearch 2 [root@slaver4 ~]# useradd elsearch -g elsearch 3 [root@slaver4 ~]# passwd elsearch 4 Changing password for user elsearch. 5 New password: 6 BAD PASSWORD: The password contains the user name in some form 7 Retype new password: 8 passwd: all authentication tokens updated successfully. 9 [root@slaver4 ~]# cd /home/hadoop/soft/ 10 [root@slaver4 soft]# ls 11 elasticsearch-5.4.3 12 [root@slaver4 soft]# chown -R elsearch:elsearch elasticsearch-5.4.3/ 13 [root@slaver4 soft]# su elsearch 14 [elsearch@slaver4 soft]$ ls 15 elasticsearch-5.4.3 16 [elsearch@slaver4 soft]$ cd elasticsearch-5.4.3/ 17 [elsearch@slaver4 elasticsearch-5.4.3]$ ls 18 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
再次启动如下所示:
如果启动成功是可以看到started的。127.0.0.1:9200。ElasticSearch默认监听的就是9200端口号的。
1 [elsearch@slaver4 elasticsearch-5.4.3]$ sh ./bin/elasticsearch 2 [2019-10-09T22:44:57,760][INFO ][o.e.n.Node ] [] initializing ... 3 [2019-10-09T22:44:57,938][INFO ][o.e.e.NodeEnvironment ] [rYUCm8s] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.9gb], net total_space [17.7gb], spins? [unknown], types [rootfs] 4 [2019-10-09T22:44:57,938][INFO ][o.e.e.NodeEnvironment ] [rYUCm8s] heap size [505.6mb], compressed ordinary object pointers [unknown] 5 [2019-10-09T22:44:57,944][INFO ][o.e.n.Node ] node name [rYUCm8s] derived from node ID [rYUCm8sMRzaXu84zRj3duQ]; set [node.name] to override 6 [2019-10-09T22:44:57,945][INFO ][o.e.n.Node ] version[5.4.3], pid[12234], build[eed30a8/2017-06-22T00:34:03.743Z], OS[Linux/3.10.0-957.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_191/25.191-b12] 7 [2019-10-09T22:44:57,945][INFO ][o.e.n.Node ] JVM arguments [-Xms512m, -Xmx512m, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/home/hadoop/soft/elasticsearch-5.4.3] 8 [2019-10-09T22:45:01,169][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [aggs-matrix-stats] 9 [2019-10-09T22:45:01,180][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [ingest-common] 10 [2019-10-09T22:45:01,180][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-expression] 11 [2019-10-09T22:45:01,180][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-groovy] 12 [2019-10-09T22:45:01,180][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-mustache] 13 [2019-10-09T22:45:01,181][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-painless] 14 [2019-10-09T22:45:01,181][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [percolator] 15 [2019-10-09T22:45:01,181][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [reindex] 16 [2019-10-09T22:45:01,181][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [transport-netty3] 17 [2019-10-09T22:45:01,181][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [transport-netty4] 18 [2019-10-09T22:45:01,182][INFO ][o.e.p.PluginsService ] [rYUCm8s] no plugins loaded 19 [2019-10-09T22:45:05,825][INFO ][o.e.d.DiscoveryModule ] [rYUCm8s] using discovery type [zen] 20 [2019-10-09T22:45:06,893][INFO ][o.e.n.Node ] initialized 21 [2019-10-09T22:45:06,894][INFO ][o.e.n.Node ] [rYUCm8s] starting ... 22 [2019-10-09T22:45:07,126][INFO ][o.e.t.TransportService ] [rYUCm8s] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300} 23 [2019-10-09T22:45:07,143][WARN ][o.e.b.BootstrapChecks ] [rYUCm8s] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] 24 [2019-10-09T22:45:07,143][WARN ][o.e.b.BootstrapChecks ] [rYUCm8s] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 25 [2019-10-09T22:45:10,263][INFO ][o.e.c.s.ClusterService ] [rYUCm8s] new_master {rYUCm8s}{rYUCm8sMRzaXu84zRj3duQ}{2aE_CPSiTZqCbaR6IU4B2g}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) 26 [2019-10-09T22:45:10,333][INFO ][o.e.g.GatewayService ] [rYUCm8s] recovered [0] indices into cluster_state 27 [2019-10-09T22:45:10,351][INFO ][o.e.h.n.Netty4HttpServerTransport] [rYUCm8s] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200} 28 [2019-10-09T22:45:10,394][INFO ][o.e.n.Node ] [rYUCm8s] started
elasticsearch在后台启动如下所示,可以使用命令查看启动进程信息。
1 [elsearch@slaver4 elasticsearch-5.4.3]$ ./bin/elasticsearch -d 2 [elsearch@slaver4 elasticsearch-5.4.3]$ ps -aux | grep elasticsearch 3 elsearch 12529 83.5 62.9 923084 627032 pts/2 Sl 22:57 0:11 /usr/local/soft/jdk1.8.0_191/bin/java -Xms512m -Xmx512m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/home/hadoop/soft/elasticsearch-5.4.3 -cp /home/hadoop/soft/elasticsearch-5.4.3/lib/* org.elasticsearch.bootstrap.Elasticsearch -d 4 elsearch 12571 0.0 0.0 112708 992 pts/2 R+ 22:57 0:00 grep --color=auto elasticsearch 5 [elsearch@slaver4 elasticsearch-5.4.3]$
使用curl localhost:9200可以看到访问成功了。也说明你的ElasticSearch启动成功了。
1 [elsearch@slaver4 elasticsearch-5.4.3]$ curl localhost:9200 2 { 3 "name" : "rYUCm8s", 4 "cluster_name" : "elasticsearch", 5 "cluster_uuid" : "-VfRdnF3Syad_6QMsa7v3A", 6 "version" : { 7 "number" : "5.4.3", 8 "build_hash" : "eed30a8", 9 "build_date" : "2017-06-22T00:34:03.743Z", 10 "build_snapshot" : false, 11 "lucene_version" : "6.5.1" 12 }, 13 "tagline" : "You Know, for Search" 14 }
外网访问,在防火墙开启9200端口命令。或者直接禁掉防火墙,如果本地学习的话。外网还无法访问的话就需要改下配置文件了。
1 [elsearch@slaver4 elasticsearch-5.4.3]$ ls 2 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile 3 [elsearch@slaver4 elasticsearch-5.4.3]$ cd config/ 4 [elsearch@slaver4 config]$ ls 5 elasticsearch.yml jvm.options log4j2.properties scripts 6 [elsearch@slaver4 config]$ vim elasticsearch.yml
在配置文件,vim elasticsearch.yml,添加如下所示内容即可。
1 network.host: 0.0.0.0
再次启动报了如下所示的错误:
下面使用红色标记起来的就是错误。
1 [elsearch@slaver4 bin]$ ./elasticsearch 2 [2019-10-10T10:14:14,226][INFO ][o.e.n.Node ] [] initializing ... 3 [2019-10-10T10:14:14,371][INFO ][o.e.e.NodeEnvironment ] [rYUCm8s] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [10.9gb], net total_space [17.7gb], spins? [unknown], types [rootfs] 4 [2019-10-10T10:14:14,372][INFO ][o.e.e.NodeEnvironment ] [rYUCm8s] heap size [505.6mb], compressed ordinary object pointers [unknown] 5 [2019-10-10T10:14:14,373][INFO ][o.e.n.Node ] node name [rYUCm8s] derived from node ID [rYUCm8sMRzaXu84zRj3duQ]; set [node.name] to override 6 [2019-10-10T10:14:14,373][INFO ][o.e.n.Node ] version[5.4.3], pid[14069], build[eed30a8/2017-06-22T00:34:03.743Z], OS[Linux/3.10.0-957.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_191/25.191-b12] 7 [2019-10-10T10:14:14,374][INFO ][o.e.n.Node ] JVM arguments [-Xms512m, -Xmx512m, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/home/hadoop/soft/elasticsearch-5.4.3] 8 [2019-10-10T10:14:17,064][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [aggs-matrix-stats] 9 [2019-10-10T10:14:17,064][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [ingest-common] 10 [2019-10-10T10:14:17,065][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-expression] 11 [2019-10-10T10:14:17,065][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-groovy] 12 [2019-10-10T10:14:17,065][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-mustache] 13 [2019-10-10T10:14:17,065][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [lang-painless] 14 [2019-10-10T10:14:17,065][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [percolator] 15 [2019-10-10T10:14:17,066][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [reindex] 16 [2019-10-10T10:14:17,066][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [transport-netty3] 17 [2019-10-10T10:14:17,066][INFO ][o.e.p.PluginsService ] [rYUCm8s] loaded module [transport-netty4] 18 [2019-10-10T10:14:17,067][INFO ][o.e.p.PluginsService ] [rYUCm8s] no plugins loaded 19 [2019-10-10T10:14:21,970][INFO ][o.e.d.DiscoveryModule ] [rYUCm8s] using discovery type [zen] 20 [2019-10-10T10:14:23,169][INFO ][o.e.n.Node ] initialized 21 [2019-10-10T10:14:23,169][INFO ][o.e.n.Node ] [rYUCm8s] starting ... 22 [2019-10-10T10:14:23,666][INFO ][o.e.t.TransportService ] [rYUCm8s] publish_address {192.168.110.133:9300}, bound_addresses {[::]:9300} 23 [2019-10-10T10:14:23,684][INFO ][o.e.b.BootstrapChecks ] [rYUCm8s] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks 24 ERROR: [2] bootstrap checks failed 25 [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] 26 [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 27 [2019-10-10T10:14:23,697][INFO ][o.e.n.Node ] [rYUCm8s] stopping ... 28 [2019-10-10T10:14:23,736][INFO ][o.e.n.Node ] [rYUCm8s] stopped 29 [2019-10-10T10:14:23,736][INFO ][o.e.n.Node ] [rYUCm8s] closing ... 30 [2019-10-10T10:14:23,765][INFO ][o.e.n.Node ] [rYUCm8s] closed 31 [elsearch@slaver4 bin]$
上面的两个错误解决方法如下所示:
错误一,[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]。解决方法如下所示:
错误原因,每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量。
注意,切记,如果按照此方法修改,必须重启你的虚拟机,而且是root用户修改的配置文件,不然你解决完报的这两个错误,再次启动elasticsearch还是会报错误一,但是不会报错误二,所以重启虚拟机以后解决这两个错误。
1 [root@slaver4 ~]# vim /etc/security/limits.conf
添加如下所示内容:
1 * soft nofile 65536 2 * 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生效。
1 [root@slaver4 ~]# vim /etc/sysctl.conf 2 [root@slaver4 ~]# sysctl -p 3 vm.max_map_count = 262144 4 [root@slaver4 ~]#
添加内容如下所示:
1 vm.max_map_count=262144
操作如下所示:
解决完上述两个错误以后,使用浏览器访问也出现了正常,如下所示:
使用命令行,访问出现如下所示表示正常启动elasticsearch。
如何停止你的elasticsearch呢,如下所示:
方式一,如果是前台启动方式,即进入/home/hadoop/soft/elasticsearch-5.4.3/bin/目录直接使用./elasticsearch启动,直接ctrl+c就可以退出了elasticsearch。
方式二,如果是后台启动elasticsearch的话。./elasticsearch -d。这种后台方式启动。使用jps命令查看进程号,然后使用kill -9 进程号。直接强制杀死的命令。
4、ElasticSearch的实用插件Head的安装。
通过浏览器访问http://192.168.110.133:9200/。返回的是json格式的数据,显示效果不是很友好的,通过Head插件提供的友好的web界面,解决了界面显示的问题。同时Head插件还实现了基本信息的查看,rest请求的模拟,以及数据的基本检索。
使用命令下载elasticsearch head插件,wget https://github.com/mobz/elasticsearch-head/archive/master.zip。
或者使用这种方式安装elasticsearch-head插件。
1 [elsearch@slaver4 package]$ yum install –y git 2 [elsearch@slaver4 package]$ git clone https://github.com/mobz/elasticsearch-head.git
我是使用wget下载zip包,直接解压缩操作,安装的elasticearch-head插件。
1 [root@slaver4 ~]# cd /home/hadoop/package/ 2 [root@slaver4 package]# ls 3 elasticsearch-5.4.3.tar.gz erlang-18.3-1.el7.centos.x86_64.rpm haproxy-1.6.5.tar.gz phantomjs-2.1.1-linux-x86_64.tar.bz2 rabbitmq-server-3.6.5-1.noarch.rpm 4 elasticsearch-analysis-ik-5.4.3.zip es-sql-site-standalone.zip keepalived-1.2.18.tar.gz rabbitmq_delayed_message_exchange-0.0.1.ez socat-1.7.3.2-1.1.el7.x86_64.rpm 5 [root@slaver4 package]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip 6 --2019-10-10 14:49:21-- https://github.com/mobz/elasticsearch-head/archive/master.zip 7 Resolving github.com (github.com)... 13.229.188.59 8 Connecting to github.com (github.com)|13.229.188.59|:443... connected. 9 HTTP request sent, awaiting response... 302 Found 10 Location: https://codeload.github.com/mobz/elasticsearch-head/zip/master [following] 11 --2019-10-10 14:49:22-- https://codeload.github.com/mobz/elasticsearch-head/zip/master 12 Resolving codeload.github.com (codeload.github.com)... 13.250.162.133 13 Connecting to codeload.github.com (codeload.github.com)|13.250.162.133|:443... connected. 14 HTTP request sent, awaiting response... 200 OK 15 Length: 1353444 (1.3M) [application/zip] 16 Saving to: ‘master.zip’ 17 18 100%[=======================================================================================================================================================================>] 1,353,444 139KB/s in 10s 19 20 2019-10-10 14:49:34 (126 KB/s) - ‘master.zip’ saved [1353444/1353444] 21 22 [root@slaver4 package]# ls 23 elasticsearch-5.4.3.tar.gz es-sql-site-standalone.zip master.zip rabbitmq-server-3.6.5-1.noarch.rpm 24 elasticsearch-analysis-ik-5.4.3.zip haproxy-1.6.5.tar.gz phantomjs-2.1.1-linux-x86_64.tar.bz2 socat-1.7.3.2-1.1.el7.x86_64.rpm 25 erlang-18.3-1.el7.centos.x86_64.rpm keepalived-1.2.18.tar.gz rabbitmq_delayed_message_exchange-0.0.1.ez 26 [root@slaver4 package]#
下载好进行解压缩操作,如下所示:
1 [root@slaver4 package]# unzip master.zip
由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。
下载安装node,wget https://nodejs.org/dist/latest-v8.x/node-v8.16.2-linux-x64.tar.xz,下载完毕进行解压缩操作。
1 [root@slaver4 package]# wget https://nodejs.org/dist/latest-v8.x/node-v8.16.2-linux-x64.tar.xz 2 [root@slaver4 package]# ls 3 elasticsearch-5.4.3.tar.gz es-sql-site-standalone.zip master.zip rabbitmq_delayed_message_exchange-0.0.1.ez 4 elasticsearch-analysis-ik-5.4.3.zip haproxy-1.6.5.tar.gz node-v8.16.2-linux-x64.tar.xz rabbitmq-server-3.6.5-1.noarch.rpm 5 erlang-18.3-1.el7.centos.x86_64.rpm keepalived-1.2.18.tar.gz phantomjs-2.1.1-linux-x86_64.tar.bz2 socat-1.7.3.2-1.1.el7.x86_64.rpm 6 [root@slaver4 package]# 7 [root@slaver4 package]# tar -zxvf node-v8.16.2-linux-x64.tar.xz -C /home/hadoop/soft/ 8 [root@slaver4 package]# cd ../soft/ 9 [root@slaver4 soft]# ls 10 elasticsearch-5.4.3 elasticsearch-head-master node-v8.16.2-linux-x64 11 [root@slaver4 soft]#
解压缩完毕,进行配置环境变量。添加完Node环境变量以后刷新配置文件source /etc/profile。
1 [root@slaver4 soft]# vim /etc/profile 2 [root@slaver4 soft]# source /etc/profile
配置如下所示:
1 export NODE_HOME=/home/hadoop/soft/node-v8.16.2-linux-x64 2 export PATH=$PATH:$NODE_HOME/bin
然后进行查看Node版本验证。如下所示:
注意:Node的版本必须大于等于node6.0版本。
1 [root@slaver4 soft]# node -v 2 v8.16.2 3 [root@slaver4 soft]# npm -v 4 6.4.1 5 [root@slaver4 soft]#
执行一下npm,npm是Node的一个包安装工具。
1 [root@slaver4 soft]# ls 2 elasticsearch-5.4.3 elasticsearch-head-master node-v8.16.2-linux-x64 3 [root@slaver4 soft]# cd elasticsearch-head-master/ 4 [root@slaver4 elasticsearch-head-master]# ls 5 crx elasticsearch-head.sublime-project index.html plugin-descriptor.properties _site 6 Dockerfile Gruntfile.js LICENCE proxy src 7 Dockerfile-alpine grunt_fileSets.js package.json README.textile test 8 [root@slaver4 elasticsearch-head-master]# np 9 npm nproc npx 10 [root@slaver4 elasticsearch-head-master]# npm install
执行npm install报了如下所示的错误,真是坎坷万千啊。
1 [root@slaver4 elasticsearch-head-master]# npm install 2 npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen) 3 npm WARN deprecated http2@3.3.7: Use the built-in module in node 9.0.0 or newer, instead 4 npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated 5 npm WARN deprecated json3@3.3.2: Please use the native JSON object instead of JSON 3 6 npm WARN deprecated json3@3.2.6: Please use the native JSON object instead of JSON 3 7 8 > phantomjs-prebuilt@2.1.16 install /home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt 9 > node install.js 10 11 PhantomJS not found on PATH 12 Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2 13 Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 14 Receiving... 15 [========================================] 99% 16 Received 22866K total. 17 Extracting tar contents (via spawned process) 18 Removing /home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom 19 Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1570691935036/phantomjs-2.1.1-linux-x86_64 -> /home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom 20 Phantom installation failed { Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1570691935036/phantomjs-2.1.1-linux-x86_64' -> '/home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom' 21 errno: -13, 22 code: 'EACCES', 23 syscall: 'link', 24 path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1570691935036/phantomjs-2.1.1-linux-x86_64', 25 dest: '/home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1570691935036/phantomjs-2.1.1-linux-x86_64' -> '/home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom' 26 npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression 27 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents): 28 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) 29 30 npm ERR! code ELIFECYCLE 31 npm ERR! errno 1 32 npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js` 33 npm ERR! Exit status 1 34 npm ERR! 35 npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script. 36 npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 37 38 npm ERR! A complete log of this run can be found in: 39 npm ERR! /root/.npm/_logs/2019-10-10T07_18_58_885Z-debug.log
应该是缺少类库,使用如下所示的命令npm install phantomjs-prebuilt –save进行安装。
1 [elsearch@slaver4 elasticsearch-head-master]$ npm install phantomjs-prebuilt -save 2 npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated 3 4 > phantomjs-prebuilt@2.1.16 install /home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt 5 > node install.js 6 7 PhantomJS not found on PATH 8 Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 9 Verified checksum of previously downloaded file 10 Extracting tar contents (via spawned process) 11 Removing /home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom 12 Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1570692541363/phantomjs-2.1.1-linux-x86_64 -> /home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom 13 Writing location.js file 14 Done. Phantomjs binary available at /home/hadoop/soft/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs 15 npm notice created a lockfile as package-lock.json. You should commit this file. 16 npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression 17 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents): 18 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) 19 20 + phantomjs-prebuilt@2.1.16 21 added 62 packages from 64 contributors, removed 4 packages and audited 1734 packages in 137.541s 22 found 37 vulnerabilities (18 low, 2 moderate, 17 high) 23 run `npm audit fix` to fix them, or `npm audit` for details 24 [elsearch@slaver4 elasticsearch-head-master]$
安装完成以后,运行一下,使用如下命令npm run start,如下所示:
1 [elsearch@slaver4 elasticsearch-head-master]$ npm run start 2 3 > elasticsearch-head@0.0.0 start /home/hadoop/soft/elasticsearch-head-master 4 > grunt server 5 6 >> Local Npm module "grunt-contrib-jasmine" not found. Is it installed? 7 8 Running "connect:server" (connect) task 9 Waiting forever... 10 Started connect web server on http://localhost:9100
可以看到head插件默认占用9100端口,浏览器访问http://192.168.110.133:9100/,如下所示。即可显示head插件界面。
由于elasticsearch和elasticsearch-head插件是属于两个不同的进程的,他们之间的访问是存在跨域问题的。
1 [root@slaver4 ~]# cd /home/hadoop/soft/elasticsearch- 2 -bash: cd: /home/hadoop/soft/elasticsearch-: No such file or directory 3 [root@slaver4 ~]# cd /home/hadoop/soft/elasticsearch- 4 elasticsearch-5.4.3/ elasticsearch-head-master/ 5 [root@slaver4 ~]# cd /home/hadoop/soft/elasticsearch-5.4.3/ 6 [root@slaver4 elasticsearch-5.4.3]# ls 7 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile 8 [root@slaver4 elasticsearch-5.4.3]# vim config/elasticsearch.yml
在/home/hadoop/soft/elasticsearch-5.4.3/config/elasticsearch.yml配置文件中添加如下所示配置。解决跨域访问的问题、支持所有的域名。
1 # 是否支持跨域 2 http.cors.enabled: true 3 # 4 # *表示支持所有域名 5 http.cors.allow-origin: "*"
此时,后台启动elasticsearch(切记,使用自己创建的用户,不能使用root用户哦,./elasticsearch -d),启动elasticsearch-head插件(切记,使用自己创建的用户,npm run start)。
通过head插件连接elasticsearch服务。输入elasticsearch服务地址http://192.168.110.133:9200/,点击连接,右边显示黄色信息说明连接成功,至此elasticsearch-head插件安装成功。
注意:green绿色代表集群健康,正常运行。yellow黄色代表集群健康不是很好,但是集群可以使用。red红色代表集群状态很差,搜索可以使用,但是可能出现丢失数据的情况。
安装grunt,可以使用后台启动elasticsearch-head插件,操作如下所示:
安装grunt,如下所示:
[elsearch@slaver4 elasticsearch-head-master]$ cd elasticsearch-head-master
[elsearch@slaver4 elasticsearch-head-master]$ npm install -g grunt –registry=https://registry.npm.taobao.org
在elasticsearch-head目录下node_modules/grunt下如果没有grunt二进制程序,需要执行:
[elsearch@slaver4 elasticsearch-head-master]$ cd elasticsearch-head-master
[elsearch@slaver4 elasticsearch-head-master]$ npm install grunt –save
1 [elsearch@slaver4 soft]$ cd elasticsearch-head-master/ 2 [elsearch@slaver4 elasticsearch-head-master]$ ls 3 crx Dockerfile-alpine Gruntfile.js index.html node_modules package-lock.json proxy _site test 4 Dockerfile elasticsearch-head.sublime-project grunt_fileSets.js LICENCE package.json plugin-descriptor.properties README.textile src 5 [elsearch@slaver4 elasticsearch-head-master]$ clear 6 [elsearch@slaver4 elasticsearch-head-master]$ ls 7 crx Dockerfile-alpine Gruntfile.js index.html node_modules package-lock.json proxy _site test 8 Dockerfile elasticsearch-head.sublime-project grunt_fileSets.js LICENCE package.json plugin-descriptor.properties README.textile src 9 [elsearch@slaver4 elasticsearch-head-master]$ npm install -g grunt --registry=https://registry.npm.taobao.org 10 /home/hadoop/soft/node-v8.16.2-linux-x64/bin/grunt -> /home/hadoop/soft/node-v8.16.2-linux-x64/lib/node_modules/grunt/bin/grunt 11 + grunt@1.0.4 12 added 97 packages from 63 contributors in 10.985s 13 [elsearch@slaver4 elasticsearch-head-master]$ npm install grunt --save 14 npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen) 15 npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression 16 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents): 17 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) 18 19 + grunt@1.0.1 20 updated 1 package and audited 1734 packages in 88.081s 21 found 37 vulnerabilities (18 low, 2 moderate, 17 high) 22 run `npm audit fix` to fix them, or `npm audit` for details
下面的配置可以修改也可以不修改的,我这里修改了。
修改elasticsearch-head下Gruntfile.js文件,默认监听在127.0.0.1下9200端口:
添加hostname: ‘192.168.110.133‘,这个配置。
1 connect: { 2 server: { 3 options: { 4 hostname: '192.168.110.133', 5 port: 9100, 6 base: '.', 7 keepalive: true 8 } 9 } 10 }
修改 _site/app.js,修改http://localhost:9200字段到本机ES端口与IP:
在命令模式,即可以使用:/localhost搜索找到localhost,然后修改如下配置。显示行号,也是在命令模式,使用:set nu既可以显示行号。
1 将此配置 2 "http://localhost:9200"; 3 4 修改为了 5 "http://192.168.110.133:9200";
Vim的三种工作模式。
后台启动elasticsearch-head插件,如下所示:
在/home/hadoop/soft/elasticsearch-head-master/node_modules/grunt/bin目录下面,使用此命令后台启动。./grunt server &
1 [elsearch@slaver4 elasticsearch-head-master]$ ls 2 crx elasticsearch-head.sublime-project index.html package.json proxy src 3 Dockerfile Gruntfile.js LICENCE package-lock.json README.textile test 4 Dockerfile-alpine grunt_fileSets.js node_modules plugin-descriptor.properties _site 5 [elsearch@slaver4 elasticsearch-head-master]$ cd node_modules/gr 6 graceful-fs/ grunt-contrib-concat/ grunt-contrib-watch/ grunt-legacy-log/ 7 grunt/ grunt-contrib-connect/ grunt-karma/ grunt-legacy-log-utils/ 8 grunt-contrib-clean/ grunt-contrib-copy/ grunt-known-options/ grunt-legacy-util/ 9 [elsearch@slaver4 elasticsearch-head-master]$ cd node_modules/grunt/bin/ 10 [elsearch@slaver4 bin]$ ls 11 grunt 12 [elsearch@slaver4 bin]$ ./grunt server & 13 [1] 10709 14 [elsearch@slaver4 bin]$ >> Local Npm module "grunt-contrib-jasmine" not found. Is it installed? 15 16 Running "connect:server" (connect) task 17 Waiting forever... 18 Started connect web server on http://192.168.110.133:9100
作者:别先生
博客园:https://www.cnblogs.com/biehongli/
如果您想及时得到个人撰写文章以及著作的消息推送,可以扫描上方二维码,关注个人公众号哦。