Zabbix -- 客户端安装以及如何添加数据库的动态监控视图

前提条件:Zabbix服务器端已经安装好,并且运行正常。

 

 

1 需要下载zabbix客户端,安装客户端,才能打开10050端口

wget http://www.zabbix.com/downloads/2.0.8/zabbix_agents_2.0.8.linux2_6.amd64.tar.gz

添加Zabbix用户和组。

groupadd zabbix  

useradd zabbix -g zabbix -s /sbin/nologin

 

2 解压缩

Tar –xvf zabbix_agents_2.0.8.linux2_6.amd64.tar.gz

Mv zabbix_agents_2.0.8.linux2_6.amd64 /usr/local/zabbix_2.0.8

[[email protected] zabbix_2.0.8]# ll

总用量 296

drwxr-xr-x. 2 root root   4096 4月  26 13:06 bin

drwxr-xr-x. 3 root root   4096 4月  26 15:20 conf

drwxr-xr-x. 2 root root   4096 4月  26 14:27 sbin

-rw-r--r--. 1 root root 288810 9月  10 2013 zabbix_agents_2.0.8.linux2_6_23.amd64.tar.gz

[[email protected] zabbix_2.0.8]#

 

3 启动

[[email protected] sbin]# nohup /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start -c  & > zabbix.log

[1] 18785

[[email protected] sbin]# nohup: 忽略输入并把输出追加到"nohup.out"

 

[[email protected] sbin]# more nohup.out

zabbix_agentd [18584]: cannot open config file [/usr/local/etc/zabbix_agentd.conf]: [2] No such file or directory

zabbix_agentd [18785]: zbx_option requires an argument -- c

usage: zabbix_agentd [-Vhp] [-c <config-file>] [-t <item key>]

报错加载不了配置文件,建立软连接

ln -s /usr/local/zabbix_2.0.8/conf/zabbix_agentd.conf /usr/local/etc/zabbix_agentd.conf

 

再次启动

[[email protected] sbin]# nohup /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start & > zabbix.log

[1] 18920

[[email protected] sbin]# nohup: 忽略输入并把输出追加到"nohup.out"

 

[1]+  Done                    nohup /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start

[[email protected] sbin]#

 

4 最终查看启动日志信息,没有最新记录,表示启动成功了。

[[email protected] sbin]# more nohup.out

zabbix_agentd [18811]: zbx_option requires an argument -- c

usage: zabbix_agentd [-Vhp] [-c <config-file>] [-t <item key>]

zabbix_agentd [18826]: user zabbix does not exist

zabbix_agentd [18826]: cannot run as root!

 

5 查看zabbix_agent启动后台进程

[[email protected] sbin]# ps -eaf|grep zabbix

zabbix   18922     1  0 13:21 ?        00:00:00 /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start

zabbix   18923 18922  0 13:21 ?        00:00:00 /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start

zabbix   18924 18922  0 13:21 ?        00:00:00 /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start

zabbix   18925 18922  0 13:21 ?        00:00:00 /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start

zabbix   18926 18922  0 13:21 ?        00:00:00 /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start

zabbix   18927 18922  0 13:21 ?        00:00:00 /usr/local/zabbix_2.0.8/sbin/zabbix_agentd start

root     18947  8652  0 13:21 pts/0    00:00:00 grep zabbix

 

6 自动添加启动脚本

ln -s /usr/local/zabbix_2.0.8/sbin/zabbix_agentd /etc/init.d/zabbix_agentd

chmod 755 /etc/init.d/zabbix_agentd

[[email protected] sbin]# chkconfig  --add zabbix_agentd

zabbix_agentd 服务不支持 chkconfig

 

chkconfig -- level 345 zabbix_agentd on

[[email protected] sbin]# chkconfig --level 345 zabbix_agentd on

zabbix_agentd 服务不支持 chkconfig

[[email protected] sbin]#
​vi /etc/init.d/zabbix_agentd 头部加描述即可
#!/bin/sh
# chkconfig: 345 95 95
# description: zabbix_agentd

 

 

失败

 

7 关闭zabbix_agentd进程

killall -9 zabbix_agentd

 

 

 

 

 

8添加自定义监控

8.1在数据库HOST上面,修改vi /usr/local/etc/zabbix_agentd.conf

UnsafeUserParameters=1 此处默认是0(不允许自定义脚本)

然后在后面添加UserParameter=key,command

key,command 为格式

此处key 是在创建item 的时候填写的

 

在这里面添加如下监控项:

UnsafeUserParameters=1

UserParameter=mysql.ping_test[*],mysqladmin -u$1 -p$2 ping|grep alive|wc –l

 

8.2重新启动 zabbix_agentd服务。

 

8.3 check服务

[[email protected] zabbix]# /usr/local/zabbix/bin/zabbix_get -s 10.254.3.72 -k mysql.ping_test['root','']

0

一直是0,但是在数据库服务器的机器上执行mysqladmin返回是1

[[email protected] conf]# mysqladmin -uroot  ping|grep alive|wc -l

1

[[email protected] conf]#

 

查看zabbix报错日志信息如下:

[[email protected] sbin]# tail -f zabbix_agentd.log

tail: 无法打开"zabbix_agentd.log" 读取数据: 没有那个文件或目录

[[email protected] sbin]# tail -f /tmp/zabbix_agentd.log

sh: mysqladmin: command not found

sh: mysqladmin: command not found

sh: mysqladmin: command not found

重新设置mysqladmin的全路径,并重新启动zabbix_agentd服务,再check状态

 

[[email protected] zabbix]# /usr/local/zabbix/bin/zabbix_get -s 10.254.3.72 -k mysql.ping_test['root','']

1

[[email protected] zabbix]#

 

9 服务器网站上面配置Item

需要在监控的服务器列表的HOST上选择服务器,打开Items下面选项,点击进去,再点击右上角的Create item。

 

点击Items-create Itmes。
Zabbix -- 客户端安装以及如何添加数据库的动态监控视图
Zabbix -- 客户端安装以及如何添加数据库的动态监控视图


输入key 值为mysql.ping_test[root,'']
Zabbix -- 客户端安装以及如何添加数据库的动态监控视图Zabbix -- 客户端安装以及如何添加数据库的动态监控视图


输入完成,点击下面的Save按钮,保存。

Zabbix -- 客户端安装以及如何添加数据库的动态监控视图Zabbix -- 客户端安装以及如何添加数据库的动态监控视图

 

10 配置graph

点击graphs---create graph,在ADD 处选择Items 为mysql.ping_test--save,稍等会儿就出图

Zabbix -- 客户端安装以及如何添加数据库的动态监控视图

Zabbix -- 客户端安装以及如何添加数据库的动态监控视图

 

 

11 然后再去看zabbix的界面,就会发现图片能生成出来了:

Zabbix -- 客户端安装以及如何添加数据库的动态监控视图

Zabbix -- 客户端安装以及如何添加数据库的动态监控视图