kibana对接elasticsearch集群中的多个节点

本文介绍如何通过在与Kibana相同的机器上运行Elasticsearch客户端节点来实现跨多个Elasticsearch节点的负载均衡。客户端节点作为智能负载均衡器,能够处理HTTP请求并根据需要将操作重定向到集群中的其他节点。

https://www.elastic.co/guide/en/kibana/current/production.html#load-balancing


Load Balancing Across Multiple Elasticsearch Nodesedit

If you have multiple nodes in your Elasticsearch cluster, the easiest way to distribute Kibana requests across the nodes is to run an Elasticsearch client node on the same machine as Kibana. Elasticsearch client nodes are essentially smart load balancers that are part of the cluster. They process incoming HTTP requests, redirect operations to the other nodes in the cluster as needed, and gather and return the results. For more information, see Node in the Elasticsearch reference.

To use a local client node to load balance Kibana requests:

  1. Install Elasticsearch on the same machine as Kibana.
  2. Configure the node as a client node. In elasticsearch.yml, set both node.data andnode.master to false:

    # 3. You want this node to be neither master nor data node, but
    #    to act as a "search load balancer" (fetching data from nodes,
    #    aggregating results, etc.)
    #
    node.master: false
    node.data: false
  3. Configure the client node to join your Elasticsearch cluster. In elasticsearch.yml, set thecluster.name to the name of your cluster.

    cluster.name: "my_cluster"
  4. Make sure Kibana is configured to point to your local client node. In kibana.yml, theelasticsearch.url should be set to localhost:9200.

    # The Elasticsearch instance to use for all your queries.
    elasticsearch.url: "http://localhost:9200"

### 安装和配置 Elasticsearch, Kibana 和 IK 分词器 #### 准备工作 为了在 Windows 环境下顺利安装和配置 ElasticsearchKibana 以及 IK 分词器,需先确认已安装 Docker Desktop 并启动服务。这能简化环境搭建过程并确保各组件间良好协作。 #### 配置环境变量 对于 Windows 用户来说,在本地磁盘上创建合适路径来放置 Elasticsearch 文件夹是必要的操作之一。应设定如下两个系统级环境变量[^4]: - `ES_HOME` 设置为 Elasticsearch 的根目录位置,例如 `D:\Study\ElasticSearch\elasticsearch-7.12.1` - `ES_JAVA_HOME` 指向内置 JDK 路径,比如 `D:\Study\ElasticSearch\elasticsearch-7.12.1\jdk` #### 启动 Elasticsearch 实例 通过命令行工具执行下面这段指令可以基于官方镜像运行一个带有持久化存储支持的 ES 进程: ```bash docker run --name elasticsearch \ -v es-data:C:\data\elasticsearch \ -v es-config:C:\elasticsearch\config \ -v es-plugins:C:\elasticsearch\plugins \ -p 9200:9200 -p 9300:9300 \ -e "discovery.type=single-node" \ -d docker.elastic.co/elasticsearch/elasticsearch:7.14.0 ``` 这里 `-v` 参数用于映射宿主机文件夹到容器内部相应位置,从而实现数据保存与插件管理功能[^3]。 #### 安装 IK 分词器插件 一旦 Elasticsearch 成功上线,则可通过以下方式为其添加中文分词能力: ```bash docker exec -it elasticsearch /bin/bash cd /usr/share/elasticsearch/plugins/ wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.14.0/elasticsearch-analysis-ik-7.14.0.zip unzip elasticsearch-analysis-ik-7.14.0.zip && rm -f elasticsearch-analysis-ik-7.14.0.zip exit ``` 上述脚本进入正在运行中的 ES 容器终端,并下载解压最新版本的 IK Analyzer 插件至指定目录完成安装流程。 #### 部署 Kibana 应用程序 最后一步就是让 Kibana 加入同一网络空间以便无缝对接前面建立好的搜索引擎集群。利用下列语句即可达成目标: ```bash docker network create es-net docker run --restart=always ^ --name kibana ^ -e ELASTICSEARCH_HOSTS=http://elasticsearch:9200 ^ --network=es-net ^ -p 5601:5601 ^ -d ^ docker.elastic.co/kibana/kibana:7.14.0 ``` 注意这里的 `ELASTICSEARCH_HOSTS` 已经被调整成指向名为 “elasticsearch”的节点名称而非 IP 地址形式,这是因为两者同处自定义虚拟交换机之下允许直接按名字互相寻址[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值