主机环境:
[root@test ~]# uname -a
Linux test 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@test ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[root@test ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.132 netmask 255.255.255.0 broadcast 192.168.139.255
ether 00:0c:29:ca:b7:70 txqueuelen 1000 (Ethernet)
RX packets 356 bytes 41989 (41.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 224 bytes 41057 (40.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Zabbix版本:3.4.9
redis版本:
[root@test ~]# redis-server -v
Redis server v=4.0.10 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=3fdb544c08410115
主机防火墙和selinux关闭
Zabbix yum安装参考:https://www.tracymc.cn/archives/614,编译安装可参考https://www.tracymc.cn/archives/218.
redis安装参考:https://www.tracymc.cn/archives/397
项目地址:https://github.com/blacked/zbx_redis_template
具体步骤:
1.主机环境
[root@test scripts]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 test //这步不能忘,我的redis装在Zabbix server上面,所以这里直接写了127.0.0.1
2.安装python环境
[root@test ~]# yum -y install python-pip
[root@test ~]# pip install argparse
[root@test ~]# pip install redis
3.设置键值
[root@test home]# unzip zbx_redis_template-master.zip
Archive: zbx_redis_template-master.zip
ab24b7d61b234726105eb34dbc282c60b36b2655
creating: zbx_redis_template-master/
inflating: zbx_redis_template-master/README.md
inflating: zbx_redis_template-master/zbx_redis.conf
inflating: zbx_redis_template-master/zbx_redis_stats.js
inflating: zbx_redis_template-master/zbx_redis_stats.py
inflating: zbx_redis_template-master/zbx_redis_templates.xml
inflating: zbx_redis_template-master/zbx_redis_trapper_templates.xml
[root@test home]# cd zbx_redis_template-master/
[root@test zbx_redis_template-master]# ll
总用量 196
-rwxr-xr-x 1 root root 2669 9月 22 2016 README.md
-rwxr-xr-x 1 root root 318 9月 22 2016 zbx_redis.conf //配置文件
-rwxr-xr-x 1 root root 2695 9月 22 2016 zbx_redis_stats.js
-rwxr-xr-x 1 root root 4925 9月 22 2016 zbx_redis_stats.py //监控脚本,python编写
-rw-r--r-- 1 root root 88895 9月 22 2016 zbx_redis_templates.xml //模板
-rwxr-xr-x 1 root root 86427 9月 22 2016 zbx_redis_trapper_templates.xml
[root@test zbx_redis_template-master]# cp zbx_redis_stats.py /etc/zabbix/scripts/
根据实际情况修改脚本如下内容:
zabbix_host = '127.0.0.1' # Zabbix Server IP
zabbix_port = 10051 # Zabbix Server Port
hostname = 'test' #redis主机在zabbix web上的名字,要一致,不然可能会报错.
[root@test scripts]# chmod u+x /etc/zabbix/scripts/zbx_redis_stats.py //赋权
-p:redis端口号
-a:redis设置的认证密码,如果没有设置密码就不需要此选项
[root@test ~]# cat /etc/zabbix/zabbix_agentd.conf |grep conf|grep -v ‘#’ //yum安装zabbix的话agent默认配置文件为/etc/zabbix/zabbix_agentd.conf
Include=/etc/zabbix/zabbix_agentd.d/*.conf //你懂的,包含/etc/zabbix/zabbix_agentd.d下面的配置
设置键值:
[root@test scripts]# cat /etc/zabbix/zabbix_agentd.d/zbx_redis.conf
UserParameter=redis[*],/etc/zabbix/scripts/zbx_redis_stats.py -a 123456 -p 6379 123456 $1 $2 $3 //最好先-a再-p,不然会报错,当时在这边卡了很久
验证脚本:
[root@test scripts]# /etc/zabbix/scripts/zbx_redis_stats.py -a 123456 -p 6379 test expired_keys none
0
说明键值配置成功.
4.导入模板
先将模板存到本地,再导入到zabbix-server中.
导入下载模板,如下:
导入成功后可以在配置-模板查看已导入的模板,如下:
5.关联模板
添加模板:
配置-主机点击相关主机进去配置模板,如下:
6.zabbix web验证是否有数据
关联模板后,稍等一会,查看web页面是否有数据.
部分截图如下:
Be First to Comment