Kubernetes 中部署 kube-state-metrics 及 Prometheus 监控配置实战

文章目录

  • Kubernetes 中部署 kube-state-metrics 及 Prometheus 监控配置实战
  • 环境准备
  • 创建监控命名空间
  • 准备配置文件
  • 创建 ServiceAccount
  • 配置 RBAC 权限
  • 部署 kube-state-metrics
  • 部署node_exporter(可选)
  • 验证服务账号 Token
  • Prometheus 配置示例
  • 小结
  • 验证
  • 增加Grafana面板
    • 增加prometheus监控数据源
    • 添加k8s监控面板(需Grafana这台有网)
  • 扩展告警规则
  • 总结


Kubernetes 中部署 kube-state-metrics 及 Prometheus 监控配置实战

本文详细介绍了如何在 Kubernetes 集群中部署 kube-state-metrics 组件,配置服务账号(ServiceAccount)、RBAC 授权,并结合 Prometheus 采集 kube-state-metrics 和 node-exporter 指标的全过程,方便你快速搭建集群监控体系。


环境准备

假设你的 Kubernetes 集群节点 IP 为 10.255.101.217,且已经安装了 kubectl,且配置了访问权限。

一台 Master 多节点玩转 Kubernetes:sealos 一键部署实践

使用 Supervisor 和 Systemd 搭建 Prometheus + Alertmanager + Node Exporter + Grafana 全套监控系统


创建监控命名空间

首先,为监控组件创建一个专用的命名空间 monitor-sa

kubectl create ns monitor-sa

确认命名空间已经创建:

kubectl get ns

在这里插入图片描述


准备配置文件

  • sa.yaml
  • rbac.yaml
  • clust.yaml
  • jiankong.yaml
  • svc.yaml
  • node.yaml

创建 ServiceAccount

monitor-sa 命名空间中为 kube-state-metrics 创建一个服务账号 kube-state-metrics,方便后续绑定权限。

sa.yaml 文件内容:

apiVersion: v1
kind: ServiceAccount
metadata:# sa 账号名称name: kube-state-metrics# sa 账号名称空间namespace: monitor-sa

执行:

# kubectl apply -f sa.yaml serviceaccount/kube-state-metrics created

配置 RBAC 权限

为了让 kube-state-metrics 能够访问 Kubernetes 资源,创建对应的 ClusterRole:

rbac.yaml 文件内容:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:name: kube-state-metrics
rules:
- apiGroups: [""]resources: ["nodes", "pods", "services", "resourcequotas", "replicationcontrollers", "limitranges", "persistentvolumeclaims", "persistentvolumes", "namespaces", "endpoints"]verbs: ["list", "watch"]
- apiGroups: ["extensions"]resources: ["daemonsets", "deployments", "replicasets"]verbs: ["list", "watch"]
- apiGroups: ["apps"]resources: ["statefulsets"]verbs: ["list", "watch"]
- apiGroups: ["batch"]resources: ["cronjobs", "jobs"]verbs: ["list", "watch"]
- apiGroups: ["autoscaling"]resources: ["horizontalpodautoscalers"]verbs: ["list", "watch"]
- apiGroups: [""]resources: ["nodes/proxy"]verbs: ["get"]

创建 ClusterRoleBinding,将 ClusterRole 绑定给前面创建的 ServiceAccount:

clust.yaml 文件内容:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: kube-state-metrics
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: kube-state-metrics
subjects:
- kind: ServiceAccountname: kube-state-metricsnamespace: monitor-sa

应用:

# kubectl apply -f rbac.yamlclusterrole.rbac.authorization.k8s.io/kube-state-metrics created# kubectl apply -f clust.yamlclusterrolebinding.rbac.authorization.k8s.io/kube-state-metrics created

部署 kube-state-metrics

准备 Deployment 配置文件 jiankong.yaml

apiVersion: apps/v1
kind: Deployment
metadata:labels:app.kubernetes.io/name: kube-state-metricsname: kube-state-metricsnamespace: monitor-sa
spec:replicas: 1selector:matchLabels:app.kubernetes.io/name: kube-state-metricstemplate:metadata:labels:app.kubernetes.io/name: kube-state-metricsspec:serviceAccountName: kube-state-metricscontainers:- image: registry.k8s.io/kube-state-metrics/kube-state-metrics::latestimagePullPolicy: IfNotPresentname: kube-state-metricsports:- containerPort: 8080name: http-metricsprotocol: TCP

