当前位置: 首页 > news >正文

网站logo在线设计遵义公共资源交易中心电话

网站logo在线设计,遵义公共资源交易中心电话,电子商务网站有哪些和网址,电影采集网站怎么做seo配置文件优化后的 Prometheus 自动发现 MySQL 实例的完整 YAML 文件。该配置包括: MySQL Exporter 部署:使用 ConfigMap 提供 MySQL 连接信息。Prometheus 自动发现:通过 Kubernetes 服务发现自动抓取 MySQL 实例。 1、mysql 配置文件 &…

配置文件优化后的 Prometheus 自动发现 MySQL 实例的完整 YAML 文件。该配置包括:

  1. MySQL Exporter 部署:使用 ConfigMap 提供 MySQL 连接信息。
  2. Prometheus 自动发现:通过 Kubernetes 服务发现自动抓取 MySQL 实例。

1、mysql 配置文件 (mysql-deployment.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:name: mysqllabels:app: mysql
spec:replicas: 3selector:matchLabels:app: mysqltemplate:metadata:labels:app: mysqlannotations:prometheus.io/scrape: "true"  # 允许 Prometheus 抓取prometheus.io/port: "9104"    # MySQL Exporter 暴露的端口spec:containers:- name: mysqlimage: harbor.fq.com/public/mysql:9.1.0  # 使用官方 MySQL 镜像env:- name: MYSQL_ROOT_PASSWORDvalue: "password"  # 设置 MySQL root 密码ports:- containerPort: 3306  # MySQL 默认端口
---
apiVersion: v1
kind: Service
metadata:name: mysql-servicelabels:app: mysqlannotations:prometheus.io/scrape: "true"  # 允许 Prometheus 抓取prometheus.io/port: "9104"    # MySQL Exporter 暴露的端口
spec:selector:app: mysqlports:- name: mysqlprotocol: TCPport: 3306targetPort: 3306

cat mysql-statefulset.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:name: mysqllabels:app: mysql
spec:serviceName: "mysql"replicas: 1selector:matchLabels:app: mysqltemplate:metadata:labels:app: mysqlannotations:prometheus.io/scrape: "true"  # 允许 Prometheus 抓取prometheus.io/port: "9104"    # MySQL Exporter 暴露的端口spec:containers:- name: mysqlimage: harbor.fq.com/public/mysql:9.1.0  # MySQL 镜像env:- name: MYSQL_ROOT_PASSWORDvalue: "password"  # 设置 MySQL root 密码ports:- containerPort: 3306  # MySQL 默认端口volumeMounts:- name: mysql-datamountPath: /var/lib/mysql  # MySQL 数据存储路径volumes:- name: mysql-dataemptyDir: {}  # 使用空目录,不持久化数据---
apiVersion: v1
kind: Service
metadata:name: mysql-servicelabels:app: mysqlannotations:prometheus.io/scrape: "true"  # 允许 Prometheus 抓取prometheus.io/port: "9104"    # MySQL Exporter 暴露的端口
spec:selector:app: mysqlports:- name: mysqlprotocol: TCPport: 3306targetPort: 3306type: ClusterIP  # 内部服务

2、登录mysql,并创建‘mysql_exporter’用户

2.1、查看mysql容器名称,登录到容器内

[root@k8s-master01 example]# kubectl get pod
NAME                                  READY   STATUS    RESTARTS   AGE
kuard-d574f5b78-r2l77                 1/1     Running   0          278d
mysql-0                               1/1     Running   0          6s[root@k8s-master01 example]# kubectl exec -it mysql-0 -- bash
bash-5.1# 

2.2、确保 mysql_exporter 用户存在**

使用 MySQL root 用户登录并检查 mysql_exporter 用户:

SELECT user, host FROM mysql.user WHERE user = 'mysql_exporter';

2.3、如果没有该用户,则创建:

CREATE USER 'mysql_exporter'@'%' IDENTIFIED BY 'your_password';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'%';
FLUSH PRIVILEGES;

实操:

CREATE USER 'mysql_exporter'@'%' IDENTIFIED BY 'mysql123!';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'%';
FLUSH PRIVILEGES;

![[IMG-5、k8s平台:mysql 监控案例-20250318102405307.png]]

mysql> SELECT user, host FROM mysql.user WHERE user = 'mysql_exporter';
Empty set (0.00 sec)mysql> CREATE USER 'mysql_exporter'@'%' IDENTIFIED BY 'mysql123!';
Query OK, 0 rows affected (0.01 sec)mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'%';
Query OK, 0 rows affected (0.01 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)mysql> SELECT user, host FROM mysql.user WHERE user = 'mysql_exporter';
+----------------+------+
| user           | host |
+----------------+------+
| mysql_exporter | %    |
+----------------+------+
1 row in set (0.00 sec)mysql>

注意:确保 your_passwordmysqld-exporter 配置的密码匹配。

4. MySQL Exporter 配置文件 (mysql-exporter-config.yaml)

apiVersion: v1
kind: ConfigMap
metadata:name: mysql-exporter-config
data:.my.cnf: |-[client]user = mysql_exporterpassword = mysql123![client.servers]user = mysql_exporterpassword = mysql123!

5. MySQL Exporter 部署文件 (mysql-exporter-deployment.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:name: mysql-exporterlabels:app: mysql-exporter
spec:replicas: 1selector:matchLabels:app: mysql-exportertemplate:metadata:labels:app: mysql-exporterannotations:prometheus.io/scrape: "true"  # 允许 Prometheus 抓取prometheus.io/port: "9104"    # MySQL Exporter 暴露的端口spec:volumes:- name: mysql-exporter-configconfigMap:name: mysql-exporter-configitems:- key: .my.cnfpath: .my.cnfcontainers:- name: mysql-exporterimage: harbor.fq.com/prometheus/mysql-exporter:v0.16.0command:- mysqld_exporter- --config.my-cnf=/etc/mysql-exporter/.my.cnf  # 指定配置文件路径securityContext:runAsUser: 0  # 以 root 用户运行ports:- containerPort: 9104  # MySQL Exporter 默认端口volumeMounts:- name: mysql-exporter-configmountPath: /etc/mysql-exporter/.my.cnfsubPath: .my.cnf
---
apiVersion: v1
kind: Service
metadata:name: mysql-exporter-servicelabels:app: mysql-exporterannotations:prometheus.io/scrape: "true"  # 允许 Prometheus 抓取prometheus.io/port: "9104"    # MySQL Exporter 暴露的端口
spec:selector:app: mysql-exporterports:- protocol: TCPport: 9104targetPort: 9104type: ClusterIP

6. Prometheus 自动发现配置 (prometheus.yml)

scrape_configs:- job_name: 'mysql'kubernetes_sd_configs:- role: endpoints  # 从 Kubernetes Endpoints 发现服务relabel_configs:# 只抓取带有 `prometheus.io/scrape: "true"` 注解的服务- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]action: keepregex: true# 替换目标地址为服务的 IP 和指定端口(9104)- source_labels: [__meta_kubernetes_endpoint_address_target_kind, __meta_kubernetes_endpoint_address_target_name]action: keepregex: Pod;(.*mysql-exporter.*)  # 仅抓取名称包含 "mysql-exporter" 的 Pod- source_labels: [__meta_kubernetes_pod_ip]action: replacetarget_label: __address__replacement: $1:9104  # 指定 MySQL Exporter 的端口为 9104# 添加 Kubernetes 服务的 app 标签- source_labels: [__meta_kubernetes_service_label_app]action: replacetarget_label: app# 添加 Kubernetes 命名空间标签- source_labels: [__meta_kubernetes_namespace]action: replacetarget_label: namespace# 添加 Kubernetes 服务名称标签- source_labels: [__meta_kubernetes_service_name]action: replacetarget_label: service# 添加 Kubernetes Pod 名称标签- source_labels: [__meta_kubernetes_pod_name]action: replacetarget_label: pod# 添加 Kubernetes 节点名称标签- source_labels: [__meta_kubernetes_pod_node_name]action: replacetarget_label: node# 添加实例标签(用于区分不同的 MySQL 实例)- source_labels: [__meta_kubernetes_pod_ip]action: replacetarget_label: instance

7. 部署步骤

  1. 创建 ConfigMap

    kubectl apply -f mysql-exporter-config.yaml
  2. 部署 MySQL Exporter:

    kubectl apply -f mysql-exporter-deployment.yaml
  3. 更新 Prometheus 配置文件(prometheus.yml),添加 MySQL 的自动发现配置。

  4. 重启 Prometheus 以加载新配置。


8. 验证

  1. 检查 mysql-exporter 容器日志:

    kubectl logs <mysql-exporter-pod-name> -c mysql-exporter
    • 确保没有错误日志。
  2. 检查 Pod 状态:

    kubectl get pods
    • 确保 mysql-exporter 容器处于 Running 状态。
  3. 访问 Prometheus Web UI(http://<prometheus-server>:9090),查看 Targets 页面,确认 MySQL 目标已被发现。 ![[IMG-5、k8s平台:mysql 监控案例-20250317170341907.png]]


9. 生产环境建议

  • 高可用性:部署多个 MySQL Exporter 实例,并使用 Kubernetes 的 HorizontalPodAutoscaler 实现自动扩展。
  • 监控告警:设置 MySQL 关键指标的告警规则(如连接数、慢查询等)。
  • 资源限制:为 MySQL Exporter 设置资源限制(CPU 和内存)。
  • 日志管理:收集 MySQL Exporter 的日志,便于排查问题。

10. 示例告警规则 (mysql-alerts.yml)

groups:- name: mysql_alertsrules:- alert: MySQLDownexpr: mysql_up == 0for: 1mlabels:severity: criticalannotations:summary: "MySQL is down"description: "MySQL instance {{ $labels.instance }} is down."- alert: HighMySQLConnectionsexpr: mysql_global_status_connections > 1000for: 5mlabels:severity: warningannotations:summary: "High number of MySQL connections"description: "MySQL instance {{ $labels.instance }} has more than 1000 connections."- alert: HighMySQLSlowQueriesexpr: mysql_global_status_slow_queries > 10for: 5mlabels:severity: warningannotations:summary: "High number of slow queries on MySQL"description: "MySQL instance {{ $labels.instance }} has more than 10 slow queries."

http://www.dtcms.com/a/452181.html

相关文章:

  • 个人网站建设方案书怎么写建网站免费吗
  • 网站建设课程设计格式网站建设主体是什么
  • 大庆哈尔滨网站建设html模板 多列展示模板
  • 凡科 360免费建站公司如何建立微网站
  • 平昌县建设局网站千锋教育和达内哪个好
  • 网站建设业务流程seo是什么的简称
  • 微网站在线制作网站建设谈单流程
  • 推广网站有哪些方式唐山最新消息今天
  • 做网站泰安cdr做图时怎么找到网站的
  • 关键词挖掘工具网站用asp做网站怎么布局
  • 东莞做网站公司安卓市场下载官网
  • 佛山网站搭建公司哪家好泉州网红打卡景点
  • 在线生成固定悬浮导航的工具网站如何做测评视频网站
  • 网站开发的常用软件统计站老站长推荐app视频
  • 自己怎么给网站做优化排名新手搭建WordPress
  • 网站建设哪家好 需要多少钱网页设计实验报告心得和总结500字
  • 廊坊seo网站排名网站建设账户搭建
  • 网站排名优化提升快速徐州睢宁建设网站
  • 我贷款网站如何做easyui网站开发实战 pdf
  • 懒人之家网站模板建湖人才网临时工招聘
  • 国外网站建设模板平台推广方式
  • 网站建设加推广wordpress 首页统计
  • 上海网站建设品做ppt比较好的网站有哪些
  • 四川网站建设设计公司哪家好wordpress php占内存
  • 百度联盟广告怎么关闭网站优化升级
  • 写网站建设的软文网站怎么建设好看
  • 上海专业网站建站济南网站设计哪家好
  • 企业网站的页面特点浦东网站开发
  • 做网站公司赚不赚钱响应式网站制作流程图
  • 重庆智能网站建设推荐跨境电商营销策划方案