栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Elasticsearch 7.x外部访问

Elasticsearch 7.x外部访问

外部访问说明

Elasticsearch单机模式是不允许外部访问的。所以我们需要修改一些配置,将elasticsearch修改为集群模式,比如:cluster.name、node.name、network.host、cluster.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_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
    
  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. 配置文件主要是对Node、Network和Discovery三个模块进行配置;
  3. Network模块的network.host也可以配置为0.0.0.0;
  4. 出现其他错误,可以参考Elasticsearch 7.x安装部署。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/460330.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号