外部访问说明
Elasticsearch单机模式是不允许外部访问的。所以我们需要修改一些配置,将elasticsearch修改为集群模式,比如:cluster.name 、node.name 、network.host 、cluster.initial_master_nodes 等参数。
环境说明
- CentOS 7
- Elasticsearch 7.7.0
- JDK 8
操作步骤
操作系统配置
操作说明:
- 操作系统配置使用
root 用户进行操作; - 我们可以将elasticsearch的
9200 端口对外开放,也可以通过nginx 将端口代理出来,这里我们选择直接关闭防火墙。
具体操作:
- 关闭防火墙
systemctl stop firewalld
systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
Nov 08 18:16:16 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 08 18:16:16 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 08 18:16:17 localhost.localdomain firewalld[7656]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in>
Nov 10 22:39:23 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Nov 10 22:39:25 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
Elasticsearch配置
Elasticsearch配置使用普通用户权限进行操作;
-
进入elasticsearch 目录,打开config/elasticsearch.yml ,对Network 模块进行配置,其中192.168.234.129 为虚拟机IP:
network.host: 192.168.234.129
http.port: 9200
-
以上配置完成之后保存退出,启动Elasticsearch : ./bin/elasticsearch -d
-
启动过程中还会有报错信息,默认的discovery 不适合使用,至少需要配置discovery.seed_hosts 、discovery.seed_providers 和cluster.initial_master_nodes 中的一项: [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
-
接下来我们继续对config/elasticsearch.yml 进行配置:
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
-
保存退出,启动Elasticsearch ;在本地浏览器地址栏访问http://192.168.234.129:9200/ : {
name: "node-1",
cluster_name: "elasticsearch",
cluster_uuid: "MZlO8UPyS52AuuCrFwABvQ",
version: {
number: "7.7.0",
build_flavor: "default",
build_type: "tar",
build_hash: "81a1e9eda8e6183f5237786246f6dced26a10eaf",
build_date: "2020-05-12T02:01:37.602180Z",
build_snapshot: false,
lucene_version: "8.5.1",
minimum_wire_compatibility_version: "6.8.0",
minimum_index_compatibility_version: "6.0.0-beta1"
},
tagline: "You Know, for Search"
}
总结
- Elasticsearch对外访问,需要按照集群的模式进行配置;
- 配置文件主要是对
Node 、Network 和Discovery 三个模块进行配置; Network 模块的network.host 也可以配置为0.0.0.0 ;- 出现其他错误,可以参考Elasticsearch 7.x安装部署。
|