在准备它的svc.yaml

apiVersion: v1
kind: Service
metadata:name: kube-state-metricsnamespace: monitor-sa
spec:ports:- name: http-metricsport: 8080protocol: TCP#targetPort: 8080targetPort: http-metrics- name: telemetryport: 8081protocol: TCPtargetPort: telemetryselector:app.kubernetes.io/name: kube-state-metricssessionAffinity: Nonetype: NodePort

执行部署:

# kubectl apply -f jiankong.yaml
deployment.apps/kube-state-metrics created
# kubectl apply -f svc.yaml
service/kube-state-metrics created

查看 Pod 状态:

# kubectl -n monitor-sa get podsNAME                                  READY   STATUS    RESTARTS   AGE
kube-state-metrics-5b7cf967d6-knhww   1/1     Running   0          40m

查看映射的端口

# kubectl -n monitor-sa get svc
NAME                 TYPE       CLUSTER-IP        EXTERNAL-IP   PORT(S)                         AGE
kube-state-metrics   NodePort   192.168.144.178   <none>        8080:32470/TCP,8081:31602/TCP   75m

部署node_exporter(可选)

集群node很多,我们不会跟传统模式似的,一个一个去部署node_exporter,这个时候我们就再k8s中创建个DaemonSet,让它自己根据k8S的node节点进行创建

准备node.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:name: node-exporternamespace: monitor-sa
spec:selector:matchLabels:app: node-exportertemplate:metadata:labels:app: node-exporterspec:hostPID: truehostIPC: truehostNetwork: truecontainers:- name: node-exporterimage: quay.io/prometheus/node-exporter:v1.9.1imagePullPolicy: IfNotPresentports:- containerPort: 9100name: metricsresources:requests:cpu: "150m"limits:cpu: "500m"securityContext:privileged: true  # 若非必要,可设为 false 增强安全args:- --path.procfs=/host/proc- --path.sysfs=/host/sys- --collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($|/)volumeMounts:- name: devmountPath: /host/devreadOnly: true- name: procmountPath: /host/procreadOnly: true- name: sysmountPath: /host/sysreadOnly: true- name: rootfsmountPath: /rootfsreadOnly: truetolerations:- key: "node-role.kubernetes.io/control-plane"operator: "Exists"effect: "NoSchedule"volumes:- name: prochostPath:path: /proc- name: devhostPath:path: /dev- name: syshostPath:path: /sys- name: rootfshostPath:path: /

执行部署:

# kubectl apply -f node.yaml
daemonset.apps/node-exporter created

查看pod状态

# kubectl -n monitor-sa get nodes -o wide NAME             STATUS   ROLES                  AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION               CONTAINER-RUNTIME
10-255-101-152   Ready    <none>                 41d   v1.22.0   10.255.101.152   <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3
10-255-101-216   Ready    <none>                 41d   v1.22.0   10.255.101.216   <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3
10-255-101-217   Ready    control-plane,master   41d   v1.22.0   10.255.101.217   <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3
10-255-101-82    Ready    <none>                 41d   v1.22.0   10.255.101.82    <none>        CentOS Linux 7 (Core)   4.18.9-1.el7.elrepo.x86_64   containerd://1.4.3# kubectl -n monitor-sa get pods -o wide NAME                                  READY   STATUS    RESTARTS   AGE   IP               NODE             NOMINATED NODE   READINESS GATES
kube-state-metrics-5b7cf967d6-tk5kr   1/1     Running   0          87m   192.168.154.12   10-255-101-82    <none>           <none>
node-exporter-7sc7c                   1/1     Running   0          72m   10.255.101.152   10-255-101-152   <none>           <none>
node-exporter-d2w2z                   1/1     Running   0          72m   10.255.101.216   10-255-101-216   <none>           <none>
node-exporter-rc6bt                   1/1     Running   0          72m   10.255.101.82    10-255-101-82    <none>           <none>

