在并行 Ubuntu 运行 上为 Elasticsearch 设置网络访问
Setup network access for Elasticsearch on Ubuntu running on parallels
我有一个 ubuntu 服务器 运行ning 版本 20.04 的实例安装在并行的 Mac 上,但是我无法从我网络上的其他设备访问它,只能从ubuntu.
的实例
lsb_release -a
给出以下结果
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
我已经使用说明 here
从 APT 存储库安装了 Elasticsearch 版本 7.6.2
我可以 运行 curl -X GET 'http://localhost:9200'
在 ubuntu 上得到以下输出
{
"name" : "dev",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "u4Xx8JDyTdaWv_HsYK6xXA",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
如果我 运行 hostname -I
我得到 10.211.55.11 fdb2:2c26:f4e4:0:21c:42ff:fee9:e2c5
这是 ubuntu 实例的 IP 地址。
然而,当我从 Mac 运行 curl -X GET 'http://10.211.55.11:9200'
中得到以下结果时 curl: (7) Failed to connect to 10.211.55.11 port 9200: Connection refused
如何从我网络上的其他设备访问我的 Elasticsearch 实例?
sudo ufw status
给我以下规则
Status: active
To Action From
-- ------ ----
9200 ALLOW Anywhere
9200 (v6) ALLOW Anywhere (v6)
/etc/elasticsearch/elasticsearch.yml
包含以下内容
# ======================== 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: /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: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation 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
添加network.host:0.0.0.0
将以上行添加到 elasticsearch.yml 文件后,出现以下错误
Job for elasticsearch.service failed because the control process exited with error code.
See "systemctl status elasticsearch.service" and "journalctl -xe" for details.
运行ning systemctl status elasticsearch.service
给我以下错误信息
● elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-05-01 14:52:23 UTC; 59s ago
Docs: http://www.elastic.co
Process: 7086 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=78)
Main PID: 7086 (code=exited, status=78)
May 01 14:52:03 dev systemd[1]: Starting Elasticsearch...
May 01 14:52:03 dev elasticsearch[7086]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
May 01 14:52:23 dev elasticsearch[7086]: ERROR: [1] bootstrap checks failed
May 01 14:52:23 dev elasticsearch[7086]: [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nod>
May 01 14:52:23 dev elasticsearch[7086]: ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log
May 01 14:52:23 dev systemd[1]: elasticsearch.service: Main process exited, code=exited, status=78/CONFIG
May 01 14:52:23 dev systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
May 01 14:52:23 dev systemd[1]: Failed to start Elasticsearch.
/var/log/elasticsearch/elasticsearch.log
包含以下错误日志
[2020-05-01T14:52:22,378][INFO ][o.e.n.Node ] [dev] starting ...
[2020-05-01T14:52:22,740][INFO ][o.e.t.TransportService ] [dev] publish_address {10.211.55.11:9300}, bound_addresses {[::]:9300}
[2020-05-01T14:52:23,333][INFO ][o.e.b.BootstrapChecks ] [dev] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2020-05-01T14:52:23,355][ERROR][o.e.b.Bootstrap ] [dev] node validation exception
[1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2020-05-01T14:52:23,361][INFO ][o.e.n.Node ] [dev] stopping ...
[2020-05-01T14:52:23,386][INFO ][o.e.n.Node ] [dev] stopped
[2020-05-01T14:52:23,387][INFO ][o.e.n.Node ] [dev] closing ...
[2020-05-01T14:52:23,435][INFO ][o.e.n.Node ] [dev] closed
[2020-05-01T14:52:23,436][INFO ][o.e.x.m.p.NativeController] [dev] Native controller process has stopped - no new native processes can be started
所以有几个问题,按照以下步骤应该可以解决问题:
- 添加了
network.host:0.0.0.0
,允许在非环回地址(即本地主机或 127.0.0.1)上公开端口,以便 LAN 上的其他系统可以连接到其 IP 地址。
- 添加了
discovery.type: single-node
配置以避免生产 bootstrap 检查。
我有一个 ubuntu 服务器 运行ning 版本 20.04 的实例安装在并行的 Mac 上,但是我无法从我网络上的其他设备访问它,只能从ubuntu.
的实例lsb_release -a
给出以下结果
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
我已经使用说明 here
从 APT 存储库安装了 Elasticsearch 版本 7.6.2我可以 运行 curl -X GET 'http://localhost:9200'
在 ubuntu 上得到以下输出
{
"name" : "dev",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "u4Xx8JDyTdaWv_HsYK6xXA",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
如果我 运行 hostname -I
我得到 10.211.55.11 fdb2:2c26:f4e4:0:21c:42ff:fee9:e2c5
这是 ubuntu 实例的 IP 地址。
然而,当我从 Mac 运行 curl -X GET 'http://10.211.55.11:9200'
中得到以下结果时 curl: (7) Failed to connect to 10.211.55.11 port 9200: Connection refused
如何从我网络上的其他设备访问我的 Elasticsearch 实例?
sudo ufw status
给我以下规则
Status: active
To Action From
-- ------ ----
9200 ALLOW Anywhere
9200 (v6) ALLOW Anywhere (v6)
/etc/elasticsearch/elasticsearch.yml
包含以下内容
# ======================== 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: /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: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation 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
添加network.host:0.0.0.0
将以上行添加到 elasticsearch.yml 文件后,出现以下错误
Job for elasticsearch.service failed because the control process exited with error code.
See "systemctl status elasticsearch.service" and "journalctl -xe" for details.
运行ning systemctl status elasticsearch.service
给我以下错误信息
● elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-05-01 14:52:23 UTC; 59s ago
Docs: http://www.elastic.co
Process: 7086 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=78)
Main PID: 7086 (code=exited, status=78)
May 01 14:52:03 dev systemd[1]: Starting Elasticsearch...
May 01 14:52:03 dev elasticsearch[7086]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
May 01 14:52:23 dev elasticsearch[7086]: ERROR: [1] bootstrap checks failed
May 01 14:52:23 dev elasticsearch[7086]: [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nod>
May 01 14:52:23 dev elasticsearch[7086]: ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log
May 01 14:52:23 dev systemd[1]: elasticsearch.service: Main process exited, code=exited, status=78/CONFIG
May 01 14:52:23 dev systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
May 01 14:52:23 dev systemd[1]: Failed to start Elasticsearch.
/var/log/elasticsearch/elasticsearch.log
包含以下错误日志
[2020-05-01T14:52:22,378][INFO ][o.e.n.Node ] [dev] starting ...
[2020-05-01T14:52:22,740][INFO ][o.e.t.TransportService ] [dev] publish_address {10.211.55.11:9300}, bound_addresses {[::]:9300}
[2020-05-01T14:52:23,333][INFO ][o.e.b.BootstrapChecks ] [dev] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2020-05-01T14:52:23,355][ERROR][o.e.b.Bootstrap ] [dev] node validation exception
[1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2020-05-01T14:52:23,361][INFO ][o.e.n.Node ] [dev] stopping ...
[2020-05-01T14:52:23,386][INFO ][o.e.n.Node ] [dev] stopped
[2020-05-01T14:52:23,387][INFO ][o.e.n.Node ] [dev] closing ...
[2020-05-01T14:52:23,435][INFO ][o.e.n.Node ] [dev] closed
[2020-05-01T14:52:23,436][INFO ][o.e.x.m.p.NativeController] [dev] Native controller process has stopped - no new native processes can be started
所以有几个问题,按照以下步骤应该可以解决问题:
- 添加了
network.host:0.0.0.0
,允许在非环回地址(即本地主机或 127.0.0.1)上公开端口,以便 LAN 上的其他系统可以连接到其 IP 地址。 - 添加了
discovery.type: single-node
配置以避免生产 bootstrap 检查。