一、 zabbix简介:
zabbix是完全开源的工具,整合了cacti和nagios等特性
cacti:snmp
nagios:linux主机:nrpe 设备:snmp
附:SNMP(udp 161 udp 162)
众多网络工具都支持此协议,比如常见路由交换,常见OS
其既可以做管理端也可以做被管理端
snmp协议大致有3个版本分别是v1 v2 v3
无论是v1 和 v2 的安全性是比较差的,因为传输是明文的, V3的认证密码用MD5/SHA摘要算法加密
很多工具支持网络管理的功能,而对于非网络设备(操作系统),可以完全抛开snmp这种不安全的架构来实现监控的。所以很多工具都是控制端和agent架构,他们有专属的agent
Zabbix的主要功能:
具备常见的商业监控软件所具备的功能(主机的性能监控、网络设备性能监控、数据库、FTP 等通用协议监控、多种告警方式、详细的报表图表绘制)
支持自动发现网络设备和服务器(可以通过配置自动发现服务器规则来实现)
支持分布式,能集中展示、管理分布式的监控点,扩展性强
server 提供通用接口(api 功能),可以自己开发完善各类监控(根据相关接口编写程序实现),编写插件容易,可以自定义监控项,报警级别的设置。
数据收集,支持 snmp(包括 trapping and polling ),IPMI,JMX,SSH,TELNET;
自定义的检测;自定义收集数据的频率;
服务器/代理和客户端模式;
灵活的触发器;可以定义非常灵活的问题阈值,称为触发器;
高可定制的报警;发送通知,可定制的报警升级,收件人,媒体类型。
CPU负荷、内存使用、磁盘使用、网络状况、端口监视、日志监视等等。
硬件监控:Zabbix IPMI Interface
系统监控:Zabbix Agent Interface
Java监控:Zabbix JMX Interface
网络设备监控:Zabbix SNMP Interface
应用服务监控:Zabbix Agent UserParameter
MySQL数据库监控:percona-monitoring-plulgins
URL监控:Zabbix Web 监控
zabbix重要组件说明:
1)zabbix server:负责接收agent发送的报告信息的核心组件,所有配置、统计数据及操作数据都由它组织进行;
2)database storage:专用于存储所有配置信息,以及由zabbix收集的数据;
3)web interface:zabbix的GUI接口;
4)proxy:可选组件,常用于监控节点很多的分布式环境中,代理server收集部分数据转发到server,可以减轻server的压力;
5)agent:部署在被监控的主机上,负责收集主机本地数据如cpu、内存、数据库等数据发往server端或proxy端;
另外,zabbix server、proxy、agent都有自己的配置文件以及log文件,重要的参数需要在这里配置,后面会详细说明。
一个监控系统运行的大概的流程是这样的:
agentd需要安装到被监控的主机上,它负责定期收集各项数据,并发送到zabbix server端,zabbix server将数据存储到数据库中,zabbix web根据数据在前端进行展现和绘图。这里agentd收集数据分为主动和被动两种模式:
主动:agent请求server获取主动的监控项列表,并主动将监控项内需要检测的数据提交给server/proxy
被动:server向agent请求获取监控项的数据,agent返回数据。
zabbix常用的监控架构平台
1、server-agentd模式:
这个是最简单的架构了,常用于监控主机比较少的情况下。
2、server-proxy-agentd模式:
这个常用于比较多的机器,使用proxy进行分布式监控,有效的减轻server端的压力。
zabbix的系统架构:
Zabbix是一个基于Web界面的提供分布式系统监视以及网络监视功能的企业级开源解决方案。借助Zabbix,可以很轻松地减轻运维人员们繁重的服务器管理任务,实现业务系统的持续运行。下面会逐步介绍Zabbix分布式监控系统的部署及使用
配置好IP、DNS 、网关,确保使用远程连接工具能够连接服务器
zabbix监控服务器 #zabbix的服务端(若要监控本机,则需要配置本机的zabbix agent)
Zabbix agent被监控主机#zabbix的客户端(被监控端,需要配置Zabbix agent
二、Zabbix部署前的LNMP环境的搭建过程:
安装编译工具及库文件
yum -y install make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel
1、系统环境:centos7.2 x86_64
因为centos7.2默认安装了mariadb-libs,所以先要卸载掉
查看是否安装mariadb
#rpm -qa | grep mariadb
卸载mariadb
rpm -e --nodeps mariadb-libs
安装nginx:
解压zlib
1
2
|
[root@localhost src]# tar zxf zlib-
1.2
.
8
.tar.gz
[root@localhost src]# tar zxf pcre-
8.39
.tar.gz
|
不需要编译,只需要解压就行
1
2
|
[root@localhost src]# groupadd www
[root@localhost src]# useradd -g www www -s /sbin/nologin
|
下载nginx的源码包:http://nginx.org/download
解压源码包:
1
2
3
|
[root@localhost src]# tar zxf nginx-
1.10
.
2
.tar.gz
[root@localhost src]# cd nginx-
1.10
.
2
/
[root@localhost nginx-
1.10
.
2
]# ./configure --prefix=/usr/local/nginx1.
10
--
with
-http_dav_module --
with
-http_stub_status_module --
with
-http_addition_module --
with
-http_sub_module --
with
-http_flv_module --
with
-http_mp4_module --
with
-pcre=/usr/src/pcre-
8.39
--
with
-zlib=/usr/src/zlib-
1.2
.
8
--
with
-http_ssl_module --
with
-http_gzip_static_module --user=www --group=www
|
1
2
|
[root@localhost nginx-
1.10
.
2
]# make && make install
[root@localhost nginx-
1.10
.
2
]# ln -s /usr/local/nginx1.
10
/sbin/nginx /usr/local/sbin/
|
1
2
3
|
[root@localhost nginx-
1.10
.
2
]# nginx
[root@localhost nginx-
1.10
.
2
]# netstat -anpt | grep nginx
tcp
0
0
0.0
.
0.0
:
80
0.0
.
0.0
:* LISTEN
46471
/nginx: master
|
1
2
|
[root@mysqla ~]# firewall-cmd --permanent --add-port=
80
/tcp
[root@mysqla ~]# firewall-cmd --reload
|
启动后可以再浏览器中打开页面,会显示nginx默认页面。
安装php
1
|
[root@localhost libmcrypt-
2.5
.
7
]# ln -s /usr/local/mysql/lib/libmysqlclient.so.
20.3
.
0
/usr/local/mysql/lib/libmysqlclient_r.so
|
1
|
[root@localhost php-
5.6
.
27
]# ./configure --prefix=/usr/local/php5.
6
--
with
-config-file-path=/etc --
with
-mysql=/usr/local/mysql --
with
-mysqli=/usr/local/mysql/bin/mysql_config --
with
-mysql-sock=/usr/local/mysql/mysql.sock --
with
-gd --
with
-iconv --
with
-libxml-dir=/usr --
with
-mhash --
with
-mcrypt --
with
-config-file-scan-dir=/etc/php.d --
with
-bz2 --
with
-zlib --
with
-freetype-dir --
with
-png-dir --
with
-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-
native
-ttf --
with
-openssl --enable-pcntl --enable-sockets --
with
-xmlrpc --enable-zip --enable-soap --without-pear --
with
-gettext --enable-session --
with
-mcrypt --
with
-curl
|
1
2
|
[root@localhost php-
5.6
.
27
]# make && make install
[root@localhost php-
5.6
.
27
]# cp php.ini-production /etc/php.ini
|
找到:
;date.timezone =
修改为:
date.timezone = PRC #设置时区
找到:
expose_php = On
修改为:
expose_php = Off #禁止显示php版本的信息
找到:
short_open_tag = Off
修改为:
short_open_tag = On //支持php短标签
找到:
post_max_size = 8M
修改为:
post_max_size = 16M //上传文件大小
找到:
max_execution_time = 30
修改为:
max_execution_time = 300 //php脚本最大执行时间
找到:
max_input_time = 60
修改为:
max_input_time = 300 //以秒为单位对通过POST、GET以及PUT方式接收数据时间进行限制
always_populate_raw_post_data = -1
mbstring.func_overload = 0
1
2
3
4
|
[root@localhost php-
5.6
.
27
]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-
5.6
.
27
]# chmod +x /etc/init.d/php-fpm
[root@localhost php-
5.6
.
27
]# chkconfig --add php-fpm
[root@localhost php-
5.6
.
27
]# chkconfig php-fpm on
|
提供php-fpm配置文件并编辑:
1
|
[root@localhost php-
5.6
.
27
]# cp /usr/local/php5.
6
/etc/php-fpm.conf.
default
/usr/local/php5.
6
/etc/php-fpm.conf
|
pid = run/php-fpm.pid
user = www
group = www
listen =127.0.0.1:9000
pm.max_children = 300
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers =50
启动php-fpm服务:
1
2
3
4
|
[root@localhost php-
5.6
.
27
]# service php-fpm start
Starting php-fpm done
[root@localhost php-
5.6
.
27
]# netstat -anpt | grep php-fpm
tcp
0
0
127.0
.
0.1
:
9000
0.0
.
0.0
:* LISTEN
49041
/php-fpm: mast
|
配置nginx支持php
1
|
[root@localhost conf]# cat /usr/local/nginx1.
10
/conf/nginx.conf
|
user www www;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main 'remoteaddr−remote_user [timelocal]"request" '
# 'statusbody_bytes_sent "$http_referer" '
# '"httpuseragent""http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
#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;
}
location /status {
stub_status on;
}
}
}
1
2
3
|
[root@localhost conf]# nginx -t
nginx: the configuration file /usr/local/nginx1.
10
/conf/nginx.conf syntax
is
ok
nginx: configuration file /usr/local/nginx1.
10
/conf/nginx.conf test
is
successful
|
测试LNMP
进入nginx默认的网页根目录,创建.php的测试页
1
2
3
4
|
[root@mysqla ~]# cat /usr/local/nginx1.
10
/html/test1.php
<?php
phpinfo()
?>
|
访问结果
NMP部署完毕。 数据mysql已经提前配置好 博客也有安装mysql5.7文档
三、监控系统Zabbix-3.2.1的安装
zabbix-server端的操作
zabbix服务器端要提前安装好LNMP环境(mysql,nginx,php5的安装目录均是/usr/local)
创建Zabbix运行的用户:
1
2
|
[root@localhost conf]# groupadd zabbix
[root@localhost conf]# useradd -g zabbix zabbix
|
安装libcurl和net-snmp:
1
|
[root@localhost src]# yum -y install net-snmp* net-snmp-develcurl-develjava-
1.8
.
0
-openjdk java-
1.8
.
0
-openjdk-devel OpenIPMI-devel* libssh2-devel* java*
|
安装fping
1
2
3
4
|
[root@localhost src]# tar zxf fping-
3.12
.tar.gz
[root@localhost fping-
3.12
]# ./configure && make && make install
[root@localhost fping-
3.12
]# chown root:zabbix /usr/local/sbin/fping
[root@localhost fping-
3.12
]# chmod
4710
/usr/local/sbin/fping
|
安装Zabbix Server:
1
2
3
|
root@localhost src]# tar zxf zabbix-
3.2
.
1
.tar.gz
[root@localhost src]# cd zabbix-
3.2
.
1
/
[root@localhost zabbix-
3.2
.
1
]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --
with
-mysql=/usr/local/mysql/bin/mysql_config --
with
-net-snmp --
with
-libcurl --
with
-openipmi
|
注:编译时最好带上--enable-java这个参数,方便后续监控tomcat程序所用。
--with-ssh2 是不需要在客户端服务器上面安装Zabbix agent,如果需要使用ssh检查,需要在编译的时候加上这项,最低需要libssh2 1.0.0版本,需要安装ssh开发包
--with-openipmi用户可以利用 IPMI 监视服务器的物理特征,如温度、电压、电扇工作状态、电源供应等。
如果添加了--enable-proxy, 那么会生成get和sender两条命令. 如下, 用于接收agent发生过来的信息, 同时发送给server.
1
|
[root@localhost zabbix-
3.2
.
1
]# make && make install
|
添加系统软连接
1
2
|
[root@localhost zabbix-
3.2
.
1
]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
[root@localhost zabbix-
3.2
.
1
]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
|
Zabbix Server配置与启动
创建Zabbix数据库和MySQL用户:
1
2
|
create database zabbix character
set
utf8;
grant all privileges on zabbix.* to zabbix@localhost identified by
'zabbix'
;
|
导入Zabbix初始数据:
切换到zabbix的解压目录下
1
2
3
4
5
6
|
[root@localhost zabbix-
3.2
.
1
]# cd database/mysql/
[root@localhost mysql]# pwd
/usr/src/zabbix-
3.2
.
1
/database/mysql
[root@localhost mysql]#
[root@localhost mysql]# ls
data.sql images.sql schema.sql
|
进行zabbix初始数据导入
编辑/usr/local/zabbix/etc/zabbix_server.conf:
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
FpingLocation=/usr/local/sbin/fping
1
2
|
[root@localhost ~]# mkdir -p /usr/local/zabbix/logs
[root@localhost ~]# chown -R zabbix:zabbix /usr/local/zabbix/
|
启动Zabbix Server:
1
2
|
[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
/usr/local/zabbix/sbin/zabbix_server: error
while
loading shared libraries: libmysqlclient.so.
20
: cannot open shared object file: No such file or directory
|
解决方法:
在ld.so.conf中加入/usr/local/mysql/lib
1
|
[root@mysqla zabbix-
3.2
.
1
]# cat /etc/ld.so.conf
|
1
|
[root@mysqla zabbix-
3.2
.
1
]# ldconfig
|
再次执行zabbix_server启动
1
2
3
|
root@localhost ~]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost ~]# netstat -anpt |grep zabbix_server
tcp
0
0
0.0
.
0.0
:
10051
0.0
.
0.0
:* LISTEN
6311
/zabbix_server
|
添加开机启动脚本
1
2
3
4
5
6
7
8
9
|
[root@localhost src]# cd zabbix-
3.2
.
1
/
[root@localhost zabbix-
3.2
.
1
]# cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
[root@localhost zabbix-
3.2
.
1
]# cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
[root@localhost zabbix-
3.2
.
1
]# chmod +x /etc/rc.d/init.d/zabbix_server
[root@localhost zabbix-
3.2
.
1
]# chmod +x /etc/rc.d/init.d/zabbix_agentd
[root@localhost zabbix-
3.2
.
1
]# chkconfig --add zabbix_server
[root@localhost zabbix-
3.2
.
1
]# chkconfig --add zabbix_agentd
[root@localhost zabbix-
3.2
.
1
]# chkconfig zabbix_server on
[root@localhost zabbix-
3.2
.
1
]# chkconfig zabbix_agentd on
|
修改zabbix开机启动脚本中的zabbix安装目录
vi /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件
BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid #pid文件路径
vi /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件
BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid #pid文件路径
1
2
3
4
5
6
7
8
9
|
[root@localhost zabbix-
3.2
.
1
]# systemctl daemon-reload
[root@mysqla zabbix-
3.2
.
1
]# /etc/init.d/zabbix_server stop
Stopping zabbix_server (via systemctl): [ OK ]
[root@mysqla zabbix-
3.2
.
1
]# netstat -anpt | grep zabbix
[root@mysqla zabbix-
3.2
.
1
]# /etc/init.d/zabbix_server start
Starting zabbix_server (via systemctl): [ OK ]
设置防火墙规则
[root@mysqla zabbix-
3.2
.
1
]# firewall-cmd --permanent --add-port=
10051
/tcp
[root@mysqla zabbix-
3.2
.
1
]# firewall-cmd --reload
|
配置zabbix web页面
在安装目录将frontends拷贝到指定的web root:
1
2
3
|
[root@localhost zabbix-
3.2
.
1
]# cd /usr/src/zabbix-
3.2
.
1
/
[root@localhost zabbix-
3.2
.
1
]# cp -r frontends/php/ /usr/local/nginx1.
10
/html/zabbix
[root@localhost zabbix-
3.2
.
1
]# chown -R www:www /usr/local/nginx1.
10
/html/zabbix/
|
注:/usr/local/nginx/html为Nginx默认站点目录 www为Nginx运行账户
注:PHP需要至少开启扩展:
gd,bcmath,ctype,libXML,xmlreader,xmlwriter,session,sockets,mbstring,gettext,mysql
如下,查看是否包括了上面所提到的扩展模块
1
|
[root@localhost zabbix-
3.2
.
1
]# /usr/local/php5.
6
/bin/php -m
|
安装web
访问Web界面http://192.168.0.3/zabbix,进行相关web配置,配置完成后使用默认用户admin(密码:zabbix)登陆即可
进入ZABBIX WEB安装画面
进入ZABBIX检测画面
点击Next step 一下步进行zabbix server 细节的设置 这一步可以默认
点击Finish 完成
使用Admin 用默认密码 zabbix 登录
至此 ZABBIX的基础安装完成
登陆zabbix后,点击右上角的“用户”图标,将语言设置为“中文”:
解决zabbix绘图中出现中文乱码问题:
a.从windows下控制面板->字体->选择一种中文字库例如“楷体”
把它拷贝到zabbix的web端的fonts目录下例如:/usr/local/nginx1.10/html/zabbix/fonts/,并且把TTF后缀改为ttf
并且将之前的字体文件DejaVuSans.ttf移动到别处
c.然后,接着修改代码include/defines.inc.php文件中的字体配置,将里面关于字体设置从DejaVuSans替换成simkai
vi替换技巧:%s/DejaVuSans/simkai
其中:simkai为字库名字,不包含ttf后缀
其中:simkai为字库名字,不包含ttf后缀
# cd/usr/local/nginx1.10/html/zabbix
# vi include/defines.inc.php
在vi编辑器的末行模式下输入%s/DejaVuSans/simkai
这样,修改后,zabbix监控图形中的中文字就不会出现乱码了
四、zabbix客户端的安装
既然要监控我们就要添加要监控的主机,在添加主机之前我们首先要在被检测主机上面安装agent,安装agent比较简单,我们也是按照安装server的流程,下载软件包,在编译的时候,我们只选择agent
192.168.0.6作为zabbix的被监控端,提供web和mysql应用
安装Zabbix,配置Zabbix agent:
1
2
3
4
5
6
7
8
9
|
[root@localhost src]# tar zxf zabbix-
3.2
.
1
.tar.gz
[root@localhost src]# cd zabbix-
3.2
.
1
/
[root@localhost zabbix-
3.2
.
1
]# ./configure --prefix=/usr/local/zabbix --enable-agent
[root@localhost zabbix-
3.2
.
1
]# make && make install
[root@localhost zabbix-
3.2
.
1
]# groupadd zabbix
[root@localhost zabbix-
3.2
.
1
]# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
[root@localhost zabbix-
3.2
.
1
]# mkdir -p /usr/local/zabbix/logs
[root@localhost zabbix-
3.2
.
1
]# useradd -g zabbix zabbix
[root@localhost zabbix-
3.2
.
1
]# chown -R zabbix:zabbix /usr/local/zabbix/
|
配置开机自动启动:
1
2
|
[root@localhost zabbix-
3.2
.
1
]# chkconfig --add zabbix_agentd
[root@localhost zabbix-
3.2
.
1
]# chkconfig zabbix_agentd on
|
修改zabbix开机启动脚本中的zabbix安装目录
vi /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件
BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid #pid文件路径
1
|
[root@localhost zabbix-
3.2
.
1
]# systemctl daemon-reload
|
编辑zabbix_agentd.conf
1
|
[root@server1 zabbix-
3.2
.
1
]# vi /usr/local/zabbix/etc/zabbix_agentd.conf
|
内容如下:
PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Server=192.168.0.3
ListenPort=10050
ServerActive=192.168.0.3
Hostname=192.168.0.6
Timeout=15
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
注:
其中Server和ServerActive都指定zabbixserver的IP地址,不同的是,前者是被动后者是主动。也就是说Server这个配置是用来允许192.168.0.3这个ip来我这取数据。而serverActive的192.168.0.3的意思是,客户端主动提交数据给他。
Hostname=XXX,这个定义的名字必须和web页面里面host的名字一样。
启动zabbix_agentd:
启动zabbix成功 查看是否有服务 如果没有进程 输入以下网址解决
1
|
http:
//www.mamicode.com/info-detail-1790201.html
|
到此,zabbix3.2.1监控系统的基本环境安装完成。
实现zabbix添加监测项
添加对Linux主机的监控
在浏览器中打开:http://192.168.0.3/zabbix
登录zabbix,先在“配置”-“主机”里添加主机监控,监控os资源:内存,cpu,io,负载,带宽等.
登录zabbix,先在“配置”-“主机”里单击”创建主机”
注意:下图中的“主机名称”要和zabbix_agentd.conf文件中设置的“Hostname”后面的名称一致!
主机名称:192.168.0.6
群组:Linux servers
agent代理程序接口ip:192.168.0.6
已启用:勾选
其它选项默认即可
切换到模板
配置过一段时间后,观察下监控图效果出来了没:
后期更新mysql数据库监控,网卡情况 短信以及邮箱报警!
本文转自柴鑫旺 51CTO博客,原文链接:http://blog.51cto.com/chaixinwang/2054929,如需转载请自行联系原作者