zabbix组件:abbix Server、Zabbix Proxy、Zabbix Agent。

zabbix Server组件:WEB GUI、Database、zabbix server。

运行平台:Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

主要功能:通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能。能监视各种网络参数,保证服务器系统的安全运营,提供灵活的通知机制以让系统管理员快速定位存在的各种问题。


zabbix可实现的功能模块 zabbix工作原理_mysql

每个模块工作职责:

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

Database Storage:用户存储所有配置信息,以及存储由Zabbix Server收集到的数据;

Web Interface:Zabbix的GUI接口,通常与Server运行在同一台主机上;

Zabbix Proxy:常用于分布监控环境中,代理Server收集部分被监控的监控数据并统一发往Server端;(通常大于500台主机需要使用)

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




zabbix可实现的功能模块 zabbix工作原理_zabbix可实现的功能模块_02


Zabbix监控原理:

Agentd安装在被监控的主机上,Agent负责定期收集客户端本地各项数据,并发送至Zabbix Server端,Zabbix Server收到数据,将数据存储到数据库中,用户基于Zabbix WEB可以看到数据在前端展现图像。当Zabbix监控某个具体的项目,改项目会设置一个触发器阈值,当被监控的指标超过该触发器设定的阈值,会进行一些必要的动作,动作包括:发送信息(邮件、微信、短信)、发送命令(SHELL 命令、Reboot、Restart、Install等)。


Zabbix监控部署在系统中,包含常见的五个程序:zabbix_server、zabbix_agentd、zabbix_proxy、zabbix_get、zabbix_sender等。

五个程序的功能如下:

zabbix server:zabbix服务端守护进程,其中zabbix_agentd、zabbix_get、zabbix_sender、zabbix_proxy的数据最终都提交给zabbix server;

zabbix agentd:客户端守护进程,负责收集客户端数据,例如:收集cpu负载、内存、硬盘使用情况等;

zabbix proxy:zabbix分布式代理守护进程,通过大于500台主机,需要进行分布式监控架构部署;

zabbix get:zabbix数据接收工具,单独使用的命令,通常在server或者proxy端执行获取远程客户端信息的命令;

zabbix sender:zabbix数据发送工具,用户发送数据给server或proxy端,通常用户耗时比较长的检查。

Zabbix监控方式

Zabbix分布式监控系统监控客户端的方式常见有三种:Agent、SNMP、IPMI。

Agent:Zabbix可以基于自身zabbix_agent客户端插件监控OS的状态,例如CPU、内存、硬盘、网卡、文件等。

SNMP:Zabbix通过简单网络管理协议(Simple Network Management Protocol)监控网络设备或windows主机等。通过设定SNMP的参数将相关监控数据传送至服务端,交换机、防火墙等网络设备一般都支持SNMP协议。

IPMI:智能平台管理接口(Intelligent Platform Management Interface,IPMI)即主要应用于设备的物理特性,包括:温度、电压、电扇工作状态,电源供应以及机箱入侵等。IPMI最大的优势在于无论OS的开机还是关机状态下,只要接通电源就可以实现对服务器的监控。

Zabbix监控客户端分为主动监控与被动监控,主被动模式以客户端为参照,Zabbix监控客户端默认为被动模式,可以修改为主动模式,只需要在客户端配置文件中添加 StartAgents=0。主被动监控模式如下:

Zabbix主动模式:Agent主动请求server获取主动的监控项列表,并主动将监控项内需要检测的数据提交给server/proxy,zabbix agent首先向ServerActive配置的IP请求获取active items,获取并提交active items数据至server/proxy。

Zabbix被动模式:Server向agent请求获取监控项的数据,agent返回数据,server打开一个TCP连接,Server发送请求agent.ping,Agent接收到请求并且响应,Server处理接收到的数据。

Zabbix监控概念

Zabbix监控系统包括很多监控概念,如下:

主机(host):                     被监控的网络设备,可以写IP或者DNS;

主机组(host group):        主机组用于管理主机,可以批量设置权限;

监控项(item):                 具体监控项,items值由独立的keys进行识别;

触发器(trigger):             为某个items设置触发器,达到触发器会执行action动作;

事件(event):                  例如达到某个触发器,称之为一个事件;

动作(action):                 对于特定事件事先定义的处理方法,默认可以发送信息及发送命令;

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

媒介(media):                 发送通知的方式,可以支持Mail、SMS、Scripts等;

通知(notification):         通过设置的媒介向用户发送的有关某事件的信息;

远程命令                达到触发器,可以在被监控端执行命令;

模板(template):              可以快速监控被监控端,模块包含:item、trigger、graph、screen、application;

web场景(web scennario)用于检测web站点可用性,监控HTTP关键词;

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

