Zabbix安装配置详解

  1. 云栖社区>
  2. 博客>
  3. 正文

Zabbix安装配置详解

技术小胖子 2017-11-08 07:38:00 浏览2078

一、Zabbix组件概述

1、Zabbix Server:负责接收agent发送的报告信息的核心组件,所有配置,统计数据及操作数据均由其组织进行;

2、Database Storage:专用于存储所有配置信息,以及由zabbix收集的数据;

3、Web interface:zabbix的GUI接口,通常与Server运行在同一台主机上;

4、Proxy:可选组件,常用于分布监控环境中,代理Server收集部分被监控端的监控数据并统一发往Server端;

5、Agent:部署在被监控主机上,负责收集本地数据并发往Server端或Proxy端;


二、Zabbix常用术语

1、主机(host):要监控的网络设备,可由IP或DNS名称指定;

2、主机组(host group):主机的逻辑容器,可以包含主机和模板,但同一个组织内的主机和模板不能互相链接;主机组通常在给用户或用户组指派监控权限时使用;

3、监控项(item):一个特定监控指标的相关的数据;这些数据来自于被监控对象;item是zabbix进行数据收集的核心,相对某个监控对象,每个item都由"key"标识;

4、触发器(trigger):一个表达式,用于评估某监控对象的特定item内接收到的数据是否在合理范围内,也就是阈值;接收的数据量大于阈值时,触发器状态将从"OK"转变为"Problem",当数据再次恢复到合理范围,又转变为"OK";

5、事件(event):触发一个值得关注的事情,比如触发器状态转变,新的agent或重新上线的agent的自动注册等;

6、动作(action):指对于特定事件事先定义的处理方法,如发送通知,何时执行操作;

7、报警升级(escalation):发送警报或者执行远程命令的自定义方案,如每隔5分钟发送一次警报,共发送5次等;

8、媒介(media):发送通知的手段或者通道,如Email、Jabber或者SMS等;

9、通知(notification):通过选定的媒介向用户发送的有关某事件的信息;

10、远程命令(remote command):预定义的命令,可在被监控主机处于某特定条件下时自动执行;

11、模板(template):用于快速定义被监控主机的预设条目集合,通常包含了item、trigger、graph、screen、application以及low-level discovery rule;模板可以直接链接至某个主机;

12、应用(application):一组item的集合;

13、web场景(web scennario):用于检测web站点可用性的一个活多个HTTP请求;

14、前端(frontend):Zabbix的web接口;


三、实验环境

192.168.30.116 OS:CentOS 6.4 x86_64   zabbix_server.luojianlong.com

192.168.30.117 OS:CentOS 6.4 x86_64   node1.luojianlong.com

192.168.30.119 OS:CentOS 6.4 x86_64   node2.luojianlong.com

需要的软件包:

zabbix-2.0.8-3.el6.x86_64.rpm

zabbix-get-2.0.8-3.el6.x86_64.rpm

zabbix-server-2.0.8-3.el6.x86_64.rpm

zabbix-server-mysql-2.0.8-3.el6.x86_64.rpm

zabbix-web-2.0.8-3.el6.noarch.rpm

zabbix-web-mysql-2.0.8-3.el6.noarch.rpm


wKiom1NM3paSLQdhAAEomij9sZ4516.jpg


首先安装zabbix server端

1
2
3
4
5
6
7
8
# 设置epel源
[root@zabbix_server ~]# cat /etc/yum.repos.d/epel.repo
[epel]
name=epel
baseurl=http://mirrors.sohu.com/fedora-epel/6/x86_64/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/fedora-epel/RPM-GPG-KEY-EPEL-6
[root@zabbix_server ~]# yum -y localinstall zabbix-2.0.8-3.el6.x86_64.rpm zabbix-get-2.0.8-3.el6.x86_64.rpm zabbix-server-2.0.8-3.el6.x86_64.rpm zabbix-server-mysql-2.0.8-3.el6.x86_64.rpm zabbix-web-2.0.8-3.el6.noarch.rpm zabbix-web-mysql-2.0.8-3.el6.noarch.rpm


