我花了 2 天时间在 stackoverflow 和许多论坛上进行了很多搜索,但无法使其正常工作并且仍然感到困惑。我会保持简单。
我正在为我的 Laravel(一个 PHP 框架)WEB 应用程序的数据库使用 ElasticSearch 作为后端。
Elasticsearch 部署在 Google 计算引擎实例上,即 UBUNTU 16.0 LTS 服务器。
我想在整个开发过程中从我的笔记本电脑向 elasticsearch 发出 RESTful 请求。 (我知道我可以在本地安装 elasticsearch 但这不是问题)
这意味着当我执行 'curl -X GET localhost:9200'
时,从我的 ubuntu 服务器的 Ssh cli它完美地响应了 elasticsearch 正在运行。 IE
{
"name" : "T1Xfr06",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "NqdJol0ZQ6imGOZxIVvnNA",
"version" : {
"number" : "6.3.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "424e937",
"build_date" : "2018-06-11T23:38:03.357887Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
但我想从我的笔记本电脑上做
curl -X GET
'http://MY_Server's_PUblic_IP:9200'
但它没有响应。这是我试图让它发挥作用的方法。
sudo nano /etc/elasticsearch/elasticsearch.yml
, 我改变了 network.host 像 network.host: 0.0.0.0
然后 sudo systemctl restart elasticsearch
到处都被告知允许流量来自所有 IP 地址,但这仍然无法响应我的笔记本电脑 curl 请求! sudo ufw
status
的任何 ufw 防火墙设置是 Status: inactive
(也就是说每个ip地址都可以连接对吧?)curl -X GET 'http://MY_Server's_PUblic_IP:9200'
是合法的事情。我在我的 UBUNTU 服务器上安装了 nginx,然后做了 curl -X GET 'http://MY_Server's_PUblic_IP:80'
从我的笔记本电脑。它会立即响应! 毕竟当我做
$ curl -X GET 'http://35.237.107.165:9200'
在我的笔记本电脑上,响应是 curl: (7) Failed to connect to 35.237.107.165 port 9200: Timed out
我是一个初学者,我知道 Elasticsearch 中有很多我不知道的东西。我错过了什么?为什么我无法通过
http
访问安装在服务器上的 elasticsearch从我的本地计算机?我根本没有防火墙设置。Update: why there is no network.bind_host parameter in my yml file ?
#---------------------------------- 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: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- 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: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 8080
#
# 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: ["35.237.107.165"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# 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
最佳答案
在 elasticsearch.yml 文件中的“http.port:”行中更改您的端口号(默认情况下,在 elasticsearch.yml 文件中,这些字段已注释,您需要删除“#”以取消注释)。然后重新启动elasticsearch并尝试访问新端口。如果您可以共享 elasticsearch.yml 文件,那就更好了。
正如我所经历的,一旦您更改了您需要启用内存锁定的主机,否则它将引发错误。
检查以下文档的“启用内存锁定”部分以启用内存锁定
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-production-elasticsearch-cluster-on-ubuntu-14-04
谢谢你
关于laravel - 如何从我的本地计算机访问远程 Elasticsearch 服务器(在 Google Compute Engine 上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51047509/