什么是ElasticSearch
ElasticSearch是基于Apache Lucene的开源搜索引擎
采用Java编写,提供了简单好用的Restful 风格的API。(你不必去了解Lucene那天与搜索引擎原理相关的深层东西)
轻松的横向扩展,可支持PB级别的结构化和非结构化的数据。(即当存储容量不够的时候,可以简单粗暴地家机器解决扩展问题)
ElasticSearch的诞生趣闻
一个待业程序猿和他的厨子老婆的故事。一个没工作的外国程序猿,为了巴结他身为食堂阿姨的老婆,开发一个菜谱搜索引擎,名为compass(指南针)。后来跑偏了,菜谱到现在都没开发好,逐步扩充功能,增加了对分布式的支持,改名为ElasticSearch。
本文出自happybks在oschina的博文:https://my.oschina.net/happyBKs/blog/1790773
ElasticSearch的应用场景
它有以下用途:
(1)海量数据分析引擎
比如每天有海量的日志数据几百TB,当你希望搜索一些指标数据的时候,就可以使用ES的聚合搜索功能,而不必花费大量的人力来设计一个新的系统。节省成本,并有不错的使用效果。
(2)站内搜索引擎
当你需要构建一个站内搜索的时候,不需要花费大量的精力去开发,直接进行一些继承和简单的封装即可使用。
(3)数据仓库
由于ES巨大的存储能力,另外他还可以作为数据仓库使用。存储PB级别的结构化和非结构化的数据。
ElasticSearch的应用案例
英国卫报——实时分析公众对文章的回应
维基百科、Github——用ES实现站内实时搜索。维基百科用ES实现全文搜索、高亮关键字。Github使用ES搜索它们1000多亿行代码。
百度——实施日志监控平台。
谷歌、阿里、腾讯等
ElasticSearch的安装
ES的版本问题
1.X 2.x 5.X 三个版本,之所以出现版本号的跳跃,是因为ElasticSearch属于ELK(ElasticSearch, Logstash, Kibana)之一,是ELK工作站的一员。原先在ES1和2的版本时,Kibana等版本号有自己的版本数字命名,十分混乱。所以为了统一,之后便统一从5开始命名。
版本选择:
ES5开始,支持Lucene6,性能有大幅度提升:
磁盘空间也少了一半。
构建磁盘索引时间相较于过去也少了一半。
查询性能提升了25%左右。
还支持IPv6
安装
Elastic官网有大量的项目提供,包括前面提到的ELK。
这里我们选择Elasticsearch 5.6.8
我们将压缩包拷贝到当前用户所能访问的目录下解压。注意:一般我们解压的应用服务一般发放在/usr/local,像之前的mongo。但是恼人的ES不可以,如果你放在/usr/local,下运行脚本,如果使用
[hadoop@localhost elasticsearch]$ sudo sh ./bin/elasticsearch
来启动。那么会报错:
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME
如果你切换到su,使用root用户来启动,又会报出其他错误。
[root@localhost elasticsearch]# sh bin/elasticsearch
[2018-04-06T05:48:19,921][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught excep tion in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticse arch as root
原因是不能使用root用户来启动。(参考:http://www.easytd.com/yichangjijin/d_16012001263.html)
所以还是把其复制在当前linux非root用户的某个目录下。
推荐:修改目录名称elasticsearch-5.XXX/ 为 elasticsearch/,方便以后升级版本升级。
我们再来看看 elasticsearch/中的文件结构如下:
[hadoop@localhost elasticsearch]$ ll
total 228
drwxr-xr-x. 2 root root 4096 Feb 16 16:48 bin
drwxr-xr-x. 2 root root 72 Feb 16 16:48 config
drwxr-xr-x. 2 root root 4096 Feb 16 16:48 lib
-rw-r--r--. 1 root root 11358 Feb 16 16:43 LICENSE.txt
drwxr-xr-x. 13 root root 4096 Feb 16 16:48 modules
-rw-rw-r--. 1 root root 194187 Feb 16 16:47 NOTICE.txt
drwxr-xr-x. 2 root root 6 Feb 16 16:48 plugins
-rw-r--r--. 1 root root 9490 Feb 16 16:43 README.textile
[hadoop@localhost elasticsearch]$
bin存放ES的脚本命令。
config存放配置文件。如果要修改某个配置,原出厂配置文件一定要备份一份。
lib存放依赖的jar包等。大家可以看到Elasticsearch 5.6.8所对应的Lucene等的版本。
plugin存放第三方插件。
module是存放一些模块的目录。
[hadoop@localhost elasticsearch]$ ll lib/
total 22400
-rw-rw-r--. 1 root root 10105603 Feb 16 16:46 elasticsearch-5.6.8.jar
-rw-r--r--. 1 root root 114165 Dec 6 14:11 HdrHistogram-2.1.9.jar
-rw-r--r--. 1 root root 1140290 Dec 6 14:11 hppc-0.7.1.jar
-rw-r--r--. 1 root root 281203 Dec 8 13:53 jackson-core-2.8.6.jar
-rw-r--r--. 1 root root 50700 Dec 8 13:53 jackson-dataformat-cbor-2.8.6.jar
-rw-r--r--. 1 root root 73897 Dec 8 13:53 jackson-dataformat-smile-2.8.6.jar
-rw-r--r--. 1 root root 40877 Dec 8 13:53 jackson-dataformat-yaml-2.8.6.jar
-rw-rw-r--. 1 root root 7465 Feb 16 16:47 java-version-checker-5.6.8.jar
-rw-r--r--. 1 root root 520701 Dec 6 14:10 jna-4.4.0-1.jar
-rw-r--r--. 1 root root 632037 Dec 6 14:11 joda-time-2.9.5.jar
-rw-r--r--. 1 root root 78074 Dec 6 14:11 jopt-simple-5.0.2.jar
-rw-r--r--. 1 root root 794991 Dec 6 14:11 jts-1.13.jar
-rw-r--r--. 1 root root 61477 Dec 6 14:11 log4j-1.2-api-2.9.1.jar
-rw-r--r--. 1 root root 239856 Dec 6 14:11 log4j-api-2.9.1.jar
-rw-r--r--. 1 root root 1549865 Dec 6 14:11 log4j-core-2.9.1.jar
-rw-r--r--. 1 root root 1513793 Dec 16 08:52 lucene-analyzers-common-6.6.1.jar
-rw-r--r--. 1 root root 87412 Dec 16 08:52 lucene-backward-codecs-6.6.1.jar
-rw-r--r--. 1 root root 2783509 Dec 16 08:52 lucene-core-6.6.1.jar
-rw-r--r--. 1 root root 107684 Dec 16 08:52 lucene-grouping-6.6.1.jar
-rw-r--r--. 1 root root 230593 Dec 16 08:52 lucene-highlighter-6.6.1.jar
-rw-r--r--. 1 root root 146622 Dec 16 08:52 lucene-join-6.6.1.jar
-rw-r--r--. 1 root root 46546 Dec 16 08:52 lucene-memory-6.6.1.jar
-rw-r--r--. 1 root root 165086 Dec 16 08:52 lucene-misc-6.6.1.jar
-rw-r--r--. 1 root root 237894 Dec 16 08:52 lucene-queries-6.6.1.jar
-rw-r--r--. 1 root root 404767 Dec 16 08:52 lucene-queryparser-6.6.1.jar
-rw-r--r--. 1 root root 169069 Dec 16 08:52 lucene-sandbox-6.6.1.jar
-rw-r--r--. 1 root root 236947 Dec 16 08:52 lucene-spatial3d-6.6.1.jar
-rw-r--r--. 1 root root 57023 Dec 16 08:52 lucene-spatial-6.6.1.jar
-rw-r--r--. 1 root root 196556 Dec 16 08:52 lucene-spatial-extras-6.6.1.jar
-rw-r--r--. 1 root root 249326 Dec 16 08:52 lucene-suggest-6.6.1.jar
-rw-rw-r--. 1 root root 28203 Feb 16 16:48 plugin-cli-5.6.8.jar
-rw-r--r--. 1 root root 7465 Dec 6 14:11 securesm-1.2.jar
-rw-r--r--. 1 root root 269295 Dec 8 13:53 snakeyaml-1.15.jar
-rw-r--r--. 1 root root 187537 Dec 6 14:11 spatial4j-0.6.jar
-rw-r--r--. 1 root root 49754 Dec 6 14:11 t-digest-3.0.jar
[hadoop@localhost elasticsearch]$ cd modules/
[hadoop@localhost modules]$ ll
total 32
drwxr-xr-x. 2 root root 75 Feb 16 16:47 aggs-matrix-stats
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 ingest-common
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 lang-expression
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 lang-groovy
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 lang-mustache
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 lang-painless
drwxr-xr-x. 2 root root 69 Feb 16 16:47 parent-join
drwxr-xr-x. 2 root root 68 Feb 16 16:47 percolator
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 reindex
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 transport-netty3
drwxr-xr-x. 2 root root 4096 Feb 16 16:47 transport-netty4
下面我们通过bin中的启动脚本启动ES:
我们可以看到ES中有许多脚本命令文件,后缀名包含了windows、linux等系统脚本文件,我们可以按照自己的服务器定制。因为我这里使用的是centos7
[hadoop@localhost bin]$ ll
total 348
-rwxr-xr-x. 1 root root 8075 Feb 16 16:43 elasticsearch
-rw-r--r--. 1 root root 3343 Feb 16 16:43 elasticsearch.bat
-rw-r--r--. 1 root root 1023 Feb 16 16:43 elasticsearch.in.bat
-rwxr-xr-x. 1 root root 367 Feb 16 16:43 elasticsearch.in.sh
-rwxr-xr-x. 1 root root 2550 Feb 16 16:43 elasticsearch-keystore
-rw-r--r--. 1 root root 743 Feb 16 16:43 elasticsearch-keystore.bat
-rwxr-xr-x. 1 root root 2540 Feb 16 16:43 elasticsearch-plugin
-rw-r--r--. 1 root root 731 Feb 16 16:43 elasticsearch-plugin.bat
-rw-r--r--. 1 root root 11261 Feb 16 16:43 elasticsearch-service.bat
-rw-r--r--. 1 root root 104448 Feb 16 16:43 elasticsearch-service-mgr.exe
-rw-r--r--. 1 root root 103936 Feb 16 16:43 elasticsearch-service-x64.exe
-rw-r--r--. 1 root root 80896 Feb 16 16:43 elasticsearch-service-x86.exe
-rwxr-xr-x. 1 root root 223 Feb 16 16:43 elasticsearch-systemd-pre-exec
-rwxr-xr-x. 1 root root 2514 Feb 16 16:43 elasticsearch-translog
-rw-r--r--. 1 root root 1435 Feb 16 16:43 elasticsearch-translog.bat
[hadoop@localhost bin]$
sh那个有x权限的。
执行过程如下:
注意启动中的starting和started,说明启动好了。
[2018-04-06T06:14:21,012][INFO ][o.e.n.Node ] [] initializing ...
[2018-04-06T06:14:22,887][INFO ][o.e.e.NodeEnvironment ] [4UaWt_1] using [1] data paths, mou nts [[/ (rootfs)]], net usable_space [9.5gb], net total_space [17.6gb], spins? [unknown], types [rootfs]
[2018-04-06T06:14:22,887][INFO ][o.e.e.NodeEnvironment ] [4UaWt_1] heap size [1.9gb], compre ssed ordinary object pointers [true]
[2018-04-06T06:14:22,888][INFO ][o.e.n.Node ] node name [4UaWt_1] derived from no de ID [4UaWt_1oTlWwziNs4SaeQQ]; set [node.name] to override
[2018-04-06T06:14:22,889][INFO ][o.e.n.Node ] version[5.6.8], pid[9269], build[68 8ecce/2018-02-16T16:46:30.010Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/ Java HotSpot(TM) 64-Bit Server VM/1.8.0_161/25.161-b12]
[2018-04-06T06:14:22,889][INFO ][o.e.n.Node ] JVM arguments [-Xms2g, -Xmx2g, -XX: +UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true , -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptim ization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -D log4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.hom e=/home/hadoop/elasticsearch-5.6.8]
[2018-04-06T06:14:27,793][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [aggs-matri x-stats]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [ingest-com mon]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [lang-expre ssion]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [lang-groov y]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [lang-musta che]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [lang-painl ess]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [parent-joi n]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [percolator ]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [reindex]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [transport- netty3]
[2018-04-06T06:14:27,794][INFO ][o.e.p.PluginsService ] [4UaWt_1] loaded module [transport- netty4]
[2018-04-06T06:14:27,795][INFO ][o.e.p.PluginsService ] [4UaWt_1] no plugins loaded
[2018-04-06T06:14:35,322][INFO ][o.e.d.DiscoveryModule ] [4UaWt_1] using discovery type [zen ]
[2018-04-06T06:14:36,552][INFO ][o.e.n.Node ] initialized
[2018-04-06T06:14:36,553][INFO ][o.e.n.Node ] [4UaWt_1] starting ...
[2018-04-06T06:14:37,458][INFO ][o.e.t.TransportService ] [4UaWt_1] publish_address {127.0.0. 1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2018-04-06T06:14:37,472][WARN ][o.e.b.BootstrapChecks ] [4UaWt_1] max file descriptors [409 6] for elasticsearch process is too low, increase to at least [65536]
[2018-04-06T06:14:37,472][WARN ][o.e.b.BootstrapChecks ] [4UaWt_1] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-04-06T06:14:40,600][INFO ][o.e.c.s.ClusterService ] [4UaWt_1] new_master {4UaWt_1}{4UaW t_1oTlWwziNs4SaeQQ}{LHSxSkzXQW-lNRdwFCXM5w}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elect ed-as-master ([0] nodes joined)
[2018-04-06T06:14:40,672][INFO ][o.e.g.GatewayService ] [4UaWt_1] recovered [0] indices int o cluster_state
[2018-04-06T06:14:40,705][INFO ][o.e.h.n.Netty4HttpServerTransport] [4UaWt_1] publish_address { 127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2018-04-06T06:14:40,705][INFO ][o.e.n.Node ] [4UaWt_1] started
这里注意,安装ES特定版本需要配备特定版本的jdk。我这里为了装ES5.6.8还特定把jdk8做了升级。
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/setup.html
由于我虚拟机出现了一些问题,我后来改在本地windows环境下运行了。内存小的小伙伴也可以这样试用。
[2018-04-07T13:27:05,987][INFO ][o.e.n.Node ] [] initializing ...
[2018-04-07T13:27:07,231][INFO ][o.e.e.NodeEnvironment ] [kPuO6XE] using [1] data paths, mounts [[Data (D:)]], net usable_space [255.7gb], net total_space [503.9gb], spins? [unknown], types [NTFS]
[2018-04-07T13:27:07,231][INFO ][o.e.e.NodeEnvironment ] [kPuO6XE] heap size [1.9gb], compressed ordinary object pointers [true]
[2018-04-07T13:27:07,247][INFO ][o.e.n.Node ] node name [kPuO6XE] derived from node ID [kPuO6XELT6mfLKUW_qVaig]; set [node.name] to override
[2018-04-07T13:27:07,247][INFO ][o.e.n.Node ] version[5.6.8], pid[21476], build[688ecce/2018-02-16T16:46:30.010Z], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_112/25.112-b15]
[2018-04-07T13:27:07,247][INFO ][o.e.n.Node ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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, -Delasticsearch, -Des.path.home=D:\IDE\elasticsearch-5.6.8]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [aggs-matrix-stats]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [ingest-common]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [lang-expression]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [lang-groovy]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [lang-mustache]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [lang-painless]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [parent-join]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [percolator]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [reindex]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [transport-netty3]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] loaded module [transport-netty4]
[2018-04-07T13:27:11,465][INFO ][o.e.p.PluginsService ] [kPuO6XE] no plugins loaded
[2018-04-07T13:27:19,682][INFO ][o.e.d.DiscoveryModule ] [kPuO6XE] using discovery type [zen]
[2018-04-07T13:27:20,388][INFO ][o.e.n.Node ] initialized
[2018-04-07T13:27:20,388][INFO ][o.e.n.Node ] [kPuO6XE] starting ...
[2018-04-07T13:27:21,524][INFO ][o.e.t.TransportService ] [kPuO6XE] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}, {[::1]:9300}
[2018-04-07T13:27:24,656][INFO ][o.e.c.s.ClusterService ] [kPuO6XE] new_master {kPuO6XE}{kPuO6XELT6mfLKUW_qVaig}{jl5bmCIhT1WiKt4oVdfV_A}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-04-07T13:27:24,765][INFO ][o.e.g.GatewayService ] [kPuO6XE] recovered [0] indices into cluster_state
[2018-04-07T13:27:25,163][INFO ][o.e.h.n.Netty4HttpServerTransport] [kPuO6XE] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}, {[::1]:9200}
[2018-04-07T13:27:25,163][INFO ][o.e.n.Node ] [kPuO6XE] started
注意看,started,成功启动了ES。
日志里最后几行写明,发布地址为127.0.0.1:9200
我们通过浏览器请求127.0.0.1:9200
Head插件安装
前面我们看到我们访问ES的服务端口9300,返回给我们一个Json。这个信息过于简单,且UI不友好。
我们需要一个像tomcat或者hadoop那样的服务端口管理查询页面。
对于ES来说,需要安装一个Head插件。
Head插件帮我们解决了一下问题:
一个可视化的界面。
实现基本信息的查看。
REST请求的模拟。
数据的基本检索。
如何安装Head插件
我们在github上搜索elasticsearch-head。
大家注意,这是一个JS项目,需要使用Node.js。所以如果你的环境没有安装node.js,请先安装好。
然后,大家把head压缩包解压,从bash进入解压后的head的根目录:
然后通过npm这个node.js的包管理工具,install这个head插件
然后就是等待,npm会将head插件进行安装。
报错不管。
然后我们启动,命令
npm run start
然后我们访问浏览器localhost:9100
这里显示此时9100的head插件显示页面,显示未连接。这是因为ES和head隶属两个独立的进程,需要进行配置,将两者进行关联。
我们打开elasticsearch的根目录下的config目录,修改elasticsearch.yml文件。在最后添加2行:
http.cors.enabled: true
http.cors.allowe-origin: "*"
注意:冒号后面一定要有一个空格,这个在springboot博客中也提过了。
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# 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]"]
#
#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: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"
然后重新启动ES和Head。
这时候我们重新看:
head页面之前的未连接,现在已经变成了green
green代表ES的服务已经正常运行。
同时他还有另外两个状态:
Yellow代表集群的状态不是很好,但仍可以使用。
Red代表集群状态很差,已经出现丢失数据的情况。