赞
踩
开始之前,需要准备好以下场景
- 一套 k8s 环境
- k8s 内有两套不同的 es 集群
- 有一个 kibana
- 有 helm 包管理工具
本集群用到的 es 和 metricbeat 都是 8.12.2 版本的
- 关于 es 和 kibana 部署,可以参考我之前的博客,我也是基于这个环境进行的配置:k8s 使用 helm 文件部署 8.12.2 es 分角色集群
es-svc 地址 | es 集群作用 |
---|---|
monitor-es-cluster-master-headless:9200 | es 监控集群 |
es-cluster-ingest-headless:9200 | es 集群 |
添加 es 的 helm 仓库
helm repo add elastic https://helm.elastic.co
下载 chart 包
helm pull elastic/metricbeat --version 8.5.1
解压 chart 包
tar xf metricbeat-8.5.1.tgz
这个集群的 svc 地址就是
monitor-es-cluster-master-headless:9200
- 需要注意,
metricbeat.modules
配置里面的 es 节点,一定要有ingest
和remote_cluster_client
这两个角色
在 kibana 页面,找到侧边栏的
开发工具
或者Dev Tools
,输入GET /
,在当前行的最右边有一个箭头点一下,运行这个 api,就能获得到类似下面这样的 json 内容,我们需要的是cluster_uuid
的值
{ "name": "monitor-es-cluster-master-0", "cluster_name": "monitor-es-cluster", "cluster_uuid": "hc2B2wFrQcWrmnH7yQmGxg", "version": { "number": "8.12.2", "build_flavor": "default", "build_type": "docker", "build_hash": "48a287ab9497e852de30327444b0809e55d46466", "build_date": "2024-02-19T10:04:32.774273190Z", "build_snapshot": false, "lucene_version": "9.9.2", "minimum_wire_compatibility_version": "7.17.0", "minimum_index_compatibility_version": "7.0.0" }, "tagline": "You Know, for Search" }
在 kibana 界面,找到侧边栏最下面的
Stack Management
,找到安全-API 密钥
或者Security-API keys
,然后创建创建 API 密钥
或者Create API Key
,自己定义一个名字,然后创建 API key
已编码切换成 beats,然后复制这个 api_key,下面的配置文件会用到
cd metricbeat/
cp values.yaml{,.tmp}
vim values.yaml
完成的 yaml 文件很长,我这里只标注一下我修改的内容,具体看注释
metricbeat 配置文件的解释:Configure Metricbeat
# 这里把 daemonset 类型注释掉,下面有 deployment 类型的 # 这个也是大家看自己的场景选择 daemonset: enabled: false # 以下的内容,都是在 deployment 层下面修改的 deployment: # 这里要注意 es 用户名密码的 secret 名字是不是集群有的 extraEnvs: - name: "ELASTICSEARCH_USERNAME" valueFrom: secretKeyRef: name: elastic-credentials key: username - name: "ELASTICSEARCH_PASSWORD" valueFrom: secretKeyRef: name: elastic-credentials key: password # metricbeat 配置文件的处理 metricbeatConfig: metricbeat.yml: | metricbeat.modules: # 我这边拿来采集 es 集群的,要把官方 helm 里面关于 k8s 采集的注释掉 # - module: kubernetes # enabled: true # metricsets: # - state_node # - state_deployment # - state_replicaset # - state_pod # - state_container # period: 10s # hosts: ["${KUBE_STATE_METRICS_HOSTS}"] # es 采集配置 - module: elasticsearch # 启用xpack xpack.enabled: true # 采集信息模块 metricsets: - node - node_stats - index - index_recovery - index_summary - ingest_pipeline - shard - ml_job period: 10s # ES节点地址,这里我们采集当前的监控集群 hosts: ["http://monitor-es-cluster-master-headless:9200"] # 前面在 kibana 页面生成的 api_key api_key: "oE7pkpABoGOz8aGJATlZ:BymKoPGeStexKYo2RJgXWQ" # 集群模式 scope: cluster # 采集 metricbeat 自身 - module: beat # 启用xpack xpack.enabled: true # 采集信息模块 metricsets: - stats - state period: 10s # metricbeat 地址信息 hosts: ["http://localhost:5066"] # 采集 kibana - module: kibana # 启用xpack xpack.enabled: true # 采集信息模块 metricsets: - status - cluster_actions - cluster_rules - node_actions - node_rules - settings - stats period: 10s # kibana 地址 hosts: ["http://monitor-kibana-kibana:5601"] # kibana 的用户名密码 username: "kibana_login" password: "Passw0rd@123" # 定义 metricbeat 采集的指标推送到哪个 es # 这里是推送到监控集群 output.elasticsearch: hosts: ["http://monitor-es-cluster-master-headless:9200"] api_key: "oE7pkpABoGOz8aGJATlZ:BymKoPGeStexKYo2RJgXWQ" _source.enabled: true preset: balanced protocol: "http" # ssl.enabled: true # ssl.certificate_authorities: ["/usr/share/metricbeat/certs/ca.crt"] # 增加自定义的标签信息 processors: - add_host_metadata: ~ - add_docker_metadata: ~ - add_kubernetes_metadata: ~ # 配置日志记录等级,error 错误才需要记录 logging.level: error monitoring.enabled: false # 这里的 uuid 是 metricbeat.modules 里面的 es 集群的 uuid ## 可以通过 kibana 或者 curl 去 GET /_cluster/state 来获取 monitoring.cluster_uuid: "hc2B2wFrQcWrmnH7yQmGxg" # 启用 http,便于健康检查 http.enabled: true http.host: 0.0.0.0 http.port: 5066 setup.template.settings: index.number_of_shards: 1 index.codec: best_compression # 我不是 https 的集群,不需要证书,这里直接注释掉,记得在 secretMounts 后面加上 [] secretMounts: [] # - name: elasticsearch-master-certs # secretName: elasticsearch-master-certs # path: /usr/share/metricbeat/certs/ # 配置资源限制,根据自己情况选择改不改 resources: requests: cpu: "100m" memory: "100Mi" limits: cpu: "1000m" memory: "1Gi" # 修改镜像 tag imageTag: "8.12.2" # 不安装 kube_state_metrics,因为不监控 k8s 集群 kube_state_metrics: enabled: false
开始安装,namespace 大家按照自己环境来
helm install monitor-es-metricbet ./ -n es-logs
返回类似下面的输出,说明 pod 开始启动了
NAME: manager-metricbet
LAST DEPLOYED: Sun Jul 7 15:23:39 2024
NAMESPACE: es-logs
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
1. Watch all containers come up.
$ kubectl get pods --namespace=es-logs -l app=manager-metricbet-metricbeat -w
和上面的方式一样,登录到对应的 es 集群的 kibana 界面去获取 uuid 和 api_key
直接复制一份 values.yaml 文件
cp values.yaml es-values.yaml
参照上面的内容做一下修改
# 监控的 es 节点要修改一下
- module: elasticsearch
hosts: ["http://es-cluster-ingest-headless:9200"]
api_key: "g0z0kpABrZG0ZA7sBUmp:spB5sF6RQe2FMygMMR-Ang"
- module: kibana
hosts: ["http://kibana-kibana:5601"]
# kibana 的用户名密码
username: "kibana_login"
password: "Passw0rd@123"
## 可以通过 kibana 或者 curl 去 GET /_cluster/state 来获取
monitoring.cluster_uuid: "YP1_tGWUTEOzQHXH9v4LNA"
开始安装
helm install es-metricbet ./ -f es-values.yaml -n es-logs
打开监控集群的 kibana 页面,找到侧边栏的
堆栈检测
或者Stack Monitoring
,然后点继续
或者Continue
点击
创建
或者Create
然后就能看到监控的两套 es 集群了
点一个进去,就能看到监控的信息了
可以点一下 Nodes,就能进去看 es 的节点监控了
Access Denied
You are not authorized to access Monitoring. To use Monitoring, you need the privileges granted by both the `kibana_admin` and `monitoring_user ` roles.
If you are attempting to access a dedicated monitoring cluster, this might be because you are logged in as a user that is not configured on the monitoring cluster.
Since Cross Cluster Search is enabled (`monitoring.ui.ccs.enabled` is set to `true`), make sure your cluster has the `remote_cluster_client` role on at least one node.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。