Advertisement

y81.第四章 Prometheus大厂监控体系及实战 -- 监控扩展(十二)

阅读量:

10.2 监控redis

https://github.com/oliver006/redis_exporter

10.2.1 部署redis

复制代码
    root@k8s-master1:~/app-monitor-case/redis/yaml# cat redis-deployment.yaml 
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: redis
      namespace: raymond-1
    spec:
      replicas: 1
      selector:
    matchLabels:
      app: redis
      template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis
        image: redis:4.0.14 
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 6379
      - name: redis-exporter
        image: oliver006/redis_exporter:latest
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 9121
    
    root@k8s-master1:~/app-monitor-case/redis/yaml# cat redis-exporter-svc.yaml 
    kind: Service  #service 类型
    apiVersion: v1
    metadata:
      annotations:
    prometheus.io/scrape: 'true'
    prometheus.io/port: "9121"
      name: redis-exporter-service
      namespace: raymond-1
    spec:
      selector:
    app: redis
      ports:
      - nodePort: 31082
    name: prom
    port: 9121
    protocol: TCP
    targetPort: 9121
      type: NodePort
    
    root@k8s-master1:~/app-monitor-case/redis/yaml# cat redis-redis-svc.yaml 
    kind: Service  #service 类型
    apiVersion: v1
    metadata:
    #  annotations:
    #    prometheus.io/scrape: 'false'
      name: redis-redis-service
      namespace: raymond-1
    spec:
      selector:
    app: redis
      ports:
      - nodePort: 31081
    name: redis
    port: 6379
    protocol: TCP
    targetPort: 6379
      type: NodePort
    
    root@k8s-master1:~/app-monitor-case/redis/yaml# kubectl create ns raymond-1
    namespace/raymond-1 created
    
    root@k8s-master1:~/app-monitor-case/redis/yaml# kubectl apply -f .
    deployment.apps/redis created
    service/redis-exporter-service created
    service/redis-redis-service created
    
    root@k8s-master1:~/app-monitor-case/redis/yaml# kubectl get pod -n raymond-1 
    NAME                     READY   STATUS    RESTARTS   AGE
    redis-78b555d9c6-rt6fq   2/2     Running   0          85s
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手

10.2.2 验证metrics

http://172.31.7.111:31082/metrics

在这里插入图片描述

10.2.3 prometheus采集数据

复制代码
    root@prometheus1:/apps/prometheus# vim prometheus.yml 
    ...
      - job_name: 'redis-monitor-metrics'
    static_configs:
    - targets: ['172.31.7.111:31082']
    
    root@prometheus1:/apps/prometheus# systemctl restart prometheus
    
    
      
      
      
      
      
      
      
    
    AI助手
在这里插入图片描述

10.2.4 grafana导入模版

14615:

在这里插入图片描述

导入自定义模版

在这里插入图片描述

10.3 监控mysql

mysqld_exporter监控Mysql服务的运行状态

https://github.com/prometheus/mysqld_exporter

10.3.1 安装mysql

复制代码
    root@node2:~# apt -y install mysql-server
    
    
      
    
    AI助手

10.3.2 授权监控账户权限

复制代码
    root@node2:~# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.29-0ubuntu0.20.04.3 (Ubuntu)
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> create user 'mysql_exporter'@'localhost' identified by 'imnot007';
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> GRANT PROCESS,REPLICATION CLIENT,SELECT ON *.* TO 'mysql_exporter'@'localhost';
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> exit
    Bye
    
    #验证权限
    root@node2:~# mysql -umysql_exporter -pimnot007
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 9
    Server version: 8.0.29-0ubuntu0.20.04.3 (Ubuntu)
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> exit
    Bye
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手

10.3.3 准备mysqld_exporter环境

复制代码
    root@node2:~# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
    
    root@node2:~# tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz 
    root@node2:~# cd mysqld_exporter-0.14.0.linux-amd64/
    root@node2:~/mysqld_exporter-0.14.0.linux-amd64# ls
    LICENSE  mysqld_exporter  NOTICE
    
    root@node2:~/mysqld_exporter-0.14.0.linux-amd64# cp mysqld_exporter /usr/local/bin/
    
    #免密码登录配置
    root@node2:~# vim /root/.my.cnf
    [client]
    user=mysql_exporter
    password=imnot007
    
    #验证权限
    root@node2:~# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10
    Server version: 8.0.29-0ubuntu0.20.04.3 (Ubuntu)
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> exit
    Bye
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手

