Elasticsearch 7.x外部访问

外部访问说明

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安装部署
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值