一:邮件配置
V3 版本
newsenmail
{TRIGGER.STATUS} IN {HOST.IP1} : {TRIGGER.NAME}
触发器:{TRIGGER.NAME}
报警时间:{EVENT.DATE} {EVENT.TIME}
状态:{TRIGGER.STATUS}
问题主机:{HOSTNAME1}
主机IP:{HOST.IP1}
监控项:{ITEM.NAME}
监控项内容:{ITEM.VALUE}
newsenmail.sh
#!/bin/bash
export LANG=zh_CN.utf-8
mailto=$1
title=$2
main=$3
tmpfile=`/bin/mktemp`
echo "$main" > $tmpfile
/usr/bin/dos2unix $tmpfile
/bin/mail -s "$title" "$mailto" < $tmpfile
/bin/rm -rf $tmpfile
监控登录登出
二:windows 客户端
安装:
C:\zabbix_agent\bin\win64\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -i
启动:
C:\zabbix_agent\bin\win64\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -s
停止:
C:\zabbix_agent\bin\win64\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -x
卸载:
C:\zabbix_agent\bin\win64\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -d
2. 下载后解压缩将x64里面的zabbix_agentd.exe和zabbix_get.exe和zabbix_sender.exe三个文件放到C盘根目录,并创建zabbix_agentd.conf和zabbix_agentd.log
3. 创建zabbix_agentd.conf
LogFile=c:\zabbix_agentd.log agent日志文件
LogFileSize=100 设置日志文件大小这里是100MB 默认是MB
Server=10.1.5.4 zabbix监控主机IP地址
ListenPort=10050 通讯端口
ServerActive=127.0.0.1 被监控机的IP地址
Hostname=Vcenter 在添加Host时命名机器名要和这里的Hostname对应上
4. windows环境内客户端管理
zabbix_agentd.exe -c c:\zabbix_agentd.conf –i 安装
zabbixagent zabbix_agentd.exe -c c:\zabbix_agentd.conf –s 启动
zabbixagent zabbix_agentd.exe -c c:\zabbix_agentd.conf –x 停止
zabbixagent
-c :指定配置文件所有位置
-i :安装客户端
-s :启动客户端
-x :停止客户端
-d :卸载客户端
agent 本机检测是否端口正常
telnet 10.0.0.67 10050
三:清理zabbix历史记录
清理脚本
#!/bin/bash
User="root"
Passwd=""
history_Date=`date -d $(date -d "-15 day" +%Y%m%d) +%s` #取30天之前的时间戳
trends_Date=`date -d $(date -d "-60 day" +%Y%m%d) +%s` #取30天之前的时间戳
#Date=`date -d "20160719 09" +%s`
#echo $Date
#exit
$(which mysql) -u${User} -e "
use zabbix;
DELETE FROM history WHERE clock < $history_Date;
#select * from history WHERE clock < $history_Date limit 2;
optimize table history;
DELETE FROM history_str WHERE clock < $history_Date;
#select * FROM history_str WHERE clock < $history_Date limit 2;
optimize table history_str;
DELETE FROM history_uint WHERE clock < $history_Date
#select * FROM history_uint WHERE clock < $history_Date limit 2;
optimize table history_uint;
DELETE FROM trends WHERE clock < $trends_Date;
#select * FROM trends WHERE clock < $trends_Date limit 2;
optimize table trends;
DELETE FROM trends_uint WHERE clock < $trends_Date;
#select * FROM trends_uint WHERE clock < $trends_Date limit 2;
optimize table trends_uint;
DELETE FROM events WHERE clock < $history_Date;
#select * FROM events WHERE clock < $history_Date limit 2;
optimize table events;
其中histroy是详细的历史数据,
trends是图表趋势数据。
会将histroy数据保留7天,trend数据保留365天
这个是用于查找数据库大小的命令
SELECT table_schema , sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+----------------------+
| table_schema | Data Base Size in MB |
+--------------------+----------------------+
| db_hk | 0.14158630 |
| information_schema | 0.00976563 |
| mysql | 0.68990040 |
| performance_schema | 0.00000000 |
| zabbix | 7204.50000000 |
+--------------------+----------------------+
这个命令可以用来查找最大的几个table size
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = 'zabbix'
ORDER BY (data_length + index_length) DESC limit 10;
+-----------------------+------------+
| Tables | Size in MB |
+-----------------------+------------+
| history_uint | 4200.38 |
| history | 1708.34 |
| history_log | 483.67 |
| trends_uint | 424.78 |
| trends | 201.80 |
| events | 134.84 |
| alerts | 24.63 |
清理历史数据表
truncate table history;
truncate table history_uint;
mysql> truncate table history;
Query OK, 0 rows affected (2 min 58.82 sec)
mysql> truncate table history_uint;
Query OK, 0 rows affected (3.73 sec)
TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行。但 TRUNCATE TABLE 比 DELETE 速度快,且使用的系统和事务日志资源少。 DELETE 语句每次删除一行,并在事务日志中为所删除的每行记录一项。
TRUNCATE TABLE 通过释放存储表数据所用的数据页来删除数据,并且只在事务日志中记录页的释放。
TRUNCATE,DELETE,DROP放在一起比较:
TRUNCATE TABLE:删除内容、释放空间但不删除定义。
DELETE TABLE:删除内容不删除定义,不释放空间。
DROP TABLE:删除内容和定义,释放空间。
四:配置自动删除磁盘空间
zabbix 服务端
more /usr/lib/zabbix/alertscripts/automatic.conf
[Free disk space on / (percentage)]
run = find /tomcat_logs -type f -mtime +10 |xargs -t rm -f
[login_log]
run = w
五:日志记录
UserParameter=ningyuan.access.count[*],type c:\logs\%date:~0,4%-%date:~5,2%-%date:~8,2%.log|find /c "$1"
日志正则
logrt["c:\\logs\\2016-[0-1][0-9]-[0-9]{2}.log",".*cancelRegister,([0-9]+)#34;,,,,\1]
六:安装错误
Q:configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
A: yum -y install net-snmp-devel
Q:configure: error: Curl library not found
A:yum -y install libcurl curl-devel
Q:
PHP mbstring.func_overload | on | off | Fail |
A:/etc/php.ini
mbstring.func_overload=0
Q:zabbix 2.4.7 WEB UI默认账号密码
账号:Admin
密码:zabbix