centos8平台用redis-cli对redis5监控和管理
一,监控redis-server上正在执行的命令
1,打开a终端:
[root@yjweb log]# /usr/local/soft/redis5/bin/redis-cli -h 127.0.0.1 -p 6379 monitor OK
2,打开b终端:
[webop@yjweb ~]$ /usr/local/soft/redis5/bin/redis-cli 127.0.0.1:6379> get 123 (nil) 127.0.0.1:6379> set a 123 OK 127.0.0.1:6379> get a "123"
3,回到a终端查看,可以看到:
[root@yjweb log]# /usr/local/soft/redis5/bin/redis-cli -h 127.0.0.1 -p 6379 monitor OK 1583910234.328954 [0 127.0.0.1:32954] "COMMAND" 1583910244.535134 [0 127.0.0.1:32954] "get" "123" 1583910251.022645 [0 127.0.0.1:32954] "set" "a" "123" 1583910252.887344 [0 127.0.0.1:32954] "get" "a"
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/20/centos8linux-yong-rediscli-dui-redis5-jian-kong-he-guan-li/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,统计redis-server的状态,间隔 1s 实时输出一次
[root@yjweb log]# /usr/local/soft/redis5/bin/redis-cli -h 127.0.0.1 -p 6379 --stat ------- data ------ --------------------- load -------------------- - child - keys mem clients blocked requests connections 1 908.36K 2 0 7 (+0) 4 1 908.36K 2 0 8 (+1) 4 1 908.36K 2 0 9 (+1) 4
说明:
可以用-i参数指定刷新的时间间隔
-i <interval> When -r is used, waits <interval> seconds per command. It is possible to specify sub-second times like -i 0.1.
这些参数可以通过help得到:
[root@yjweb ~]$ /usr/local/soft/redis5/bin/redis-cli --help
三,扫描大 KEY
[root@yjweb log]# /usr/local/soft/redis5/bin/redis-cli -h 127.0.0.1 -p 6379 --bigkeys
可以列出系统中的大key
说明;如果是list,会给出包含多少items
如果是hash,会给出包含多少fields
四,统计当前机器到redis-server之间的延时
[root@yjweb log]# /usr/local/soft/redis5/bin/redis-cli -h 172.17.121.112 -p 6379 --latency
五,传出服务端的数据到当前目录,保存成一个rdb文件
[root@yjweb log]# /usr/local/soft/redis5/bin/redis-cli -h 172.17.121.112 -p 6379 --rdb order.rdb SYNC sent to master, writing 14252566 bytes to 'order.rdb' Transfer finished with success.
六,测试从redis-cli写一条信息到日志
这里需要lua命令
127.0.0.1:6379> eval "redis.log(redis.LOG_NOTICE,'aaaa')" 0 (nil)
执行完成后我们查看日志:
[root@yjweb log]# tail -10 redis.log 8240:M 11 Mar 2020 14:55:45.681 # Server initialized 8240:M 11 Mar 2020 14:55:45.681 * DB loaded from disk: 0.000 seconds 8240:M 11 Mar 2020 14:55:45.681 * Ready to accept connections 8240:M 11 Mar 2020 15:10:46.025 * 1 changes in 900 seconds. Saving... 8240:M 11 Mar 2020 15:10:46.025 * Background saving started by pid 8322 8322:C 11 Mar 2020 15:10:46.026 * DB saved on disk 8322:C 11 Mar 2020 15:10:46.026 * RDB: 0 MB of memory used by copy-on-write 8240:M 11 Mar 2020 15:10:46.125 * Background saving terminated with success 8240:M 11 Mar 2020 15:53:47.814 * aaaa
看到了我们写入的aaaa字串
七,查看当前centos服务器版本
[root@yjweb ~]# cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)