验证服务账号 Token

通过命令查看 default 服务账号的 token:

# kubectl -n monitor-sa get secrets 
NAME                             TYPE                                  DATA   AGE
default-token-wrbmj              kubernetes.io/service-account-token   3      5m9s
kube-state-metrics-token-bkrsr   kubernetes.io/service-account-token   3      3m41s# kubectl -n monitor-sa describe secrets kube-state-metrics-token-bkrsr

将显示包含 token 的详细信息,可用于 Prometheus 授权。
在这里插入图片描述
!!!把token内容,复制到prometheus的服务器里

/data/app/prometheus/token

[root@10-255-101-216 prometheus]# cat token 
eyJhbGciOiJSUzI1NiIsImtpZCI6IlUyVjJSUGFyMWRDcWlZUUota2F0Q2xVY1pBTU45cW1HNEl2a1R2ajRlRzQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJtb25pdG9yLXNhIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Imt1YmUtc3RhdGUtbWV0cmljcy10b2tlbi1ia3JzciIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlLXN0YXRlLW1ldHJpY3MiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjZjRmODFlYS00Mzg3LTRhOGUtYjdlMC04ZjM1NjM0YjczMTciLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6bW9uaXRvci1zYTprdWJlLXN0YXRlLW1ldHJpY3MifQ.cco-tUhN7SeZL6H40ShY4WPwZ-h3TBQ2fLj1v64W9lCRAf2U0yTFackRO19odYY5YgVhujdaQcmMxfd3EGN_RQuQZv3p0AtRIXstOc9q9jdwFmQtGaPMjN-DuUWHa5Gx72jUXjgdXzEe6oHugjfFikBs13JCSU7uY3DfpDTIGWRorNz2hQCXWGJktydk_5J_mqH7y3DWsGNOLXZpENavVo25DMRgVvIGuRLTqh7atkcGGgke92cSSUJqhQ9RMqtrCApJ_8eZiL4r8vY-aF224yCqbzlMva1Jd2CMhagQbQIBQUeXzfMDRqVIyPv9KNziIKr68cA4XEaIv6yvqMzE8w
[root@10-255-101-216 prometheus]# 

Prometheus 配置示例

将上面获取到的服务账号 Token 保存到 Prometheus 服务器 /data/app/prometheus/token 文件中。

Prometheus 配置文件 prometheus.yml 中增加如下内容,实现采集 kube-state-metricsnode-exporter 指标:

global:scrape_interval: 15sevaluation_interval: 15s# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:# - "first_rules.yml"# - "second_rules.yml"scrape_configs:- job_name: "prometheus"static_configs:- targets: ["localhost:9090"]# 上边查看的svc的端口映射地址- job_name: kube-state-metricsstatic_configs:- targets: ['10.255.101.217:32470']labels:env: test20250528# 采集 node-exporter 指标- job_name: 'k8s-node-exporter'kubernetes_sd_configs:- role: podapi_server: https://10.255.101.217:6443bearer_token_file: /data/app/prometheus/tokentls_config:insecure_skip_verify: truerelabel_configs:- source_labels: [__meta_kubernetes_pod_label_app]regex: node-exporteraction: keep- target_label: envreplacement: test20250528- source_labels: [__meta_kubernetes_pod_ip]target_label: __address__replacement: '${1}:9100'action: replace- source_labels: [__meta_kubernetes_pod_node_name]target_label: nodeaction: replace- source_labels: [__meta_kubernetes_namespace]target_label: kubernetes_namespaceaction: replace- source_labels: [__meta_kubernetes_pod_name]target_label: kubernetes_pod_nameaction: replace# 采集 cadvisor 指标- job_name: test20250528-cadvisorhonor_timestamps: truemetrics_path: /metricsscheme: httpskubernetes_sd_configs:- api_server: https://10.255.101.217:6443role: nodebearer_token_file: /data/app/prometheus/tokentls_config:insecure_skip_verify: truebearer_token_file: /data/app/prometheus/tokentls_config:insecure_skip_verify: truerelabel_configs:- action: labelmapregex: __meta_kubernetes_node_label_(.+)- separator: ;regex: (.*)target_label: __address__replacement: 10.255.101.217:6443action: replace- source_labels: [__meta_kubernetes_node_name]separator: ;regex: (.+)target_label: __metrics_path__replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisoraction: replace- source_labels: [kubernetes_io_hostname]separator: ;regex: (.+)target_label: env_kubernetes_io_hostnamereplacement: test20250528-${1}action: replace- source_labels: [kubernetes_io_hostname]separator: ;regex: (.+)target_label: envreplacement: test20250528action: replace

