學習zabbix(一)
一、zabbix監控簡介
server: 通過收集snmp和agent發送的數據,寫入數據庫(MySQL,ORACLE),再通過 php+apache 在 web 前端展示。
agent:主機通過安裝agent方式采集數據,網絡設備通過SNMP方式采集數據
二、Zabbix功能
--具備常見的商業監控軟件所具備的功能
主機的性能監控、網絡設備監控、數據庫監控、多種報警方式、實時繪圖功能
--支持自動發現網絡設備和服務器
--支持分布式,能集中展示、管理分布式的監控點
--擴展性強,server提供通用接口,可以自己開發完善各類監控
三、安裝zbbix
yum源 cat /etc/yum.repos.d/a.repo [os] name=aliyun baseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/ enabled=1 gpgcheck=0 [zabbix] name=zabbix baseurl=http://mirrors.ustc.edu.cn/epel/6/x86_64/ enabled=1 gpgcheck=0
server 端:
1、安裝zabbix-server yum -y install zabbix22-server zabbix22-web zabbix22-web-mysql zabbix22-dbfiles-mysql zabbix22-agent mysql-server mysql php php-devel php-mysql2、導入數據結構 service mysqld start mysql CREATE DATABASE zabbix CHARACTER SET utf8; GRANT ALL ON zabbix.* TO ‘zabbix‘@‘192.168.4.%‘ IDENTIFIED BY ‘zabbix‘; FLUSH PRIVILEGES; mysql -u root -p zabbix < schema.sql 各種表結構 mysql -u root -p zabbix < images.sql 基本數據 mysql -u root -p zabbix < data.sql 自帶模板 mysql-e ‘USE zabbix;SHOW TABLES;‘ 3、配置文件 grep -n ‘^[a-Z]‘ /etc/zabbix_server.conf 39:LogFile=/var/log/zabbixsrv/zabbix_server.log 48:LogFileSize=0 68:PidFile=/var/run/zabbixsrv/zabbix_server.pid 77:DBHost=192.168.4.19 87:DBName=zabbix 103:DBUser=zabbix 111:DBPassword=zabbix 118:DBSocket=/var/lib/mysql/mysql.sock 458:AlertScriptsPath=/var/lib/zabbixsrv/alertscripts 466:ExternalScripts=/var/lib/zabbixsrv/externalscripts 507:TmpDir=/var/lib/zabbixsrv/tmp
agent
1、安裝 yum -y install zabbix22-agent 2、配置文件 grep -n ‘^[a-Z]‘ /etc/zabbix_agentd.conf 11:PidFile=/var/run/zabbix/zabbix_agentd.pid 21:LogFile=/var/log/zabbix/zabbix_agentd.log 30:LogFileSize=0 81:Server=192.168.4.19 122:ServerActive=127.0.0.1 133:Hostname=Zabbix server
訪問http://192.168.4.19/zabbix
點Next
修改配置文件
vim /etc/php.ini 945date.timezone = Asia/Shanghai 設置時區 440max_execution_time = 300 最大執行時間,秒 729post_max_size = 32M POST數據最大容量 449max_input_time = 300 服務器接收數據的時間限制 457memory_limit = 128M PHP內存占用的容量限制
service httpd restart
默認管理員賬戶密碼:admin zabbix
生成配置文件: /etc/zabbix/web/zabbix.conf.php
若切至中文有亂碼,解決辦法:
1、查看/etc/httpd/conf.d/zabbix.conf得知zabbix網頁目錄為/usr/share/zabbix/;
2、查看/usr/share/zabbix/include/defines.inc.php得知字體目錄位置:
define(‘ZBX_FONTPATH‘, ‘/usr/share/fonts/dejavu‘);// where to search for font (GD > 2.0.18)
define(‘ZBX_GRAPH_FONT_NAME‘, ‘DejaVuSans‘); // font file name;
3、將win中的任意字體(控制面板-->字體,例如仿宋或華文雅黑)復制到/usr/share/fonts/dejavu/下並覆蓋改名為DejaVuSans.ttf;
添加一臺主機
Configuration-->Hosts,Createhost--> Host name(test2) Visable name(test2) New group(demo) IP address(192.168.4.19) Port(10050) Status(Monitored)
添加報警:
註:報警針對用戶和用戶組;生產環境最好有短信平臺,或晚上用SMS,白天email;
Administration-->Users-->選Zabbixadministrators旁的Users-->右上角Create User,User標簽(Alias(demo),
Name(demo),Groups(Zabbix administrators),Password(demo)兩次,勾選Auto-login-->Media標簽,
Add,Type(Email),Send to(*@163.com),Add-->Permissions標簽(User-type選Zabbix Super Admin)-->Save;
右上角logout,用demo登錄;
註:Configuration-->Templates中的Applications應用集是監控項的集合,Item項目是監控的最小單位,有的Templates有Triggers有的沒
四、添加mysql監控
添加項目:
Configuration-->Hosts,選test2中的Items-->點右上角Createitem,如下圖創建,Name(mysql_check),Key(mysql_alive),update interval(in sec)(60),new flexible interval(300)-->Add,new application(MySQL),Description(MySQL Check)-->Save
agent 端的配置
vim /etc/zabbix/zabbix_agentd.conf UserParameter=mysql_alive,mysqladminping | grep -c alive
service zabbix-agentd restart
添加 觸發器
Configuration-->Hosts,選test2的triggers,右上角Createtrigger-->Name(MySQL down),Expression(點Add,如下圖,點Select,test2的mysql_check,Function(選Last (most recent) T value is NOT N,N(1))-->Insert-->Severity(disaster)
點Trigger標簽旁邊的Dependencies-->Add,選Zabbix agent on {HOST.NAME} is unreachable for 5minutes-->Save
添加圖形:
Configuration-->Hosts,選test2的graph,右上角Creategraph,Name(mysql status),Graph type(Normal),Items-->Add,選test2的mysql_check,點Graph標簽旁邊的Preview可預覽-->Save
添加報警
Configuration-->Actions,將Reportproblems to Zabbix administrators的status改為Enabled-->點Report problems to Zabbix administrators,Action標簽中的項(要精簡,一條短信是70個字符),Conditions,Operations(Operation details,from 1 to 3,第1次到第3次報警每次發送通知給指定的人,Operation type選Send message)-->先點Update-->再Save
五、添加報警郵件
配置郵箱
vim /etc/mail.rc #######set mail set from=usertzc@163.com smtp=smtp.163.com set smtp-auth-user=usertzc smtp-auth-password=password smtp-auth=login
添加腳本
cd /var/lib/zabbixsrv/alertscripts/ #(此目錄下的腳本必須支持三個參數,介質參數(email or SMS),title,content) vim /usr/lib/zabbix/alertscripts/mail.sh #!/bin/sh MAIL_TITLE=$2 MAIL_CON=$3 echo "$MAIL_CON" | /bin/mail -s "$MAIL_TITLE" $1 echo "$1 $2 $3" >> /tmp/alert chmod 755 send_mail.sh
配置報警郵件
Administration-->Media types-->Create media type,Name(send_mail),Type(Script),Script name(會自動生成),勾選Enabled-->Save
Configuration-->Actions-->點Report problems to Zabbix administrators-->選Operations,Edit,Operation details中,User group為zabbix administrator,Send only to選send_mail-->Update-->Save
Administration-->Users-->demo-->Media-->Add,Type(send_mail),Send to([email protected])-->Add-->Save
Administration-->Users-->Admin-->Media-->Add,Type(send_mail),Send to(root@localhost)-->Add-->Save
設置報警聲音:
右上角Profile-->Messaging標簽,勾選Frontend messaging;
測試:
1、將test2的mysqld停掉,#service mysqld stop|start 2、在Monitoring-->Dashboard中查看System status、Host status、Last 20issues中的Actions
less /var/log/zabbixsrv/zabbix_server.log tail -f /var/log/maillog
學習zabbix(一)