在zabbix server上安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@zabbix_server ~]# useradd mysql -r
[root@zabbix_server ~]# tar zxvf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[root@zabbix_server ~]# ln -s /usr/local/mysql-5.5.33-linux2.6-x86_64 /usr/local/mysql
[root@zabbix_server ~]# cd /usr/local/mysql
[root@zabbix_server mysql]# mkdir /mydata/data -p
[root@zabbix_server mysql]# chown -R root.mysql ./*
[root@zabbix_server mysql]# chown -R mysql.mysql /mydata/data/
[root@zabbix_server mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@zabbix_server mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@zabbix_server mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@zabbix_server mysql]# chkconfig --add mysqld
[root@zabbix_server mysql]# chkconfig mysqld on
[root@zabbix_server mysql]# vi /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@zabbix_server mysql]# . /etc/profile.d/mysql.sh
[root@zabbix_server mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
[root@zabbix_server mysql]# vi /etc/my.cnf
datadir = /mydata/data
innodb_file_per_table = 1
[root@zabbix_server mysql]# service mysqld start
Starting MySQL...... SUCCESS!


创建zabbix数据库,并导入表

1
2
3
4
5
6
7
8
9
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON zabbix.* TO zbuser@'192.168.30.%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@zabbix_server ~]# mysql -u zbuser -p123456 -h 192.168.30.116 zabbix < /usr/share/doc/zabbix-server-mysql-2.0.8/create/schema.sql
[root@zabbix_server ~]# mysql -u zbuser -p123456 -h 192.168.30.116 zabbix < /usr/share/doc/zabbix-server-mysql-2.0.8/create/images.sql
[root@zabbix_server ~]# mysql -u zbuser -p123456 -h 192.168.30.116 zabbix < /usr/share/doc/zabbix-server-mysql-2.0.8/create/data.sql


修改zabbix_server.conf配置文件

1
2
3
4
5
[root@zabbix_server ~]# vi /etc/zabbix/zabbix_server.conf
# 修改
DBHost=192.168.30.116
DBUser=zbuser
DBPassword=123456


启动zabbix_server

1
2
3
4
5
[root@zabbix_server ~]# service zabbix-server start
Starting Zabbix server:                                    [  OK  ]
[root@zabbix_server ~]# ss -anptl | grep zabbix
LISTEN     0      128                      :::10051                   :::*      users:(("zabbix_server",19539,5),("zabbix_server",19541,5),("zabbix_server",19542,5),("zabbix_server",19543,5),("zabbix_server",19544,5),("zabbix_server",19545,5),("zabbix_server",19546,5),("zabbix_server",19547,5),("zabbix_server",19548,5),("zabbix_server",19549,5),("zabbix_server",19550,5),("zabbix_server",19552,5),("zabbix_server",19554,5),("zabbix_server",19555,5),("zabbix_server",19557,5),("zabbix_server",19559,5),("zabbix_server",19562,5),("zabbix_server",19563,5),("zabbix_server",19566,5),("zabbix_server",19567,5),("zabbix_server",19569,5),("zabbix_server",19570,5),("zabbix_server",19572,5),("zabbix_server",19574,5),("zabbix_server",19576,5),("zabbix_server",19577,5),("zabbix_server",19580,5))
LISTEN     0      128                       *:10051                    *:*      users:(("zabbix_server",19539,4),("zabbix_server",19541,4),("zabbix_server",19542,4),("zabbix_server",19543,4),("zabbix_server",19544,4),("zabbix_server",19545,4),("zabbix_server",19546,4),("zabbix_server",19547,4),("zabbix_server",19548,4),("zabbix_server",19549,4),("zabbix_server",19550,4),("zabbix_server",19552,4),("zabbix_server",19554,4),("zabbix_server",19555,4),("zabbix_server",19557,4),("zabbix_server",19559,4),("zabbix_server",19562,4),("zabbix_server",19563,4),("zabbix_server",19566,4),("zabbix_server",19567,4),("zabbix_server",19569,4),("zabbix_server",19570,4),("zabbix_server",19572,4),("zabbix_server",19574,4),("zabbix_server",19576,4),("zabbix_server",19577,4),("zabbix_server",19580,4))


修改php时区

1
2
3
4
[root@zabbix_server ~]# vi /etc/php.ini
# 启动并修改
date.timezone = Asia/Shanghai
[root@zabbix_server ~]# service httpd restart

打开浏览器访问http://192.168.30.116/zabbix

wKiom1NM62DDhyVFAAa_6ZCbH2w470.jpg


点击Next


wKioL1NM62zQuc0TAAeY77Bh2VM144.jpg


检测都正常,Next


wKiom1NM69XTppvoAAdlH4rdv7c159.jpg


连接数据库正常,Next

wKioL1NM6-Gi6f5mAAdMPIl4gHI257.jpg


设置zabbix server 名称端口,Next

wKiom1NM7EWDzmkWAAesbLyUHgQ660.jpg


Next

wKioL1NM7D_iR6JrAAakQveHYAA928.jpg


Next

wKioL1NM7G_ho_G2AAiXRv7igPE338.jpg


登录,默认账号Admin,密码:zabbix

wKioL1NM7MLiMEirAAiNIFDKplY139.jpg




下面开始安装zabbix agent,先登录node1安装

1
2
3
4
5
6
7
8
# 设置epel源
[root@node1 yum.repos.d]# cat epel.repo
[epel]
name=epel
baseurl=http://mirrors.sohu.com/fedora-epel/6/x86_64/
gpgcheck=1
gpgkey=http://mirrors.sohu.com/fedora-epel/RPM-GPG-KEY-EPEL-6
[root@node1 ~]# yum -y localinstall zabbix-2.0.8-3.el6.x86_64.rpm zabbix-agent-2.0.8-3.el6.x86_64.rpm zabbix-sender-2.0.8-3.el6.x86_64.rpm


修改agent配置文件

1
2
3
[root@node1 ~]# vi /etc/zabbix/zabbix_agentd.conf
# 修改
Server=192.168.30.116


启动agent

1
2
3
4
5
[root@node1 ~]# service zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@node1 ~]# ss -antp | grep zabbix
LISTEN     0      128                      :::10050                   :::*      users:(("zabbix_agentd",18997,5),("zabbix_agentd",18999,5),("zabbix_agentd",19000,5),("zabbix_agentd",19001,5),("zabbix_agentd",19002,5),("zabbix_agentd",19003,5))
LISTEN     0      128                       *:10050                    *:*      users:(("zabbix_agentd",18997,4),("zabbix_agentd",18999,4),("zabbix_agentd",19000,4),("zabbix_agentd",19001,4),("zabbix_agentd",19002,4),("zabbix_agentd",19003,4))


添加监控主机


点击Configuration里面Hosts


wKiom1NM7-ywuWxTAAO98hZG3JQ694.jpg


点击creat host


wKiom1NM8GjidyzvAAQkVaNP9Jk878.jpg


添加hostname ,visiable name 属于的group,agent interfaces,然后保存

wKioL1NM8JLhUnq_AASCSKmaWNY483.jpg


添加成功


接着,为添加host创建item,点击item

wKiom1NM8QjhznoYAAPcHi4CRYI574.jpg


点击create item

wKioL1NM8cTQ17AmAALjgek4XCc228.jpg


添加item名称,类型为agent,key选择为网卡eth0出去的流量,添加监控的时间段为周一到周七每天的00:00-24:00,没隔10分钟采集一次数据,store value:选择为Delta(speed per second),后面采集到的减去前面采集到的数据,新建 NetTraffic应用,然后保存


Delta (speed per second):保存为(value-prev_value)/(time-prev_time的计算结果,即当前值减去前一次获取的数据值,除以当前时间戳减去前一次值获取时的时间戳得到的结果;如果当前值小于前一次的值,其将会被丢弃;

Delta (simple change):保存为 (value-prev_value)的计算结果;




wKiom1NM807AUwbdAARHgYhY6-g740.jpg


每新建一个item,会自动创建一个graph,可以在Monitoring ---> Latest data下面看到

wKioL1NM8_rxaAXrAAOBccaKks0615.jpg


wKiom1NM9FmDMsEbAAWvhZUsA04580.jpg


如上步骤,继续新建一个item为eth0入站的流量


wKioL1NM9PbQ_7deAATYYCu4syQ962.jpg


接下来创建自定义graph,点击configration--->host--->grap-->create graph

wKioL1NM9cXRAA6NAAPwRyIgRBo113.jpg


添加关联的item

wKioL1NM9iGjbgxeAAJUll0CacM015.jpg


选择图形样式

wKiom1NM9pPBb4RrAAPooN7yGHY122.jpg


保存,在Monitoring的graph中可以看到,刚才新建的2个item的graph显示在了一个graph中

wKiom1NM9zqClzEuAAZA0mmApqc905.jpg



创建trigger触发器

点击configuration-->host->node1.luojianlong-->triggers-->create trigger

wKiom1NM-HWDxYMeAAL-Em88fJg555.jpg


添加trigger名称


点击add,添加表达式

wKioL1NM-R3xOEzvAARBzqA-hXI027.jpg


指定最后一次采集的值大于1024的,点击insert

wKioL1NM-VqhQIXPAANoz3NV1gw219.jpg


选择,事件类型为High,然后保存

wKiom1NM-e3jnqgeAAMuPtItbWM420.jpg

看到新创建的trigger

wKiom1NM-yKztyR6AAO4eUMqj2g929.jpg



在node1上下载数据,测试trigger效果

1
[root@node1 ~]# wget ftp://rpmfind.net/linux/fedora-secondary/updates/20/ppc64/puppet-3.4.2-1.fc20.noarch.rpm




查看graph

wKioL1NM-97wzTY8AAQbbs8TOqE115.jpg


wKioL1NM_CCzApeuAAPEDNiOofA967.jpg


发现trigger生效


下面创建media媒介,点击Administration-->Media types-->create media type


wKiom1NM_XaAT6X2AAM_HcJMDKQ329.jpg


保存,并禁用其他media

wKioL1NN10vBJJOnAARasOvj7zg369.jpg





创建用户,用户组

wKiom1NM_9Kx4y7fAAOEaz47tkA781.jpg


wKioL1NNAPyQJbAXAAJ1vq77dQA725.jpg


添加Tom用户的media

wKiom1NNAHbh3UonAAMDwC6KFm4703.jpg


定义Admin用户的media

wKioL1NN1sOgACfSAAN5wu_5WDg709.jpg




下面创建action,点击Configuration-->Action-->Create action

wKioL1NM_f2SPhmfAAQ5whhQfdw176.jpg


Default operation step duration:定义隔多长时间报警升级;

Default subject:默认的发送主题;

Default message:默认发送邮件内容;

Recovery message:是否启用恢复通知;

Recovery subject:恢复通知主题;

Recovery message:恢复通知邮件内容;






然后继续创建,触发action后真正要做的操昨,Operations



wKiom1NNAjixgI5iAAN2DGZ7EKI799.jpg


只要触发一次,就向Admin用户发邮件

wKioL1NNAuzDz9VpAAM5SkeqHJ0070.jpg


触发10次,问题还没有解决,发送给TOM,报警升级


定义conditions,选择之前定义trigger

wKiom1NNA5jQuAwqAAQVppIxtq4719.jpg


wKioL1NNA5iCy7TaAARz51aDa54104.jpg


看到新建的action已经启用


测试报警功能,在node1上,下载文件

1
[root@node1 ~]# wget http://mirrors.163.com/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD2.iso


在zabbix_server上看是否收到邮件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost ~]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 11 messages 7 new 8 unread
    1 logwatch@zabbix_serv  Fri Jan 10 10:45 247/9293  "Logwatch for zabbix_server.luojianlong.com (Linux)"
    2 logwatch@zabbix_serv  Tue Apr 15 17:36  42/1528  "Logwatch for zabbix_server.luojianlong.com (Linux)"
 U  3 logwatch@zabbix_serv  Wed Apr 16 03:42 105/3180  "Logwatch for zabbix_server.luojianlong.com (Linux)"
    4 root                  Wed Apr 16 08:54 1590/69736 "1234"
>N  5 zabbix@localhost.loc  Wed Apr 16 08:55  23/1058  "PROBLEM: Network Inbound Traffic trigger"
 N  6 zabbix@localhost.loc  Wed Apr 16 08:56  23/1058  "PROBLEM: Network Inbound Traffic trigger"
 N  7 zabbix@localhost.loc  Wed Apr 16 08:57  23/1058  "PROBLEM: Network Inbound Traffic trigger"
 N  8 zabbix@localhost.loc  Wed Apr 16 08:58  22/1040  "OK: Network Inbound Traffic trigger"
 N  9 zabbix@localhost.loc  Wed Apr 16 08:59  22/1040  "OK: Network Inbound Traffic trigger"
 N 10 zabbix@localhost.loc  Wed Apr 16 09:00  22/1040  "OK: Network Inbound Traffic trigger"
 N 11 zabbix@localhost.loc  Wed Apr 16 09:01  22/1040  "OK: Network Inbound Traffic trigger"


发现都到报警邮件


定义模板,点击Configuration-->Template-->Create Template

wKioL1NN2eeDPl3NAAIkgH61sEc540.jpg


点击Macros,定义宏

wKiom1NN2k_iT6KgAAMx9iDJ6Qw788.jpg


已经创建好模板

wKioL1NN2oiz07q5AAVLTCtinAQ775.jpg


给模板定义item

wKiom1NN2zXhzFCbAAPu0VhdLAw864.jpg


wKiom1NN24Px5uNuAANH9311pwg273.jpg


wKiom1NN26eDWFWBAAS5aWI91oQ780.jpg



给模板创建graph

wKiom1NN2_XBVt7iAAQS_UCv1o0423.jpg


wKioL1NN2-3zk40aAAPo5uLZpxA643.jpg




使用模板快速添加node2节点

1
2
3
4
5
6
7
8
[root@node2 ~]# yum -y localinstall zabbix-2.0.8-3.el6.x86_64.rpm zabbix-sender-2.0.8-3.el6.x86_64.rpm zabbix-agent-2.0.8-3.el6.x86_64.rpm
[root@node2 ~]# vi /etc/zabbix/zabbix_agentd.conf
Server=192.168.30.116
[root@node2 ~]# service zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@node2 ~]# ss -antpl | grep zabbix
LISTEN     0      128                      :::10050                   :::*      users:(("zabbix_agentd",10486,5),("zabbix_agentd",10488,5),("zabbix_agentd",10489,5),("zabbix_agentd",10490,5),("zabbix_agentd",10491,5),("zabbix_agentd",10492,5))
LISTEN     0      128                       *:10050                    *:*      users:(("zabbix_agentd",10486,4),("zabbix_agentd",10488,4),("zabbix_agentd",10489,4),("zabbix_agentd",10490,4),("zabbix_agentd",10491,4),("zabbix_agentd",10492,4))


打开浏览器添加host

wKioL1NN3e7gQnAAAAN1OM6EucY900.jpg


点击Templates,选择关联刚才创建的for test servers模板

wKioL1NN3teT9t6LAAKy7z49AZM726.jpg



wKioL1NN3zuBsC3fAAQ-GxrkMTA369.jpg


发送node2已经使用了创建的模板,并且有2个item,1个graph


为模板创建trigger

wKioL1NN4JrBmSaHAAPC-NG64E8726.jpg


wKiom1NN4OGzEZ0OAAMR6SP3WDg163.jpg


wKiom1NN4QiBXm87AATP4sM1Ris898.jpg


发现node2已经自动创建了trigger








     本文转自ljl_19880709 51CTO博客,原文链接:http://blog.51cto.com/luojianlong/1395828,如需转载请自行联系原作者