ElasticSearch(下文简称ES)是一个基于Lucene的搜索服务器,它提供了一个分布式多用户能力的全文搜索引擎。Kibana则是一款开源的分析与可视化平台,可以用来与ES进行交互,通过可视化界面来查看和操作ES中的数据。默认情况下这两个软件只允许通过本机localhost访问。本文分享如何通过设置使得这两者可以被同一网络中的其他机器访问。

我们先看一下在使用默认设置时,当我们尝试通过IP地址去访问ES的服务(在9200端口)时,会得到如下结果
$ curl 10.0.0.141:9200 curl: (7) Failed to connect to 10.0.0.141 port 9200:
Connection refused
从提示结果可以看到,ES服务拒绝了我们的访问,这是因为ES服务默认监听的主机是localhost,如果希望通过IP进行访问,需要设置其监听0.0.0.0
。这个地址表示的是所有未知的主机和目的网络的集合。对于Kibana也是一样的道理,因此以下只阐述ES的配置方法

具体来说,分为两步走,首先要找到ES的配置文件,在不同的系统中配置文件存放的路径也不同。对于Mac系统来说,如果是通过brew
安装的ES,那么可以通过以下命令来查看配置文件的位置
$ brew info elasticsearch elasticsearch: stable 6.2.3, HEAD Distributed search
& analytics engine https://www.elastic.co/products/elasticsearch
/usr/local/Cellar/elasticsearch/5.6.3 (217 files, 124MB) * Built from source on
2017-11-07 at 16:32:00 From:
https://github.com/Homebrew/homebrew-core/blob/master/Formula/elasticsearch.rb
==> Requirements Required: java =1.8 ✔ ==> Options --HEAD Install HEAD version
==> Caveats Data: /usr/local/var/lib/elasticsearch/elasticsearch_gao-yimei/
Logs: /usr/local/var/log/elasticsearch/elasticsearch_gao-yimei.log Plugins:
/usr/local/var/elasticsearch/plugins/ Config: /usr/local/etc/elasticsearch/ To
have launchd start elasticsearch now and restart at login: brew services start
elasticsearch Or,if you don't want/need a background service you can just run:
elasticsearch
结果中的Config标识了配置文件所在的目录。进入该目录,可以看到一个名为elasticsearch.yml的配置文件,通过less命令查看并搜索host
可以找到一个network.host的配置参数,我们只需要将该参数前的#号去掉,并将该值设置为0.0.0.0并保存即可。注意第一个0
与参数名之间需要有一个空格,这是配置文件的格式要求

修改完成后,还需要一步,那就是重新启动ES服务器,对于Mac用户,可以通过以下命令重启服务:
$ brew services restart elasticsearch Stopping `elasticsearch`... (might take a
while) ==> Successfully stopped `elasticsearch` (label:
homebrew.mxcl.elasticsearch) ==> Successfully started `elasticsearch` (label:
homebrew.mxcl.elasticsearch)
等待两三分钟后,服务即可稳定,此时再通过IP访问ES服务,就可以正常使用


值得注意的是,当我们这样设置以后,同一网络中的所有设备都能随意地访问到本机的ES服务,包括所有存储在ES中的数据,这是一个比较危险的操作,因此请谨慎使用。另外,对于其他很多不同的软件,也存在这种默认情况下不允许通过IP访问的问题,设置的方式和ES大同小异,可以参考上述的操作流程。

友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信