zoukankan      html  css  js  c++  java
  • 4.监控Redis

    prometheus监控redis需要用到redis_exporter。

    redis_exporter 项目地址:https://github.com/oliver006/redis_exporter

    1、安装部署

    我这里的redis部署在192.168.0.254之上,而prometheus服务端是在192.168.75.11上,这个时候,监控的工具redis_exporter可以部署在这两台主机任一一台上,只不过需要注意的是,在配置prometheus.yaml添加监控目标的时候,注意填写对应ip即可。

    我这里则部署在了Prometheus Server之上。

    cd /usr/local/src
    wget https://github.com/oliver006/redis_exporter/releases/download/v1.6.1/redis_exporter-v1.6.1.linux-amd64.tar.gz
    tar -zxv -f redis_exporter-v1.6.1.linux-amd64.tar.gz -C /usr/local/
    cd /usr/local/
    mv redis_exporter-v1.6.1.linux-arm64/ redis_exporter
    

    2、redis_exporter 用法

    解压后只有一个二进制程序就叫 redis_exporter 通过 -h 可以获取到帮助信息,下面列出一些常用的选项:

    -redis.addr:指明一个或多个 Redis 节点的地址,多个节点使用逗号分隔,默认为 redis://localhost:6379
    -redis.password:验证 Redis 时使用的密码;
    -redis.file:包含一个或多个redis 节点的文件路径,每行一个节点,此选项与 -redis.addr 互斥。
    -web.listen-address:监听的地址和端口,默认为 0.0.0.0:9121
    

    3,运行 redis_exporter 服务

    1,方式A直接启动

    ## 无密码
    ./redis_exporter redis//192.168.111.11:6379 &
    ## 有密码
    redis_exporter  -redis.addr 192.168.111.11:6379  -redis.password 123456 
    

    2,方式B通过system管理

    创建 redis_exporter.service 启动脚本

    vim /usr/lib/systemd/system/redis_exporter.service 
    
    [Unit]
    Description=redis_exporter
    Documentation=https://github.com/oliver006/redis_exporter
    After=network.target
    
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr 192.168.0.254:6377
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    

    注意:关于redis的相关信息,则在ExecStart配置项当中进行定义!

    redis_exporter 使用 prometheus 用户运行,所以需要创建该用户

    groupadd prometheus
    useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
    
    # 若有用户,则直接执行这个
    chown -R prometheus.prometheus /usr/local/redis_exporter
    

    启动服务:

    systemctl daemon-reload
    systemctl start redis_exporter
    systemctl status redis_exporter
    systemctl enable redis_exporter
    ss -tulnp | grep 9121
    

    4、配置 prometheus.yml 添加监控目标

    vim /usr/local/prometheus/prometheus.yml
      - job_name: 'redis'
        scrape_interval: 5s
        static_configs:
        - targets: ['localhost:9121']    #如果是部署在192.168.0.254上,那么localhost需要改成192.168.0.254
    

    重启服务。

    systemctl restart prometheus
    

    5,配置 Grafana 的模板

    redis_exporter 在 Grafana 上为我们提供好了 Dashboard 模板:https://grafana.com/dashboards/763

    下载后在 Grafana 中导入 json 模板就可以看到官方这样的示例截图啦:



  • 相关阅读:
    js 跳转链接的几种方式
    js 指定分隔符连接数组元素join()
    Ajax async属性
    非负数正则表达式
    firefox因 HTTP 严格传输安全(HSTS)机制无法打开网页
    查看linux系统某宏的定义(另类)
    ctags高级用法
    ctags简明用法
    关于数组和指针的一道例题的解读
    让gcc和gdb支持intel格式的汇编
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/13094099.html
Copyright © 2011-2022 走看看