• 欢迎访问显哥博客,本网站纯属学习技术,绝无商业用途,欢迎小伙伴们共同学习!研究技术!QQ:52249909 加我QQ
  • 世界75亿人,这么小的概率,能认识你,是我一生的幸运,不妨加个QQ接触一下:52249909 加我QQ

企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】

Zabbix监控 lixian 5年前 (2020-05-21) 20801次浏览 1个评论 扫描二维码

1.部署Discuz论坛系统

#配置论坛nginx文件
[root@web01 ~]# cat  /etc/nginx/conf.d/discuz.conf
server {
    listen       80;
    server_name  www.discuz.com;
    location / {
        root   /usr/share/nginx/html/upload;
        index  index.php index.htm;
    }
    location ~ \.php$ {
        root   /usr/share/nginx/html/upload;
        fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
	}
}

#上传论坛代码包
[root@web01 ~]# ls
Discuz_X3.3_SC_GBK.zip

#解压代码包到nginx站点目录
[root@web01 ~]# unzip -q  Discuz_X3.3_SC_UTF8.zip  -d /usr/share/nginx/html/

#重启nginx服务
[root@web01 ~]# systemctl  restart  nginx

#更改php用户为nginx
[root@web01 /usr/share/nginx/html/upload]# vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx

#重启php-fpm服务
[root@web01 /usr/share/nginx/html/upload]# systemctl  restart  php-fpm.service 

#授权
[root@web01 /usr/share/nginx/html/upload]# chown -R nginx.nginx ./

2.安装discuz论坛页面

企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】

企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】

企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】

3.部署redis服务

#安装redis服务
[root@web01 ~]# yum install -y redis

#设置redis密码(大概在480行,添加一行代码即可)
[root@web01 ~]# vim /etc/redis.conf
requirepass 123456

#重启Redis服务
[root@web01 ~]# systemctl  restart  redis.service 

#配置discuz全局配置文件(更改redis配置信息)
[root@web01 ~]# vim /usr/share/nginx/html/upload/config/config_global.php
$_config['memory']['redis']['server'] = '127.0.0.1';
$_config['memory']['redis']['port'] = 6379;
$_config['memory']['redis']['pconnect'] = 1;
$_config['memory']['redis']['timeout'] = '0';
$_config['memory']['redis']['requirepass'] = '123456';

#重启php-fpm和redis服务
[root@web01 ~]# systemctl  restart  php-fpm.service  redis.service

#获取Redis配置信息
[root@web01 ~]# redis-cli   -a 123456  info
# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-957.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
...
...省略N行redis配置信息
...

4.编写监听脚本并赋予权限

[root@web01 /server/scripts]# cat redis_status.sh 
#!/bin/bash
R_COMMAND="$1"
R_PORT="6379" #根据实际情况调整端口
R_SERVER="127.0.0.1" #根据具体情况调整IP地址
PASSWD="123456" #如果没有设置Redis密码,为空即可
redis_status(){
    (echo -en "AUTH $PASSWD\r\nINFO\r\n";sleep 1;) | /usr/bin/nc "$R_SERVER" "$R_PORT" > /tmp/redis_"$R_PORT".tmp
    REDIS_STAT_VALUE=$(grep "$R_COMMAND:" /tmp/redis_"$R_PORT".tmp | cut -d ':' -f2)
    echo "$REDIS_STAT_VALUE"
}
case $R_COMMAND in
    used_cpu_user_children)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    used_cpu_sys)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    total_commands_processed)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    role)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    lru_clock)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    latest_fork_usec)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    keyspace_misses)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    keyspace_hits)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    keys)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    expired_keys)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    evicted_keys)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    connected_clients)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    changes_since_last_save)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    blocked_clients)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    rdb_bgsave_in_progress)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    aof_rewrite_in_progress)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    used_memory_peak)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    used_memory)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    used_cpu_user)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    used_cpu_sys_children)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    total_connections_received)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    cluster_enabled)
        redis_status "$R_PORT" "$R_COMMAND"
        ;;
    *)
        echo $"USAGE:$0 {used_cpu_user_children|used_cpu_sys|total_commands_processed|role|lru_clock|latest_fork_usec|keyspace_misses|keyspace_hits|keys|expired|expired_keys|connected_clients|changes_since_last_save|blocked_clients|rdb_bgsave_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received|aof_rewrite_in_progress|cluster_enabled}"
esac

#给脚本文件赋予执行权限
[root@web01 /server/scripts]# chmod +x redis_status.sh

5.编写zabbix监控项

[root@web01 /server/scripts]# cat /etc/zabbix/zabbix_agentd.d/redis_status.conf
UserParameter=redis_status[*],/bin/bash /server/scripts/redis_status.sh "$1"

#重启zabbix客户端
[root@web01 /server/scripts]# systemctl   restart   zabbix-agent

#zabbix客户端获取值测试
[root@web01 /server/scripts]# zabbix_agentd -t redis_status[used_cpu_user_children]
redis_status[used_cpu_user_children]          [t|0.00]

#删除tmp目录下不必要的缓存文件
[root@web01 /server/scripts]# rm -f /tmp/redis_6379.tmp

6.导入监控Redis状态模板

企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】

7.被控主机关联链接模板

企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】

8.查看redis_status模板监控项状态,若有数据则成功

企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】


本站博主 , 版权所有丨如未注明 , 均为原创
转载请注明原文链接:企业级zabbix监控实战——zabbix监控Redis服务【显哥出品,必为精品】
喜欢 (0)

您必须 登录 才能发表评论!

(1)个小伙伴在吐槽
  1. I may need your help. I've been doing research on gate io recently, and I've tried a lot of different things. Later, I read your article, and I think your way of writing has given me some innovative ideas, thank you very much.
    gate.io2023-05-27 14:07