CentOS7 部署 ETCD 3.5.0 三节点 TLS 集群,集成 ETCD UI 管理和监控告警

本文将详细介绍如何在 CentOS7 系统上部署 ETCD 3.5.0 三节点 TLS 集群,并集成 ETCD UI 管理工具和 Prometheus、Grafana 监控系统,同时配置告警机制,实时监测 ETCD 节点状态,并在节点挂掉、磁盘不足或内存不足等情况下通知企业微信。

软件下载地址:

  • ETCD 3.5.0:https://github.com/etcd-io/etcd/releases/tag/v3.5.0
  • ETCD UI:https://github.com/etcd-io/etcd-browser/releases

部署步骤:

  1. 下载并解压 ETCD 3.5.0,进入解压后的目录。
  2. 生成 TLS 证书和密钥文件,具体步骤可以参考官方文档:https://etcd.io/docs/v3.5/op-guide/security/
  3. 配置 ETCD 集群,创建 etcd.service 文件,配置 ETCD 监听地址、TLS 证书和密钥文件、集群通信地址、节点名称等信息,示例配置如下:
[Unit]
Description=etcd
Documentation=https://github.com/etcd-io/etcd
After=network.target

[Service]
User=root
Type=notify
WorkingDirectory=/var/lib/etcd
ExecStart=/usr/local/bin/etcd \
  --name node1 \
  --listen-client-urls 'https://192.168.1.1:2379' \
  --advertise-client-urls 'https://192.168.1.1:2379' \
  --listen-peer-urls 'https://192.168.1.1:2380' \
  --initial-advertise-peer-urls 'https://192.168.1.1:2380' \
  --initial-cluster 'node1=https://192.168.1.1:2380,node2=https://192.168.1.2:2380,node3=https://192.168.1.3:2380' \
  --initial-cluster-token 'my-etcd-token' \
  --initial-cluster-state new \
  --client-cert-auth \
  --trusted-ca-file=/etc/etcd/ssl/ca.crt \
  --cert-file=/etc/etcd/ssl/server.crt \
  --key-file=/etc/etcd/ssl/server.key \
  --peer-client-cert-auth \
  --peer-trusted-ca-file=/etc/etcd/ssl/ca.crt \
  --peer-cert-file=/etc/etcd/ssl/server.crt \
  --peer-key-file=/etc/etcd/ssl/server.key \
  --data-dir=/var/lib/etcd \
  --logger=zap \
  --log-outputs=stderr \
  --log-level=info

Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
  1. 配置 ETCD UI 管理,下载并解压 ETCD UI,进入解压后的目录,修改 config.json 文件,配置 ETCD 的监听地址和 TLS 证书和密钥文件,示例配置如下:
{
  "etcdHost": "https://192.168.1.1:2379",
  "etcdCaCert": "/path/to/ca.crt",
  "etcdCert": "/path/to/client.crt",
  "etcdKey": "/path/to/client.key"
}
  1. 启动 ETCD 集群和 ETCD UI 管理,分别执行以下命令:
systemctl daemon-reload
systemctl enable etcd.service
systemctl start etcd.service

./etcd-browser --port=8000 --etcd-config=/path/to/config.json

优化 ETCD:

  1. 调整 ETCD 的日志级别,可以通过修改 etcd.service 文件中的 --log-level 参数来调整日志级别。
  2. 调整 ETCD 的内存限制,可以通过修改 etcd.service 文件中的 LimitNOFILE 参数来调整内存限制。
  3. 设置 ETCD 的自动备份,可以通过 crontab 定时调用 etcdctl 命令备份 ETCD 数据。

添加 Prometheus 和 Grafana 的监控:

  1. 安装 Prometheus 和 Grafana,可以参考官方文档:https://prometheus.io/docs/prometheus/latest/installation/ 和 https://grafana.com/docs/grafana/latest/installation/
  2. 配置 Prometheus,创建 prometheus.yml 文件,配置 ETCD 的 metrics 地址和 TLS 证书和密钥文件,示例配置如下:
global:
  scrape_interval:     15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'etcd'
    tls_config:
      ca_file: /path/to/ca.crt
      cert_file: /path/to/client.crt
      key_file: /path/to/client.key
    static_configs:
      - targets: ['192.168.1.1:2381', '192.168.1.2:2381', '192.168.1.3:2381']
  1. 启动 Prometheus,访问 http://localhost:9090/ 可以查看 Prometheus 的监控数据。
  2. 配置 Grafana,添加 Prometheus 数据源,导入 ETCD 的 dashboard,可以参考官方文档:https://grafana.com/docs/grafana/latest/features/datasources/prometheus/ 和 https://grafana.com/grafana/dashboards/13703

如果 Etcd 节点挂掉、磁盘不足、内存不足等,请通知企业微信,可以通过监控工具和告警系统来实现,比如 Prometheus 和 Alertmanager。可以参考官方文档:https://prometheus.io/docs/alerting/latest/configuration/ 和 https://prometheus.io/docs/alerting/latest/alertmanager/。

本文提供的部署和配置步骤仅供参考,具体配置需要根据实际情况进行调整。建议参考官方文档和相关教程,确保配置正确,并进行必要的测试。

CentOS7 部署 ETCD 3.5.0 三节点 TLS 集群,集成 ETCD UI 管理和监控告警

原文地址: https://www.cveoy.top/t/topic/ndA4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录