小结

通过以上步骤,你已经完成了以下工作:

  • 创建专用命名空间 monitor-sa
  • 创建 kube-state-metrics 服务账号和对应的 RBAC 授权
  • 部署 kube-state-metrics 监控组件
  • 通过 Prometheus 采集 kube-state-metrics 和 node-exporter 指标
  • 配置了 Prometheus 访问 Kubernetes API Server 的安全 Token

验证

在这里插入图片描述

增加Grafana面板

增加prometheus监控数据源

请添加图片描述
请添加图片描述
我是只修改了URL,其他没任何修改
请添加图片描述
请添加图片描述

添加k8s监控面板(需Grafana这台有网)

请添加图片描述
ID:10000
请添加图片描述
请添加图片描述
在这里插入图片描述
至此面板添加完了,数据未显示的,需要微调,可自行进行调整


扩展告警规则

# 容器相关报警信息
groups:
- name: "ContainerRules"rules:- alert: "容器异常"expr: kube_pod_container_status_running{env="test20250528",pod !~ "security-inspector-polaris-cronjob.*"} != 1for: 90slabels:severity: Disasterenv: test20250528annotations:summary: "ns:{{ $labels.namespace }} pod: {{ $labels.container }}]"description: "{{ $labels.instance }}: {{ $labels.namespace }} 服务{{ $labels.container }} 容器运行异常"# 容器内存使用率告警(>80%)- alert: "ContainerMemoryUsage"expr: sum by(namespace,pod,container) (container_memory_rss{image!="",env="test20250528"}) / sum by(namespace,pod,container) (container_spec_memory_limit_bytes{image!="",env="test20250528"}) * 100  != +Inf > 80for: 1mlabels:severity: Warningenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] Container memory usage warning"description: "Container memory usage is above 80%.\nVALUE = {{ $value | printf \"%.2f\" }}%\n"# 容器 CPU 使用率告警(>80% - Warning)- alert: ContainerCpuUsageexpr: sum by(container, namespace, pod) (irate(container_cpu_usage_seconds_total{env="test20250528",image!=""}[5m]) * 100) / sum by(container, namespace, pod) (container_spec_cpu_quota{env="test20250528",image!=""} / container_spec_cpu_period{env="test20250528",image!=""}) > 80for: 1mlabels:severity: Warningenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] Container CPU usage warning"description: "Container CPU usage is above 80%.\nVALUE = {{ $value | printf \"%.2f\" }}%\n"# 容器 CPU 使用率告警(>90% - Disaster)- alert: "ContainerCpuUsage"expr: sum by(container, namespace, pod) (irate(container_cpu_usage_seconds_total{env="test20250528",image!=""}[5m]) * 100) / sum by(container, namespace, pod) (container_spec_cpu_quota{env="test20250528",image!=""} / container_spec_cpu_period{env="test20250528",image!=""}) > 90for: 1mlabels:severity: Disasterenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] Container CPU usage critical"description: "Container CPU usage is above 90%.\nVALUE = {{ $value | printf \"%.2f\" }}%\n"- alert: "容器重启"expr: rate(kube_pod_container_status_restarts_total{env="test20250528"}[15m]) > 0for: 5mlabels:severity: Disasterenv: test20250528annotations:summary: "[{{ $labels.namespace }}/{{ $labels.pod }} - {{ $labels.container }}] 容器发生重启"description: "{{ $labels.namespace }} 命名空间中的容器 {{ $labels.container }}(所属 Pod: {{ $labels.pod }})在过去 15 分钟内发生了重启)"

总结

