zabbix 邮件告警

一.安装过程

1.关闭selinux,iptables,修改hosts信息

zabbix 邮件告警

2.上传yum源

[[email protected] ~]# yum install -y wget lrzsz
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[[email protected] yum.repos.d]# rz
[[email protected] yum.repos.d]# ls
Centos-6.repo CentOS-Debuginfo.repo CentOS-Vault.repo
CentOS-Base.repo CentOS-Media.repo epel-6.repo

3.安装mysql服务

[[email protected] yum.repos.d]# yum install -y mysql mysql-server
[[email protected] yum.repos.d]# /etc/init.d/mysqld start
[[email protected] yum.repos.d]# chkconfig mysqld on
[[email protected] yum.repos.d]# mysqladmin -uroot password ‘zabbix’

4.安装http服务

[[email protected] yum.repos.d]# yum install -y httpd
[[email protected] yum.repos.d]# /etc/init.d/httpd start
[[email protected] yum.repos.d]# chkconfig httpd on

5.部署php服务

#获取yum源
[[email protected] yum.repos.d]# rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
[[email protected] yum.repos.d]# yum -y install php56w php56w-gd php56w-mysqlnd php56w-bcmath php56w-mbstring php56w-xml php56w-ldap

#修改php.ini
[[email protected] ~]# vi /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1

6.配置web的主目录

[[email protected] ~]# mkdir /var/www/html/zabbix
[[email protected] ~]# vi /etc/httpd/conf/httpd.conf
DocumentRoot “/var/www/html/zabbix”
[[email protected] ~]# chown -R apache:apache /var/www/html/zabbix