图形(graph)                    监控图像;

屏幕(screens)                  屏幕显示;

幻灯(slide show)             幻灯显示





zabbix 可以使用apache+zabbix+mysql,或者nginx+zabbix+mysql 安装。



nginx+zabbix+mysql安装 :

使用yum来安装相关的软件包

yum install -y gcc make cmake php php-gd php-devel php-mysql php-bcmath php-ctytpe php-xml php-xmlreader php-xlmwriter php-session php-net-socket php-mbstring php-gettext httpd net-snmp curl curl-devel net-snmp net-snmp-devel perl-DBI

安装3.0以上的zabbix,需要使用Php5.6以上的版本,如果使用Yum安装就必需清除之前的版本。

yum remove php*
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64

添加yum源

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

yum 安装 php5.6

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64
yum -y install  php-xml php-xmlreader php-xlmwriter
yum -y install php56w-bcmath.x86_64





创建用户zabbix:

useradd -M -s /sbin/nologin zabbix

安装mysql:

[root@zabbix_3.0 tools]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz [root@zabbix_3.0 tools]# mv mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32[root@zabbix_3.0 tools]# ln -s /application/mysql-5.5.32/ /application/mysql
[root@zabbix_3.0tools]# useradd mysql -s /sbin/nologin -M[root@zabbix_3.0 tools]# chown -R mysql.mysql /application/mysql 
[root@zabbix_3.0 tools]# cd /application/mysql
vim /etc/hosts[root@zabbix_3.0 mysql]# ./scripts/mysql_install_db  --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
 cp support-files/my-small.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
 source /etc/profile
[root@zabbix_3.0 application]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

在mysql创建zabbix账号,并授权给用户zabbix权限。

mysql> use mysql;  
mysql>create database zabbix character set utf8;  
mysql>grant all privileges on zabbix.* to nmc@'192.168.136.144' identified by 'nmc123';


解压zabbix压缩包,我下载的zabbix3.2版本,zabbix-3.2.0.tar.gz。 解压后,我们进入database/mysql 目录,这个目录下有3个sql,我们需要导入到 mysql的 zabbix数据库中。注意有先后顺序,否则会报错


#mysql -uroot -pnmc123 zabbix < schema.sql  
#mysql -uroot -pnmc123 zabbix < images.sql  
#mysql -uroot -pnmc123 zabbix < data.sql



执行完成并且没有报告错误后 ,我们可以登录数据库查询一下是否建立库表,用show tables命令查看库表。如下图

[root@mock prod]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 74170
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |



修改php参数:

vi /etc/php.ini
[PHP]
always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai
engine = On
short_open_tag = Off
asp_tags = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 32M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
"/etc/php.ini" 172L, 3730C

主要参数:

date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 2

always_populate_raw_post_data = -1

修改php指定使用账号:

[root@mock ~]# cat /etc/php-fpm.d/www.conf | grep -v "^;" | grep -v "^$"
[www]
listen = 127.0.0.1:9000
 
listen.allowed_clients = 127.0.0.1
user = prod
group = prod
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache

zabbix配置文件:

vim /usr/local/zabbix/etc/zabbix_server.conf
DBHost=192.168.136.144
DBName= zabbix
DBUser=zabbixuser
DBPassword=zabbixpass
StartPollers=30                         #开启多线程数,一般不要超过30个
StartTrappers=20                        #trapper线程数
StartPingers=10                         #fping线程数
StartDiscoverers=120            
MaxHousekeeperDelete=5000       
CacheSize=1024M                         #用来保存监控数据的缓存数,根据监控主机的数量适当调整
StartDBSyncers=8                        #数据库同步时间
HistoryCacheSize=1024M          
TrendCacheSize=128M                     #总趋势缓存大小
HistoryTextCacheSize=512M
AlertScriptsPath=/etc/zabbix/alertscripts
LogSlowQueries=1000

然后,将zabbix的页面文件copy到指定目录

cp /home/prod/zabbix-3.2.11/frontends/php/*   /home/prod/nginx/html/zabbix/

nginx相关配置:

server {
        listen       8001;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/prod/nginx/html;
            index  index.html index.htm index.php;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /home/prod/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           # fastcgi_param  SCRIPT_FILENAME /home/prod/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;

启动zabbix

输入URL   http://192.168.136.144/zabbix/setup.php    #进行安装 

zabbix可实现的功能模块 zabbix工作原理_数据_03

安装完成后:

输入:http://IP地址:端口号/zabbix


zabbix/sbin/zabbix_server -c /home/prod/zabbix/zabbix_server.conf

zabbix可实现的功能模块 zabbix工作原理_php_04