10.3.4 启动mysql_exporter

复制代码
    root@node2:~# vim /etc/systemd/system/mysqld_exporter.service
    [Unit]
    Description=Prometheus Node Exporter
    After=network.target
    
    [Service]
    ExecStart=/usr/local/bin/mysqld_exporter --config.my-cnf=/root/.my.cnf
    
    [Install]
    WantedBy=multi-user.target
    
    root@node2:~# systemctl enable --now mysqld_exporter
    
    
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手

10.3.5 验证metrics

http://172.31.2.182:9104/metrics

在这里插入图片描述

10.3.6 prometheus采集数据

复制代码
    root@prometheus1:/apps/prometheus# vim prometheus.yml 
    ...
      - job_name: 'mysql-monitor-metrics'
    static_configs:
    - targets: ['172.31.2.182:9104'] 
    
    root@prometheus1:/apps/prometheus# systemctl restart prometheus
    
    
      
      
      
      
      
      
      
    
    AI助手

10.3.7 验证指标数据

在这里插入图片描述

10.3.8 导入模版

13106:

在这里插入图片描述

11323:

在这里插入图片描述

10.4 监控haproxy

通过haproxy_exporter监控haproxy

https://github.com/prometheus/haproxy_exporter

10.4.1 部署haproxy

复制代码
    root@node2:~# apt -y install haproxy
    
    #修改配置文件
    root@node2:~# vim /etc/haproxy/haproxy.cfg
    ...
    stats socket /var/lib/haproxy/haproxy.sock mode 660 level admin expose-fd listeners 
    
    root@node2:~# systemctl restart haproxy
    
    
      
      
      
      
      
      
      
      
    
    AI助手

10.4.2 部署haproxy_exporter

复制代码
    root@node2:~# wget https://github.com/prometheus/haproxy_exporter/releases/download/v0.13.0/haproxy_exporter-0.13.0.linux-amd64.tar.gz
    
    root@node2:~# tar xf haproxy_exporter-0.13.0.linux-amd64.tar.gz 
    root@node2:~# cd haproxy_exporter-0.13.0.linux-amd64/
    root@node2:~/haproxy_exporter-0.13.0.linux-amd64# ls
    haproxy_exporter  LICENSE  NOTICE
    root@node2:~/haproxy_exporter-0.13.0.linux-amd64# cp haproxy_exporter /usr/local/bin/
    
    #启动方式一:
    root@node2:~/haproxy_exporter-0.13.0.linux-amd64# haproxy_exporter --haproxy.scrape-uri=unix:/var/lib/haproxy/haproxy.sock 
    
    #启动方式二:
    开启状态页
    root@node2:~/haproxy_exporter-0.13.0.linux-amd64# vim /etc/haproxy/haproxy.cfg 
    ...
    listen stats
    bind :9009
    stats enable
    stats uri /haproxy-status
    stats realm HAProxy\ Stats\ Page
    stats auth admin:123456 
    
    root@node2:~/haproxy_exporter-0.13.0.linux-amd64# systemctl restart haproxy
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手

http://172.31.2.182:9009/haproxy-status

在这里插入图片描述
复制代码
    root@node2:~/haproxy_exporter-0.13.0.linux-amd64# haproxy_exporter --haproxy.scrape-uri="http://admin:123456@127.0.0.1:9009/haproxy-status;csv" &
    
    
      
    
    AI助手

10.4.3 验证metrics数据

http://172.31.2.182:9101/metrics

在这里插入图片描述

10.4.4 prometheus添加job

复制代码
    root@prometheus1:/apps/prometheus# vim prometheus.yml 
    ...
      - job_name: 'haproxy-monitor-metrics'
    static_configs:
    - targets: ['172.31.2.182:9101'] 
    
    root@prometheus1:/apps/prometheus# systemctl restart prometheus
    
    
      
      
      
      
      
      
      
    
    AI助手

10.4.5 验证指标数据

在这里插入图片描述

10.4.6 导入模板

367:

在这里插入图片描述

2428:

在这里插入图片描述

全部评论 (0)

还没有任何评论哟~