groupadd zabbix
useradd -g zabbix -M -s /sbin/nologin zabbix
tar zxvf zabbix-2.0.6.tar.gz
cd zabbix-2.0.6
./configure --enable-agent --prefix=/usr/local/zabbix
make
make install
[root@dota2 core]# pwd
/root/zabbix-2.0.6/misc/init.d/fedora/core
[root@dota2 core]# cp zabbix_agentd /etc/init.d/
vi /etc/init.d/zabbix_agentd
修改BASEDIR=/usr/local/为BASEDIR=/usr/local/zabbix
修改配置文件:
[root@dota2 etc]# pwd
/usr/local/zabbix/etc
[root@dota2 etc]# vi zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
DebugLevel=3
Server=zabbix_server_ip
ServerActive=zabbix_server_ip
Hostname=new_web1 ###服务器网页中设置的名子一致即可
启动:
[root@dota2 etc]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd: [ OK ]
[root@dota2 etc]# ps aux | grep zabbix
zabbix 20640 0.0 0.0 15884 672 ? S 22:15 0:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix 20642 0.0 0.0 15884 872 ? S 22:15 0:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix 20643 0.0 0.0 15884 484 ? S 22:15 0:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix 20644 0.0 0.0 15884 484 ? S 22:15 0:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix 20645 0.0 0.0 15884 484 ? S 22:15 0:00 /usr/local/zabbix/sbin/zabbix_agentd
zabbix 20646 0.0 0.0 15892 692 ? S 22:15 0:00 /usr/local/zabbix/sbin/zabbix_agentd
root 20648 0.0 0.0 103244 832 pts/0 S+ 22:15 0:00 grep zabbix
[root@dota2 etc]# netstat -ln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
Active UNIX domain sockets (only servers)
......
......
......
5:在mysql所在机器上的/usr/local/zabbix/etc/zabbix_agentd.conf文件的
# Include=/usr/local/etc/zabbix_agentd.conf.d/下加入:
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
userparameter_mysql.conf文件位于/usr/local/zabbix/etc/zabbix_agentd.conf.d/,内容如下:
-
[root@db zabbix_agentd.conf.d]# cat userparameter_mysql.conf
-
# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.
-
-
# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
-
# Key syntax is mysql.status[variable].
-
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/usr/local/zabbix /data/mysql/bin/mysql -uroot -pk****601 -hlocalhost -N | awk '{print $$2}'
-
-
# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
-
# Key syntax is mysql.size[<database>,<table>,<type>].
-
# Database may be a database name or "all". Default is "all".
-
# Table may be a table name or "all". Default is "all".
-
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
-
# Database is mandatory if a table is specified. Type may be specified always.
-
# Returns value in bytes.
-
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
-
UserParameter=mysql.size[*],echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema='$1'")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name='$2'");" | HOME=/usr/local/zabbix /data/mysql/bin/mysql -uroot -pk*****601 -hlocalhost -N
-
-
UserParameter=mysql.ping,HOME=/usr/local/zabbix /data/mysql/bin/mysqladmin -uroot -pk***601 ping | grep -c alive
-
UserParameter=mysql.version,/data/mysql/bin/mysql -uroot -pk***601 -hlocalhost -V
#****替换为mysql的密码即可
重启服务/etc/init.d/zabbix_agentd restart
将模板添加到机器上,然后即可显示相关信息!
过个几分钟就可以看到mysql的相关信息了!来个图片如下;
这种方式可以针对mysql5.5 或以前的版本,对应mysql5.6或以后的版本是有问题的,因为mysql -uroot -p'password'
会有报错!
Warning: Using a password on the command line interface can be insecure.
解决方法:创建一个无密码的用户,有类似于root的权限,
那么为了解决这个问题,必须无密码登录才可以,为了安全起见,限定只能在localhost登录
先创建一个zabbix用户(创建用户,密码不能为空,否则报错)
grant all PRIVILEGES on *.* to zabbix@'localhost' identified by '123456';
设置密码为root
set password for 'root'@'localhost'=password("");
退出
exit;
阅读(1729) | 评论(0) | 转发(2) |