7.安装zabbix(网址:https://sourceforge.net/projects/zabbix/files/latest/download?source=files)

[[email protected] ~]# rz
[[email protected] ~]# ls
anaconda-ks.cfg install.log.syslog
install.log zabbix-3.4.8.tar.gz
[[email protected] ~]# tar -zxvf zabbix-3.4.8.tar.gz
[[email protected] ~]# cp -a zabbix-3.4.8/frontends/php/ /var/www/html/zabbix
#将配置文件复制到web目录下
[[email protected] ~]# chmod +x /var/www/html/zabbix/php/
#设置执行权限
[[email protected] ~]# groupadd zabbix
[[email protected] ~]# useradd -g zabbix Zabbix
#添加用户和组

#编译安装
[[email protected] zabbix-3.4.8]# pwd
/root/zabbix-3.4.8
[[email protected] zabbix-3.4.8]# yum install gcc* mysql-devel libxml2-devel net-snmp* java* curl-devel libevent-devel -y
[[email protected] zabbix-3.4.8]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --enable-java --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl --prefix=/usr/local/Zabbix
遇到的问题
1、 configure: error: unixODBC library not found
[[email protected] zabbix-3.4.8]# yum install unixODBC-devel libssh2-devel -y
2、 configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h
[[email protected] zabbix-3.4.8]# yum -y install OpenIPMI-devel
3、 configure: error: Unable to use libevent (libevent check failed)
zabbix 邮件告警

4、 configure: error: Unable to use libpcre (libpcre check failed)
[[email protected] zabbix-3.4.8]# yum -y install pcre*

[[email protected] zabbix-3.4.8]# make && make install

8.修改zabbix_server.conf

[[email protected] zabbix-3.4.8]# vi /usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
AlertScriptsPath=/usr/local/zabbix/alertscripts
#指定发邮件的目录

9.添加Zabbix服务器和Zabbix代理启动脚本

[[email protected] zabbix-3.4.8]# cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
[[email protected] zabbix-3.4.8]# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
[[email protected] zabbix-3.4.8]# vi /etc/init.d/zabbix_server
[[email protected] zabbix-3.4.8]# vi /etc/init.d/zabbix_agentd
将上面的两个文件的 BASEDIR=/usr/local/为BASEDIR=/usr/local/zabbix

10.创建数据库,导入相关的数据库

[[email protected] zabbix-3.4.8]# mysql -uroot -p
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql> GRANT ALL PRIVILEGES ON zabbix.* TO [email protected] IDENTIFIED BY ‘zabbix’;
[[email protected] zabbix-3.4.8]# mysql -uroot -pzabbix zabbix < database/mysql/schema.sql
[[email protected] zabbix-3.4.8]# mysql -uroot -pzabbix zabbix < database/mysql/images.sql
[[email protected] zabbix-3.4.8]# mysql -uroot -pzabbix zabbix < database/mysql/data.sql

11.启动服务

[[email protected] zabbix-3.4.8]# /etc/init.d/mysqld restart
[[email protected] zabbix-3.4.8]# /etc/init.d/httpd restart
[[email protected] zabbix-3.4.8]# /etc/init.d/zabbix_server start
[[email protected] zabbix-3.4.8]# /etc/init.d/zabbix_agentd start
[[email protected] zabbix-3.4.8]# chkconfig zabbix_server on
[[email protected] zabbix-3.4.8]# chkconfig zabbix_agentd on

12.进入网页配置(http://192.168.2.100/php/setup.php)

zabbix 邮件告警
zabbix 邮件告警
zabbix 邮件告警
#设置密码为zabbix
zabbix 邮件告警
zabbix 邮件告警
zabbix 邮件告警
#需要下载文件,然后上传到指定的目录()
[[email protected] conf]# pwd
/var/www/html/zabbix/php/conf
[[email protected] conf]# rz
[[email protected] conf]# ls
maintenance.inc.php zabbix.conf.php.example
zabbix.conf.php
[[email protected] conf]# chown -R 1000.1000 zabbix.conf.php

zabbix 邮件告警
#密码:zabbix

设置为中文
zabbix 邮件告警
zabbix 邮件告警

13.更改Admin密码

zabbix 邮件告警

二.乱码解决

(1)C:\Windows\Fonts找到楷体simkai.ttf 上传到zabbix网站的fonts目录下。切换到zabbix站点目录,替换字体名称sed -i ‘s/DejaVuSans/simkai/g’ include/defines.inc.php

三.zabbix_agent的配置

添加zabbix用户和组
[[email protected] ~]# groupadd zabbix
[[email protected] ~]# useradd -g zabbix -m Zabbix

下载zabbix安装包,本文用的是3.0.3版本zabbix-3.4.8.tar.gz
tar -zxvf zabbix-3.4.8.tar.gz
yum install -y gcc pcre*
cd zabbix-3.4.8
./configure --prefix=/usr/local/zabbix --enable-agent
make && make install

修改agentd配置文件,配置zabbix server地址以及agented自己的Hostname
[[email protected] zabbix-3.4.8]# vi /usr/local/zabbix/etc/zabbix_agentd.conf
Server= ip.ip.ip.ip #服务端ip地址
ServerActive= ip.ip.ip.ip #服务端ip地址(主动模式)
Hostname=client #该值跟zabbix web上配置的主机名称要一致(配置-》主机-》主机名称(ip地址))

设置启动脚本
[[email protected] zabbix-3.4.8]# cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
[[email protected] zabbix-3.4.8]# chmod +x /etc/init.d/zabbix_agentd
[[email protected] zabbix-3.4.8]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[[email protected] zabbix-3.4.8]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
[[email protected] zabbix-3.4.8]# service zabbix_agentd start
[[email protected] zabbix-3.4.8]# echo “service zabbix_agentd start”>>/etc/rc.d/rc.local

四.如何设置简单的邮件报警

4.1安装mailx

[[email protected] ~]# yum install -y mailx
[[email protected] ~]# ln -s /bin/mailx /bin/mail
zabbix 邮件告警

#生成授权码,登录
[[email protected] php]# tail -4 /etc/mail.rc
set smtp=smtp.qq.com
set [email protected]
set smtp-auth-password=123456 #授权码
set smtp-auth=login
[[email protected] php]# /etc/init.d/postfix restart
[[email protected] ~]# echo test | mail -s “test” [email protected]
zabbix 邮件告警

4.2 zabbix服务器发送脚本配置

[[email protected] ~]# mkdir /usr/local/zabbix/alertscripts/
[[email protected] ~]# yum -y install mailx dos2unix
[[email protected] ~]# cd /usr/local/zabbix/alertscripts/
[[email protected] alertscripts]# ls
sendmail.sh
[[email protected] alertscripts]# vi sendmail.sh
[[email protected] alertscripts]# cat sendmail.sh
#!/bin/bash
FILE=/tmp/mailtmp.txt
echo "3">3" >FILE
dos2unix -k $FILE
/bin/mail -s “$2” $1 < $FILE
[[email protected] alertscripts]# chown zabbix.zabbix sendmail.sh
[[email protected] alertscripts]# chmod +x sendmail.sh
[[email protected] alertscripts]# ./sendEmail.sh [email protected] “test1” “test1”

4.3 zabbix页面配置

4.3.1 设置报警媒介

zabbix 邮件告警
#这三个参数必须加上

4.3.2 配置用户的邮箱地址

zabbix 邮件告警

4.3.3 配置触发动作

zabbix 邮件告警
zabbix 邮件告警
zabbix 邮件告警
zabbix 邮件告警

五.添加监控主机

5.1 填写agent信息

zabbix 邮件告警
zabbix 邮件告警

5.2 添加监控模板

zabbix 邮件告警
zabbix 邮件告警
zabbix 邮件告警

5.3 查看各项指标的情况变化

zabbix 邮件告警

六.测试

6.1 停掉zabbix_agent服务

[[email protected] etc]# poweroff
zabbix 邮件告警
zabbix 邮件告警