至此 Kubernetes 监控体系的基础框架搭建完毕。后续可以根据业务需求增加更多监控项和告警规则。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/diannao/84911.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《重塑认知:Django MVT架构的多维剖析与实践》

MVT&#xff0c;即Model - View - Template&#xff0c;是Django框架独特的架构模式。它看似简单的三个字母&#xff0c;实则蕴含着深刻的设计哲学&#xff0c;如同古老智慧的密码&#xff0c;解开了Web应用开发的复杂谜题。 模型&#xff0c;是MVT架构中的数据核心&#xff0…

【JVM】初识JVM 从字节码文件到类的生命周期

初识JVM JVM&#xff08;Java Virtual Machine&#xff09;即 Java 虚拟机&#xff0c;是 Java 技术的核心组件之一。JVM的本质就是运行在计算机上的一个程序&#xff0c;通过软件模拟实现了一台抽象的计算机的功能。JVM是Java程序的运行环境&#xff0c;负责加载字节码文件&a…

人工智能在智能零售中的创新应用与未来趋势

随着电子商务的蓬勃发展和消费者需求的不断变化&#xff0c;零售行业正面临着前所未有的挑战和机遇。智能零售作为零售行业的重要发展方向&#xff0c;通过引入人工智能&#xff08;AI&#xff09;、物联网&#xff08;IoT&#xff09;、大数据和云计算等前沿技术&#xff0c;正…

DeepSeek 赋能智能物流:解锁仓储机器人调度的无限可能

目录 一、智能物流仓储机器人调度现状1.1 传统调度面临的挑战1.2 现有智能调度的进展与局限 二、DeepSeek 技术探秘2.1 DeepSeek 核心技术原理2.2 DeepSeek 的独特优势 三、DeepSeek 在智能物流仓储机器人调度中的创新应用3.1 智能任务分配与调度3.2 路径规划与避障优化3.3 实时…

Vue CLI创建vue项目,安装插件

Vue CLI创建vue项目&#xff0c;安装插件 一、创建项目1. 安装Vue CLI2. 创建项目 二、安装插件routerlesssassjquery 一、创建项目 1. 安装Vue CLI npm install -g vue/cli2. 创建项目 vue create project cd project二、安装插件 router npm install vue-router # 对于 …

小白成长之路-Linux程序管理(二)

文章目录 一、源码包&#xff08;编译&#xff09;安装1.安装前先查看磁盘大小2.压缩包的位置3.执行编译 二、二进制安装三、Linux操作系统启动流程3.1概述3.2启动流程核心阶段1.电源与固件阶段2.引导加载程序3.内核初始化4.systemd初始化进程5. 用户登录阶段 四、systemd管理机…

Ansible模块——Ansible的安装!

Ansible 安装 Ansible 有三种安装方式&#xff0c;源码安装、发行版安装和 Python 安装。 使用发行版安装或 Python 安装两种方式时&#xff0c;Ansible 的安装包有两个&#xff0c;区别如下&#xff1a; • ansible-core&#xff1a;一种极简语言和运行时包&#xff0c;包含…

《全面解析鸿蒙相关概念:鸿蒙、开源鸿蒙、鸿蒙 Next 有何区别》

大家好&#xff0c;这里是程序员晚枫&#xff0c;最近接了一个和鸿蒙电脑有关的商单&#xff0c;所以专门花时间研究了一下和鸿蒙有关的概念。 鸿蒙系统相关概念主要有以下三个&#xff0c;它们之间存在多方面的区别&#xff0c;以下是具体介绍&#xff1a; OpenHarmony 定义…

C# 数组与字符串:全面解析与应用实践

在C#编程语言中&#xff0c;数组和字符串是两种最基础也是最重要的数据类型。无论是简单的控制台应用程序&#xff0c;还是复杂的企业级系统&#xff0c;数组和字符串都扮演着不可或缺的角色。本文将全面深入地探讨C#中数组和字符串的特性、使用方法、性能考量以及实际应用场景…

VR 技术在农业领域或许是一抹新曙光​

在科技日新月异的今天&#xff0c;VR(虚拟现实)技术已不再局限于游戏、影视等娱乐范畴&#xff0c;正逐步渗透到各个传统行业&#xff0c;为其带来全新的发展契机&#xff0c;农业领域便是其中之一。VR 技术利用计算机生成三维虚拟世界&#xff0c;给予用户视觉、听觉、触觉等多…

