zoukankan      html  css  js  c++  java
  • zabbix监控redis服务

                 zabbix监控redis服务

                                         作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.安装并配置redis服务

    1>.安装epel源

    [root@node201.yinzhengjie.org.cn ~]# yum -y install epel-release
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.huaweicloud.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.tuna.tsinghua.edu.cn
    Resolving Dependencies
    --> Running transaction check
    ---> Package epel-release.noarch 0:7-11 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==============================================================================================================================================================================================================================================================================
     Package                                                               Arch                                                            Version                                                          Repository                                                       Size
    ==============================================================================================================================================================================================================================================================================
    Installing:
     epel-release                                                          noarch                                                          7-11                                                             extras                                                           15 k
    
    Transaction Summary
    ==============================================================================================================================================================================================================================================================================
    Install  1 Package
    
    Total download size: 15 k
    Installed size: 24 k
    Downloading packages:
    epel-release-7-11.noarch.rpm                                                                                                                                                                                                                           |  15 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : epel-release-7-11.noarch                                                                                                                                                                                                                                   1/1 
      Verifying  : epel-release-7-11.noarch                                                                                                                                                                                                                                   1/1 
    
    Installed:
      epel-release.noarch 0:7-11                                                                                                                                                                                                                                                  
    
    Complete!
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# yum -y install epel-release

    2>.使用yum方式安装redis

    [root@node201.yinzhengjie.org.cn ~]# yum -y install redis
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    epel/x86_64/metalink                                                                                                                                                                                                                                   | 7.7 kB  00:00:00     
     * base: mirrors.huaweicloud.com
     * epel: mirrors.tuna.tsinghua.edu.cn
     * extras: mirrors.aliyun.com
     * updates: mirrors.tuna.tsinghua.edu.cn
    epel                                                                                                                                                                                                                                                   | 5.4 kB  00:00:00     
    (1/3): epel/x86_64/group_gz                                                                                                                                                                                                                            |  90 kB  00:00:00     
    (2/3): epel/x86_64/updateinfo                                                                                                                                                                                                                          | 1.0 MB  00:00:00     
    (3/3): epel/x86_64/primary_db                                                                                                                                                                                                                          | 6.7 MB  00:00:03     
    Resolving Dependencies
    --> Running transaction check
    ---> Package redis.x86_64 0:3.2.12-2.el7 will be installed
    --> Processing Dependency: libjemalloc.so.1()(64bit) for package: redis-3.2.12-2.el7.x86_64
    --> Running transaction check
    ---> Package jemalloc.x86_64 0:3.6.0-1.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==============================================================================================================================================================================================================================================================================
     Package                                                           Arch                                                            Version                                                                Repository                                                     Size
    ==============================================================================================================================================================================================================================================================================
    Installing:
     redis                                                             x86_64                                                          3.2.12-2.el7                                                           epel                                                          544 k
    Installing for dependencies:
     jemalloc                                                          x86_64                                                          3.6.0-1.el7                                                            epel                                                          105 k
    
    Transaction Summary
    ==============================================================================================================================================================================================================================================================================
    Install  1 Package (+1 Dependent package)
    
    Total download size: 648 k
    Installed size: 1.7 M
    Downloading packages:
    warning: /var/cache/yum/x86_64/7/epel/packages/jemalloc-3.6.0-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Public key for jemalloc-3.6.0-1.el7.x86_64.rpm is not installed
    (1/2): jemalloc-3.6.0-1.el7.x86_64.rpm                                                                                                                                                                                                                 | 105 kB  00:00:00     
    (2/2): redis-3.2.12-2.el7.x86_64.rpm                                                                                                                                                                                                                   | 544 kB  00:00:00     
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                                                                                                                                                         1.5 MB/s | 648 kB  00:00:00     
    Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    Importing GPG key 0x352C64E5:
     Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
     Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
     Package    : epel-release-7-11.noarch (@extras)
     From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : jemalloc-3.6.0-1.el7.x86_64                                                                                                                                                                                                                                1/2 
      Installing : redis-3.2.12-2.el7.x86_64                                                                                                                                                                                                                                  2/2 
      Verifying  : redis-3.2.12-2.el7.x86_64                                                                                                                                                                                                                                  1/2 
      Verifying  : jemalloc-3.6.0-1.el7.x86_64                                                                                                                                                                                                                                2/2 
    
    Installed:
      redis.x86_64 0:3.2.12-2.el7                                                                                                                                                                                                                                                 
    
    Dependency Installed:
      jemalloc.x86_64 0:3.6.0-1.el7                                                                                                                                                                                                                                               
    
    Complete!
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# yum -y install redis

    3>.修改redis的监听地址并启动

    [root@node201.yinzhengjie.org.cn ~]# hostname -i
    172.200.1.201
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# grep ^bind /etc/redis.conf 
    bind 127.0.0.1
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# sed -r -i 's#(bind )127.0.0.1#1172.200.1.201#' /etc/redis.conf 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# grep ^bind /etc/redis.conf 
    bind 172.200.1.201
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl restart redis.service 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl enable redis.service 
    Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# redis-cli -h 172.200.1.201 
    172.200.1.201:6379> 
    172.200.1.201:6379> info
    # Server
    redis_version:3.2.12
    .....

    二.zabbix agent端配置监控redis的脚本

    1>.在命令行中查看数据redis的监控指标

    [root@node201.yinzhengjie.org.cn ~]# echo -e "info
     quit" | nc 172.200.1.201 "6379" | grep -w redis_version
    redis_version:3.2.12
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# echo -e "info
     quit" | nc 172.200.1.201 "6379" | grep -w redis_version | awk -F ":" '{print $2}'
    3.2.12
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# echo -e "info
     quit" | nc 172.200.1.201 "6379" | grep -w os
    os:Linux 3.10.0-957.el7.x86_64 x86_64
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# echo -e "info
     quit" | nc 172.200.1.201 "6379" | grep -w os | awk -F ":" '{print $2}'
    Linux 3.10.0-957.el7.x86_64 x86_64
    [root@node201.yinzhengjie.org.cn ~]# 

    2>.编写脚本获取redis的监控项数据

    [root@node201.yinzhengjie.org.cn ~]# cat /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh 
    #!/bin/bash
    #
    #********************************************************************
    #Author:        yinzhengjie
    #QQ:             1053419035
    #Date:             2019-11-23
    #FileName:        shell/menu.sh
    #URL:             http://www.cnblogs.com/yinzhengjie
    #Description:        The test script
    #Copyright notice:     original works, no reprint! Otherwise, legal liability will be investigated.
    #********************************************************************
    
    function redis_status(){
        R_PORT=$1
        R_COMMAND=$2
        (echo -en "INFO 
    ";sleep 1;) | nc 172.200.1.201 "$R_PORT" > /tmp/redis_"$R_PORT".tmp
        REDIS_STATUS_VALUE=$(grep -w "$R_COMMAND" /tmp/redis_"$R_PORT".tmp | cut -d ':' -f2)
        echo $REDIS_STATUS_VALUE
    }
    
    function help(){
        echo "${0} + redis_status+ PORT + COMMAND"
    }
    
    function main(){
        case $1 in
            redis_status)
                redis_status $2 $3
                ;;
            *)
                help
                ;;
        esac
    }
    
    main $1 $2 $3
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# bash /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh redis_status 6379 redis_version
    3.2.12
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# bash /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh redis_status 6379 used_cpu_sys
    2.65
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# ll /tmp/redis_6379.tmp 
    -rw-r--r-- 1 root root 2139 Feb 28 10:21 /tmp/redis_6379.tmp
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# rm -f /tmp/redis_6379.tmp 
    [root@node201.yinzhengjie.org.cn ~]# 

    3>.修改zabbix的配置文件

    [root@node201.yinzhengjie.org.cn ~]# grep ^Include /etc/zabbix/zabbix_agentd.conf 
    Include=/etc/zabbix/zabbix_agentd.d/*.conf
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# cat /etc/zabbix/zabbix_agentd.d/yinzhengjie_monitoring.conf 
    UserParameter=tcp_status_monitoring[*],/etc/zabbix/zabbix_agentd.d/tcp_status_monitoring.sh $1 $2
    UserParameter=memcached_monitoring[*],/etc/zabbix/zabbix_agentd.d/memcached_monitoring.sh $1 $2 $3
    UserParameter=redis_monitoring[*],/etc/zabbix/zabbix_agentd.d/redis_monitoring.sh $1 $2 $3
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent.service 
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# ll /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh 
    -rw-r--r-- 1 root root 972 Feb 28 10:19 /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# chmod +x /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh           #别忘记为redis的监控脚本添加执行权限哟~
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# ll /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh
    -rwxr-xr-x 1 root root 972 Feb 28 10:19 /etc/zabbix/zabbix_agentd.d/redis_monitoring.sh
    [root@node201.yinzhengjie.org.cn ~]# 
    [root@node201.yinzhengjie.org.cn ~]# 

    三.zabbix WebUI配置

    1>.在zabbix server测试是否可以获取redis的监控数据

    [root@zabbix203.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s node201.yinzhengjie.org.cn -p 10050 -k "redis_monitoring[redis_status 6379 redis_version]"
    3.2.12
    [root@zabbix203.yinzhengjie.org.cn ~]# 

    2>.自定义redis模板的监控项

    3>.自定义redis模板的监控项图形

    4>.自定义redis模板的触发器

    5>.将自定义的模板和对应的zabbix agent主机进行关联

    6>.查看监控主机的图形

  • 相关阅读:
    C#-练习题
    C#-命名空间(十五)
    C#-枚举(十三)
    C#-多态(十二)
    C#-继承(十一)
    C#-结构体(十)
    C#-类(九)
    C#-方法(八)
    二叉树深度遍历和广度遍历
    iOS main.m解析
  • 原文地址:https://www.cnblogs.com/yinzhengjie2020/p/12348428.html
Copyright © 2011-2022 走看看