阅读 161

Elasticsearch 7.x外部访问(elasticsearch菜鸟教程)

外部访问说明

Elasticsearch单机模式是不允许外部访问的。所以我们需要修改一些配置,将elasticsearch修改为集群模式,比如:cluster.namenode.namenetwork.hostcluster.initial_master_nodes等参数。

环境说明

  • CentOS 7

  • Elasticsearch 7.7.0

  • JDK 8

操作步骤

操作系统配置

操作说明:

  1. 操作系统配置使用root用户进行操作;

  2. 我们可以将elasticsearch的9200端口对外开放,也可以通过nginx将端口代理出来,这里我们选择直接关闭防火墙

具体操作:

  1. 关闭防火墙

    # 关闭防火墙 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配置使用普通用户权限进行操作;

  1. 进入elasticsearch目录,打开config/elasticsearch.yml,对Network模块进行配置,其中192.168.234.129为虚拟机IP:

    # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # 配置为虚拟机IP或者0.0.0.0 network.host: 192.168.234.129 # # Set a custom port for HTTP: # http.port: 9200 # # For more information, consult the network module documentation. # 复制代码

  2. 以上配置完成之后保存退出,启动Elasticsearch

    ./bin/elasticsearch -d 复制代码

  3. 启动过程中还会有报错信息,默认的discovery不适合使用,至少需要配置discovery.seed_hostsdiscovery.seed_providerscluster.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 复制代码

  4. 接下来我们继续对config/elasticsearch.yml进行配置:

    # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: node-1 # # Add custom attributes to the node: # #node.attr.rack: r1 # # --------------------------------- 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"] # # For more information, consult the discovery and cluster formation module documentation. 复制代码

  5. 保存退出,启动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" } 复制代码

总结

  1. Elasticsearch对外访问,需要按照集群的模式进行配置;

  2. 配置文件主要是对NodeNetworkDiscovery三个模块进行配置;

  3. Network模块的network.host也可以配置为0.0.0.0

  4. 出现其他错误,可以参考Elasticsearch 7.x安装部署。


作者:kaysen
链接:https://juejin.cn/post/7028968829820600333


文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