SPEAR开源程序是用于逼真演示 AI 研究的模拟器

​一、软件介绍 文末提供程序和源码下载 SPEAR开源程序是用于逼真具身 AI 研究的模拟器 二、AI 研究的模拟器 交互式模拟器正在成为训练具体代理的强大工具&#xff0c;但现有的模拟器存在内容多样性、物理交互性和视觉保真度有限的问题。我们通过引入 SPEAR&#xff1a;照片…

第1章 Redis 概述

一、Redis 简介 Redis,Remote Dictionary Server,远程字典服务,由意大利人Salvatore Sanfilippo(又名Antirez)开发,是一个使用ANSI C 语言编写&#xff64;支持网络&#xff64; 可基于内存亦可持久化的日志型&#xff64;NoSQL 开源内存数据库,其提供多种语言的API&#xff61…

图论学习笔记 5 - 最小树形图

我们不废话&#xff0c;直接进入正题&#xff1a;最小树形图&#xff0c;一个名字看起来很高级的东西。 声明&#xff1a;为了便于理解&#xff0c;可能图片数量会有亿点点多。图片尺寸可能有的较大。 概念 最小树形图的英文是 Directed Minimum Spanning Tree。 相信懂英文…

力扣面试150题--完全二叉树的节点个数

Day 51 题目描述 思路 根据完全二叉树的规律&#xff0c;完全二叉树的高度可以直接通过不断地访问左子树就可以获取&#xff0c;判断左右子树的高度: 1. 如果相等说明左子树是满二叉树, 然后进一步判断右子树的节点数(最后一层最后出现的节点必然在右子树中&#xff09; 2. 如…

社区造数服务接入MCP|得物技术

一、背景 ​ 今年 MCP 的概念非常火&#xff0c;市面上也涌现出了一大批 MCP 相关工具。作为技术一线者&#xff0c;都会按捺不住地去实操一下&#xff0c;很早的时候就有个设想&#xff0c;如果把我们的测试工具都改造为符合 MCP 服务协议标准&#xff0c;然后全部接入 AI A…

Mysql 查询时间段内的sql优化

Mysql 查询时间段内的sql优化 一说写到查询某个时间段的sql查询,我们就会使用DATE_FORMAT函数格式化日期字段: 比如查询某年某月的数据,我们可能常用的方式如下 DATE_FORMAT(pay_time,%Y-%m)=DATE_FORMAT(now(),%Y-%m) 但是这样做会使索引失效,尤其在数据量越来越多的情况…

用 Deepseek 写的 html+js 密码生成器

下面是一个功能完整的密码生成器HTMLJS实现&#xff0c;包含数字、小写字母、大写字母、符号、避免重复字符和密码长度设置功能。 <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta name"viewport&…

WPF绑定

如何使用绑定去改变事件驱动的关系。 先介绍一下标签扩展 目录 控件与控件之间的绑定 代码分析 绑定语法详解 1. Binding - 绑定标记 2. ElementName=slider - 绑定源 3. Path=Value - 绑定路径 不同控件属性的默认模式: 控件和属性绑定 1. 数据模型类的作用 2. 窗…

同源“平滑思想”的问题解法:正则化与拉普拉斯平滑

同源“平滑思想”的问题解法&#xff1a;正则化与拉普拉斯平滑 在机器学习和概率模型的实践中&#xff0c;正则化与拉普拉斯平滑是两个看似无关的技术&#xff1a;前者用于防止模型过拟合&#xff0c;后者用于解决零概率问题。但如果深入理解它们的核心逻辑&#xff0c;会发现…

用 AI 让学习更懂你:如何打造自动化个性化学习系统?

用 AI 让学习更懂你:如何打造自动化个性化学习系统? 在这个信息爆炸的时代,传统的学习方式已经难以满足个体化需求。过去,我们依赖固定的教学课程,所有学生按照统一进度进行学习,但每个人的学习节奏、兴趣点和理解方式都不尽相同。而人工智能(AI)正在彻底改变这一局面…