- 前言
告警将重要信息发送给运维「或者其他相关人」,及时发现并且处理问题。在所有开源监控软件里面,Zabbix 的告警方式无疑是最棒的。告警的方式各式各样,从 Email 告警到飞信、139/189邮箱、最后到微信甚至电话告警,接入存在各种问题以及困难,有没有什么软件能够将他们All In one呢?OneAlert
2. Zabbix传统告警方法
Email:调用 sendmail 、sendEmail 等脚本通过 SMTP 发送邮件
飞信:飞信已经退出历史舞台,不再有人使用
189/139:发送邮箱邮件至邮箱,邮箱将短信转到用户手机短信,存在一定的延迟
微信:需要申请一个微信公众号,并接入API,整个流程比较复杂,而且存在会话时间限制
短信:众多短信网关收费不同、稳定性也不确定,需要通过API接入
3.传统告警 VS OneAlert
在整个使用过程中,得出了传统告警方式的不足以及给个了 OneAlert 告警的功能,具体如下:
3.1 传统告警方式的不足
Zabbix 邮件告警经常发不出去
如需短信告警,要么购买短信猫要么购买短信 API,整个流程太麻烦
微信告警需要申请公众号以及 API 接入,而且会话有时间限制
夜间的告警基本成为一个摆设,试问谁能被微弱的短信声叫醒
阿里云、腾讯云、Zabbix 各种系统告警都需要单独配置,工作繁琐
普遍缺少告警分析
139/189 发送告警存在明显的延迟
3.2 onealert告警功能
告警 All In One,支持微信、邮箱、短信、APP、电话告警
支持接入 Zabbix、Nagios、阿里云、腾讯云、监控宝等等告警信息
灵活的分配策略,可灵活的分配告警信息发送给相关人员
微信、邮箱、app 等告警方式全部免费
实验环境
localhost:(server端) 172.25.24.1 linx7.3
server2 (agent端) 172.25.24.2 linux6.5
配置网络使虚拟机可以上网
物理机:
[root@foundation24 zabbix]# iptables -t nat -I POSTROUTING -s 172.25.24.0/24 -j MASQUERADE
localhost:
root@localhost zabbix]# route add default gw 172.25.24.250
[root@localhost zabbix]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.24.250 0.0.0.0 UG 0 0 0 eth0
172.25.24.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@localhost zabbix]# vim /etc/resolv.conf
nameserver 114.114.114.114
[root@localhost zabbix]# ping www.baidu.com
PING www.baidu.com (183.232.231.173) 56(84) bytes of data.
64 bytes from 183.232.231.173 (183.232.231.173): icmp_seq=1 ttl=53 time=101 ms
64 bytes from 183.232.231.173 (183.232.231.173): icmp_seq=2 ttl=53 time=123
配置zabbix-server
[root@localhost zabbix]# vim /etc/zabbix/zabbix_server.conf ##默认地址
安装oneitsm_zabbix_release并创建连接
必须在系列路径中进行安装,这是zabbix-server配置文件中指定的位置
[root@localhost zabbix]# cd /usr/lib/zabbix/alertscripts/
[root@localhost alertscripts]# ls
oneitsm_zabbix_release-1.2.0.tar.g
[root@localhost alertscripts]# tar zxf oneitsm_zabbix_release-1.2.0.tar.gz
[root@localhost alertscripts]# cd oneitsm
[root@localhost oneitsm]# ls
bin logs release update
[root@localhost oneitsm]# cd bin/ ##oneitsm连接脚本位置
在浏览器添加zabbix
创建zabbix会有一个key ,这个key是用来连接zabbix和onealert的钥匙
使用生成的key来建立连接
[root@localhost bin]# ./install.sh ce7f5ae4-b136-6dbf-6fb9-b18d8cf5d838
./log.sh: line 6: /usr/lib/zabbix/alertscripts/oneitsm/bin/oneitsm.conf: No such file or directory
start to create config file...
Zabbix管理地址: http://172.25.24.1/zabbix
Zabbix管理员账号: Admin
Zabbix管理员密码: ##密码是用来登陆zabbix的密码
start to auth by zabbix admin user and password...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 195 100 70 100 125 473 845 --:--:-- --:--:-- --:--:-- 844
auth success!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 109 100 41 100 68 958 1589 --:--:-- --:--:-- --:--:-- 1619
start to create mediatype...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 356 100 56 100 300 760 4073 --:--:-- --:--:-- --:--:-- 4109
create media type success!
start to create user group...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 214 100 54 100 160 772 2289 --:--:-- --:--:-- --:--:-- 2318
create user group success!
start to create user in zabbix...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 623 100 51 100 572 348 3909 --:--:-- --:--:-- --:--:-- 3917
create user success!
start to create action...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2013 100 51 100 1962 249 9611 --:--:-- --:--:-- --:--:-- 9617
create action success!
安装成功.
在浏览器zabbix
查看动作
关闭agent报警媒介 ,留下onelism的
查看用户如下,oneltsm有超级管理员权限
测试开始:
Server2停止zabbix-agent服务
[root@server2 bin]# /etc/init.d/zabbix-agent stop
Shutting down Zabbix agent:
过一段时间
同时伴随着你的设置来进行微信或者电话等,不间断通知,由于无法截图就不再此叙述了。
onealert上
重新开启zabbix-agent
[root@server2 bin]# /etc/init.d/zabbix-agent start
Starting Zabbix agent:
查看zabbix(问题已解决)
查看onealert(问题已解决)
Server3 利用zabbix-haproxy 分担server端压力(主动模式)
root@server3 ~]# yum install zabbix-proxy-mysql-3.4.6-1.el6.x86_64.rpm fping-2.4b2-16.el6.x86_64.rpm -y
[root@server3 zabbix]# yum install -y mysql-server
[root@server3 ~]# cd /etc/zabbix/
[root@server3 zabbix]# ls
zabbix_agentd.conf zabbix_agentd.d zabbix_proxy.conf
[root@server3 zabbix]# vim zabbix_proxy.conf
添加用户和表
[root@server3 zabbix]# /etc/init.d/mysqld start
mysql> create database zabbix_proxy character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix_proxy.* to zabbix@localhost identified by 'westos';
Query OK, 0 rows affected (0.00 sec)
添加zabbix库
[root@server3 zabbix-proxy-mysql-3.4.6]# pwd
/usr/share/doc/zabbix-proxy-mysql-3.4.6
[root@server3 zabbix-proxy-mysql-3.4.6]# zcat schema.sql.gz | mysql -u zabbix -p zabbix_proxy
Enter password:
配置zabbix-proxy
[root@server2 ~]# vim /etc/zabbix/zabbix_agentd.conf
开启zabbix-proxy
root@server2 ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [ OK ]
Starting Zabbix agent: [ OK ]