www.zabbix.com
http://www.zabbix.com/documentation/1.8/complete
http://www.zabbix.com/wiki/start
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux, Solaris, HP-UX, AIX, Free BSD, Open
BSD, OS X等平台之上。
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix agent可以运行在Linux ,Solaris, HP-UX, AIX, Free BSD,
Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows 2000/2003/XP/Vista)等系统之上。
zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(trapping方式),同时还可被动接收zabbix agent发送的数
据(trapping方式)。
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
软件需求:
Software Version Comments
Apache 1.3.12 or later
PHP 5.0 or later
PHP modules:php-gd GD 2.0 or later PHP GD module must support PNG p_w_picpaths.
PHP TrueType support --with-ttf
PHP bc support php-bcmath, --enable-bcmath
PHP XML support php-xml or php5-dom, if provided as a separate package by the distributor
PHP session support php-session, if provided as a separate package by the distributor
PHP socket support php-net-socket, --enable-sockets. Required for user script support.
PHP multibyte support php-mbstring, --enable-mbstring
MySQL php-mysql 3.22 or later Required if MySQL is used as Zabbix back end database.
①环境
yum -y install gcc mysql-server httpd php php-mysql php-gd php-bcmath php-xml php-mbstring mysql-devel php-snmp net-snmp-devel net-snmp net-snmp-utils OpenIPMI-devel
curl-devel
②下载解压
wget http://prdownloads.sourceforge.net/zabbix/zabbix-1.8.11.tar.gz?download
tar zxvf zabbix-1.8.11.tar.gz
③配置zabbix数据库
useradd zabbix
cd zabbix-1.8.11
\cp -rf /usr/share/doc/mysql-server-5.0.77/my-medium.cnf /etc/my.cnf
mysql_install_db --user=mysql
/etc/init.d/mysqld start
进入数据库:
mysql -u root -p
create database zabbix character set utf8;
grant all on zabbix.* to zabbix@localhost identified by 'zabbixpwd';
quit
退出数据库
mysql -uzabbix -pzabbixpwd zabbix < create/schema/mysql.sql
mysql -uzabbix -pzabbixpwd zabbix < create/data/data.sql
mysql -uzabbix -pzabbixpwd zabbix < create/data/p_w_picpaths_mysql.sql
④编译安装zabbix
./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-openipmi && \
make && \
make install
⑤zabbix服务配置
* 服务端口定义:
编辑 /etc/services,在后面追加:
cat >> /etc/services << "EOF"
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper
EOF
* 复制配置文件:
mkdir /etc/zabbix
cp misc/conf/zabbix_server.conf /etc/zabbix/
cp misc/conf/zabbix_proxy.conf /etc/zabbix/
cp misc/conf/zabbix_agent.conf /etc/zabbix/
cp misc/conf/zabbix_agentd.conf /etc/zabbix/
* 修改 zabbix server 配置文件 /etc/zabbix/zabbix_server.conf 中的数据库用户名和密码:
sed -i '95s/root/zabbix/' /etc/zabbix/zabbix_server.conf
sed -i '103a\DBPassword=zabbixpwd' /etc/zabbix/zabbix_server.conf
* 安装启动脚本
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
* 修改 /etc/init.d/zabbix_server 变量定义:
sed -i '19s#opt#usr/local#' /etc/init.d/zabbix_server
sed -i '25s#bin#sbin#' /etc/init.d/zabbix_server
* 修改 /etc/init.d/zabbix_agentd 变量定义:
sed -i '19s#opt#usr/local#' /etc/init.d/zabbix_agentd
sed -i '25s#bin#sbin#' /etc/init.d/zabbix_agentd
* 启动 Zabbix Server:
/etc/init.d/zabbix_server start
* 启动 Zabbix Agentd
/etc/init.d/zabbix_agentd start
* 配置WEB,复制 Web Interface 到 web 目录:
cp -r frontends/php/* /var/www/html/
/etc/init.d/httpd start
⑥WEB配置zabbix
打开http://localhost/,看到提示:
Timezone for PHP is not set. Please set "date.timezone" option in php.ini.
按照提示,修改 php.ini 中时区设置:
date.timezone = Asia/Shanghai
service httpd restart
依次单击下一步,在环境检测时会看到几个fail,再次修改 php.ini,根据提示设置相应参数:
post_max_size = 32M
max_execution_time = 600
max_input_time = 600
memory_limit = 256M
upload_max_filesize = 32M
Current value Required Recommended
PHP version 5.1.6 5.0 5.3.0 Ok
PHP memory limit 16M 128M 256M Fail
PHP post max size 8M 16M 32M Fail
PHP upload max filesize 2M 2M 16M Ok
PHP max execution time 30 300 600 Fail
PHP max input time 60 300 600 Fail
PHP timezone Asia/Shanghai Ok
PHP databases support MySQL Ok
PHP BC math yes Ok
PHP MB string yes Ok
PHP Sockets yes Ok
PHP GD 2.0.28 2.0 2.0.34 Ok
GD PNG Support yes Ok
libxml module 2.6.26 2.6.15 2.7.6 Ok
ctype module yes Ok
解决后按提示继续安装即可。
⑦结束:
安装完后直接访问:
http://localhost/
默认用户名和密码是:
admin/zabbix
客户端安装配置:
①环境
yum -y install gcc
②下载解压
tar zxf zabbix-1.8.11.tar.gz
③配置zabbix用户
useradd zabbix
cd zabbix-1.8.11
④编译安装zabbix
./configure --prefix=/usr/local/zabbix --enable-agent && \
make && \
make install
⑤zabbix服务配置
* 服务端口定义:
编辑 /etc/services,在后面追加:
cat >> /etc/services << "EOF"
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
EOF
* 复制配置文件:
mkdir /etc/zabbix
cp misc/conf/zabbix_agent.conf /etc/zabbix/
cp misc/conf/zabbix_agentd.conf /etc/zabbix/
* 修改配置文件:
vi /etc/zabbix/zabbix_agent.conf
Server=192.168.168.100
vi /etc/zabbix/zabbix_agentd.conf
Server=192.168.168.100
Hostname=server30
* 安装启动脚本
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
chmod a+x /etc/init.d/zabbix_agentd
* 修改 /etc/init.d/zabbix_agentd 变量定义:
BASEDIR=/usr/local/zabbix
FULLPATH=$BASEDIR/sbin/$BINARY_NAME
* 添加到启动服务:
chkconfig --add zabbix_agentd
* 启动 Zabbix Agentd
/etc/init.d/zabbix_agentd start
减少data1大小的办法,在vim /etc/my.cnf内修改
innodb_data_file_path = ibdata1:10M:autoextend:max:12800M
innodb_file_io_threads = 4
innodb_file_per_table = 0
忘记密码怎么办
更改密码为zabbix
mysql
mysql>update users set passwd=md5("zabbix") where userid='1';
Query OK, 0 rows affected (0.01 sec)
Rows matched: 1 Changed: 0 Warnings: 0
飞信下载连接及脚本
http://www.it-adv.net/
把飞信机器人和支持库都放在同一个目录/usr/local/fetion,复制部分支持库到/lib才能正常使用,运行./fetion不报错就行了
cp /usr/local/fetion/libACE-5.7.2.so /lib/
cp /usr/local/fetion/libACE_SSL-5.7.2.so /lib/
cp /usr/local/fetion/libcrypto.so.4 /lib/
cp /usr/local/fetion/libssl.so.4 /lib/
l 尝试发送测试飞信信息
cd /usr/local/fetion
./fetion --mobile=136116XXXXX --pwd=XXXXX --to=136116XXXXX --msg-utf8="我是小金金"
检查手机是否收到消息
#脚本位置
cd /home/zabbix/bin
#!/bin/bash
/usr/local/fetion/fetion --sid=946384807 --pwd=passwd --to="$1" --exit-on-verifycode=1 --msg-type=2 --msg-utf8="$2" >/dev/null 2>&1
或者
#!/bin/sh
#send sms by fetion
#$1, $2, $3 mean Recipient, Subject and Message
/usr/local/fetion/fetion --mobile=136116XXXXX --pwd=XXXXXX --to=$1 --msg-utf8="$2, $3" >/dev/null 2>&1
IO监控for Linux
UserParameter=vfs.partition.read[*],/usr/bin/iostat -d -k $(/bin/df | grep "$1$" | awk '{print $$1}'|awk -F\/ '{print $$3}')|sed -n '4p'|awk '{print $$3}'
UserParameter=vfs.partition.write[*],/usr/bin/iostat -d -k $(/bin/df | grep "$1$" | awk '{print $$1}'|awk -F\/ '{print $$3}')|sed -n '4p'|awk '{print $$4}'
vfs.partition.read[sda] //IO key
IO监控for aix
UserParameter=vfs.partition.read[*],/usr/bin/iostat -d -m $1 | grep '^$1' | awk '{print $$5}'
UserParameter=vfs.partition.write[*],/usr/bin/iostat -d -m $1 | grep '^$1' | awk '{print $$6}'
vfs.partition.read[hdisk1] //IO key
#检测用户登陆
UserParameter=user.login[*],who|grep $1 &>/dev/null;echo $?
user.login[root] //key
#检查mount
UserParameter=mount.nfs[*],cat /proc/mounts|grep $1 &>/dev/null;echo $?
mount.nfs[需要监控的目录] //key
检查USB使用
UserParameter=usb.device.number,tree /proc/bus/usb/ | wc -l
Windows服务器网卡流量监控
windows的key的关键字可以使用网卡的ip地址来替代。例如:net.if.out[192.168.101.1,bytes]
ORACLE监控
sqlplus '/as sysdba'
CREATE USER "ZABBIX" IDENTIFIED BY "jinyan123";
GRANT "CONNECT" TO "ZABBIX";
grant select on v_$instance to zabbix;
grant select on v_$sysstat to zabbix;
grant select on v_$session to zabbix;
grant select on dba_free_space to zabbix;
grant select on dba_data_files to zabbix;
grant select on dba_tablespaces to zabbix;
grant select on v_$log to zabbix;
grant select on v_$archived_log to zabbix;
grant select on v_$loghist to zabbix;
grant select on v_$system_event to zabbix;
grant select on v_$event_name to zabbix;
UserParameter=oracle[*],/zabora/zabora \$1 \$2
#TCP/IP链接数
UserParameter=custom.tcp.conn[*],netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' | grep $1 | awk '{print $$2}'
监视网卡流量的trigger
{Template_Linux:net.if.in[eth0,bytes].min(300)}>10000000
#memcached
UserParameter=memcache[*],printf 'stats\n' | nc 127.0.0.1 11211 | grep "STAT $1"|awk '{print $$3}'
#redis监控
cat redis_stats.sh
#!/bin/bash
/usr/local/bin/redis-cli -h IP地址 info >/tmp/redisstat
UserParameter=redis.stat[*],cat /tmp/redisstat | grep "$1:" | cut -d":" -f2
UserParameter=used_cpu_user_children,sed -n 78p /tmp/redisstat|awk -F':' '{print $2}'
UserParameter=used_cpu_sys_children,sed -n 77p /tmp/redisstat|awk -F':' '{print $2}'
#监控程序响应时间
curl -o /dev/null -s -w %{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}"\n" "http://localhost:8080/"
UserParameter=checktime,sh /etc/zabbix/checkweb.sh|awk -F ":" '{print $7}'
#监控文件大小
vfs.file.size[/opt/mysql_slow/localhost-slow.log]