bjghzly 发表于 2019-1-17 12:17:08

zabbix安装以及监控(一)

一、 zabbix简介:
  zabbix是完全开源的工具,整合了cacti和nagios等特性
  cacti:snmp
  nagios:linux主机:nrpe    设备:snmp
  附:SNMP(udp 161udp 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
  系统监控:ZabbixAgent 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的系统架构:
http://s1.运维网.com/images/20171226/1514294303295292.png
  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
http://s1.运维网.com/images/20180115/1515983300297133.png
  1、系统环境:centos7.2 x86_64
http://s1.运维网.com/images/20171226/1514294373120704.png
  因为centos7.2默认安装了mariadb-libs,所以先要卸载掉
  查看是否安装mariadb
  #rpm -qa | grep mariadb
  卸载mariadb
  rpm -e --nodeps mariadb-libs
  安装nginx:
  解压zlib
# tar zxf zlib-1.2.8.tar.gz
# tar zxf pcre-8.39.tar.gz  不需要编译,只需要解压就行
# groupaddwww
# useradd -g www www -s /sbin/nologin  下载nginx的源码包:http://nginx.org/download
  解压源码包:
# tar zxf nginx-1.10.2.tar.gz
# cd 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=wwwhttp://s1.运维网.com/images/20171226/1514294487709230.png
# make && make install
#ln -s /usr/local/nginx1.10/sbin/nginx /usr/local/sbin/# nginx
# netstat -anpt | grep nginx
tcp      0      0 0.0.0.0:80            0.0.0.0:*               LISTEN      46471/nginx: master# firewall-cmd --permanent --add-port=80/tcp
# firewall-cmd --reload  启动后可以再浏览器中打开页面,会显示nginx默认页面。
http://s1.运维网.com/images/20171226/1514294557358987.png
  安装php
http://s1.运维网.com/images/20171226/1514294571531405.png
# ln -s /usr/local/mysql/lib/libmysqlclient.so.20.3.0 /usr/local/mysql/lib/libmysqlclient_r.sohttp://s1.运维网.com/images/20171226/1514294597329097.png
# ./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# make && make install
# cp php.ini-production/etc/php.ini  找到:
;date.timezone =
修改为:
date.timezone = PRC #设置时区
http://s1.运维网.com/images/20171226/1514294655890814.png
  找到:
expose_php = On
修改为:
expose_php = Off #禁止显示php版本的信息
http://s1.运维网.com/images/20171226/1514294672452985.png
  找到:
short_open_tag = Off
修改为:
  short_open_tag = On //支持php短标签
http://s1.运维网.com/images/20171226/1514294687956994.png
  找到:
  post_max_size = 8M
  修改为:
  post_max_size = 16M//上传文件大小
http://s1.运维网.com/images/20171226/1514294704350944.png
  找到:
  max_execution_time = 30
  修改为:
  max_execution_time = 300//php脚本最大执行时间
http://s1.运维网.com/images/20171226/1514294718608599.png
  找到:
  max_input_time = 60
  修改为:
  max_input_time = 300//以秒为单位对通过POST、GET以及PUT方式接收数据时间进行限制
http://s1.运维网.com/images/20171226/1514294733861273.png
  always_populate_raw_post_data = -1
http://s1.运维网.com/images/20171226/1514294753385966.png
  mbstring.func_overload = 0
http://s1.运维网.com/images/20171226/1514294771393780.png
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on  提供php-fpm配置文件并编辑:
# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf  pid = run/php-fpm.pid
http://s1.运维网.com/images/20171226/1514294834456803.png
  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
http://s1.运维网.com/images/20171226/1514294850107272.png
  启动php-fpm服务:
# servicephp-fpm start
Starting php-fpmdone
# netstat -anpt | grep php-fpm
tcp      0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      49041/php-fpm: mast  配置nginx支持php
# cat /usr/local/nginx1.10/conf/nginx.conf  userwww www;
  worker_processes4;
  #error_loglogs/error.log;
  #error_loglogs/error.lognotice;
  #error_loglogs/error.loginfo;
  #pid      logs/nginx.pid;
  events {
  use epoll;
      worker_connections1024;
  }
  http {
  include       mime.types;
      default_typeapplication/octet-stream;
      #log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
      #                  '$status $body_bytes_sent "$http_referer" '
      #                  '"$http_user_agent" "$http_x_forwarded_for"';
  
      #access_loglogs/access.logmain;
  sendfile      on;
      #tcp_nopush   on;
      #keepalive_timeout0;
      keepalive_timeout65;
      #gzipon;
  server {
  listen       80;
        server_namelocalhost;
  charset utf-8;
        #access_loglogs/host.access.logmain;
  location / {
  root   html;
  indexindex.php index.html index.htm;
        }
  location ~ \.php$ {
  root html;
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_index index.php;
  include fastcgi.conf;
        }
        #error_page404            /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;
        }
     }
  }
# 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的测试页
# cat /usr/local/nginx1.10/html/test1.php
  访问结果
http://s1.运维网.com/images/20171226/1514294990116154.png
  NMP部署完毕。 数据mysql已经提前配置好博客也有安装mysql5.7文档
  三、监控系统Zabbix-3.2.1的安装
  zabbix-server端的操作
  zabbix服务器端要提前安装好LNMP环境(mysql,nginx,php5的安装目录均是/usr/local)
  创建Zabbix运行的用户:
# groupadd zabbix
# useradd -g zabbix zabbix  安装libcurl和net-snmp:
# yum -y install net-snmp* net-snmp-develcurl-develjava-1.8.0-openjdk java-1.8.0-openjdk-develOpenIPMI-devel*libssh2-devel*java*  安装fping
# tar zxf fping-3.12.tar.gz
# ./configure && make && make install
# chown root:zabbix /usr/local/sbin/fping
# chmod 4710 /usr/local/sbin/fping  安装Zabbix Server:
root@localhost src]# tar zxf zabbix-3.2.1.tar.gz
# cd 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-openipmihttp://s1.运维网.com/images/20171226/1514295087192983.png
  注:编译时最好带上--enable-java这个参数,方便后续监控tomcat程序所用。
  --with-ssh2 是不需要在客户端服务器上面安装Zabbix agent,如果需要使用ssh检查,需要在编译的时候加上这项,最低需要libssh2 1.0.0版本,需要安装ssh开发包
  --with-openipmi用户可以利用 IPMI 监视服务器的物理特征,如温度、电压、电扇工作状态、电源供应等。
  如果添加了--enable-proxy, 那么会生成get和sender两条命令. 如下, 用于接收agent发生过来的信息, 同时发送给server.
# make && make install  添加系统软连接
# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
#ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/  Zabbix Server配置与启动
创建Zabbix数据库和MySQL用户:
create database zabbix character set utf8;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';http://s1.运维网.com/images/20171226/1514295157111085.png
  导入Zabbix初始数据:
  切换到zabbix的解压目录下
# cd database/mysql/
# pwd
/usr/src/zabbix-3.2.1/database/mysql
#
# ls
data.sqlimages.sqlschema.sql  进行zabbix初始数据导入
  编辑/usr/local/zabbix/etc/zabbix_server.conf:
  LogFile=/usr/local/zabbix/logs/zabbix_server.log
http://s1.运维网.com/images/20171226/1514295203952418.png
  PidFile=/usr/local/zabbix/logs/zabbix_server.pid
http://s1.运维网.com/images/20171226/1514295221624834.png
  DBHost=localhost
http://s1.运维网.com/images/20171226/1514295233192832.png
  DBName=zabbix
http://s1.运维网.com/images/20171226/1514295245243477.png
  DBUser=zabbix
http://s1.运维网.com/images/20171226/1514295259944162.png
  DBPassword=zabbix
http://s1.运维网.com/images/20171226/1514295274421736.png
  DBPort=3306
http://s1.运维网.com/images/20171226/1514295288101378.png
  FpingLocation=/usr/local/sbin/fping
http://s1.运维网.com/images/20171226/1514295312324834.png
# mkdir -p /usr/local/zabbix/logs
# chown -R zabbix:zabbix /usr/local/zabbix/  启动Zabbix Server:
# /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
# cat /etc/ld.so.confhttp://s1.运维网.com/images/20171226/1514295376323908.png
# ldconfig  再次执行zabbix_server启动
root@localhost ~]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
#netstat -anpt |grep zabbix_server
tcp      0      0 0.0.0.0:10051         0.0.0.0:*               LISTEN      6311/zabbix_server  添加开机启动脚本
# cd zabbix-3.2.1/
# cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
# cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
# chmod +x /etc/rc.d/init.d/zabbix_server
# chmod +x /etc/rc.d/init.d/zabbix_agentd
# chkconfig --add zabbix_server
# chkconfig --add zabbix_agentd
#chkconfig zabbix_server on
# chkconfig zabbix_agentd on  修改zabbix开机启动脚本中的zabbix安装目录
  vi /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件
  BASEDIR=/usr/local/zabbix/ #zabbix安装目录
http://s1.运维网.com/images/20171226/1514295470511757.png
  PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid    #pid文件路径
http://s1.运维网.com/images/20171226/1514295487695284.png
  vi /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件
  BASEDIR=/usr/local/zabbix/ #zabbix安装目录
  PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid#pid文件路径
# systemctl daemon-reload
# /etc/init.d/zabbix_server stop
Stopping zabbix_server (via systemctl):                  
# netstat -anpt | grep zabbix
# /etc/init.d/zabbix_server start
Starting zabbix_server (via systemctl):                  
设置防火墙规则
# firewall-cmd --permanent --add-port=10051/tcp
# firewall-cmd --reload  配置zabbix web页面
  在安装目录将frontends拷贝到指定的web root:
# cd /usr/src/zabbix-3.2.1/
# cp -r frontends/php/ /usr/local/nginx1.10/html/zabbix
#chown-Rwww: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
如下,查看是否包括了上面所提到的扩展模块
#/usr/local/php5.6/bin/php -mhttp://s1.运维网.com/images/20171226/1514295571870115.png
  安装web
  访问Web界面http://192.168.0.3/zabbix,进行相关web配置,配置完成后使用默认用户admin(密码:zabbix)登陆即可
  进入ZABBIX WEB安装画面
http://s1.运维网.com/images/20171226/1514295591124151.png
http://s1.运维网.com/images/20171226/1514295618884435.png
  进入ZABBIX检测画面
http://s1.运维网.com/images/20171226/1514295682142202.png
  点击Next step 一下步进行zabbix server 细节的设置 这一步可以默认
  点击Finish 完成
  使用Admin用默认密码 zabbix 登录
http://s1.运维网.com/images/20171226/1514295710754450.png
http://s1.运维网.com/images/20171226/1514295722961965.png
  至此 ZABBIX的基础安装完成
  登陆zabbix后,点击右上角的“用户”图标,将语言设置为“中文”:
http://s1.运维网.com/images/20171226/1514295742762898.png
  解决zabbix绘图中出现中文乱码问题:
  a.从windows下控制面板->字体->选择一种中文字库例如“楷体”
  把它拷贝到zabbix的web端的fonts目录下例如:/usr/local/nginx1.10/html/zabbix/fonts/,并且把TTF后缀改为ttf
http://s1.运维网.com/images/20171226/1514295757540048.png
  并且将之前的字体文件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:
# tar zxf zabbix-3.2.1.tar.gz
# cd zabbix-3.2.1/
# ./configure --prefix=/usr/local/zabbix --enable-agent
# make && make install
# groupadd zabbix
# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# mkdir -p /usr/local/zabbix/logs
# useradd -g zabbix zabbix
# chown -R zabbix:zabbix /usr/local/zabbix/  配置开机自动启动:
# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentdon  修改zabbix开机启动脚本中的zabbix安装目录
  vi /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件
  BASEDIR=/usr/local/zabbix/ #zabbix安装目录
http://s1.运维网.com/images/20171226/1514295842296773.png
  PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid#pid文件路径
# systemctl daemon-reload  编辑zabbix_agentd.conf
# vi /usr/local/zabbix/etc/zabbix_agentd.conf  内容如下:
  PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid
http://s1.运维网.com/images/20171226/1514295893336553.png
  LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
http://s1.运维网.com/images/20171226/1514296047409016.png
  Server=192.168.0.3
http://s1.运维网.com/images/20171226/1514296156997385.png
  ListenPort=10050
http://s1.运维网.com/images/20171226/1514296029112499.png
  ServerActive=192.168.0.3
  http://s1.运维网.com/images/20171226/1514296179979374.png
  Hostname=192.168.0.6
http://s1.运维网.com/images/20171226/1514296188885923.png
  Timeout=15
http://s1.运维网.com/images/20171226/1514296213258813.png
  Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
http://s1.运维网.com/images/20171226/1514296229622518.png
  注:
  其中Server和ServerActive都指定zabbixserver的IP地址,不同的是,前者是被动后者是主动。也就是说Server这个配置是用来允许192.168.0.3这个ip来我这取数据。而serverActive的192.168.0.3的意思是,客户端主动提交数据给他。
  Hostname=XXX,这个定义的名字必须和web页面里面host的名字一样。
  启动zabbix_agentd:
  启动zabbix成功 查看是否有服务 如果没有进程输入以下网址解决
http://www.mamicode.com/info-detail-1790201.html  到此,zabbix3.2.1监控系统的基本环境安装完成。
  实现zabbix添加监测项
  添加对Linux主机的监控
  在浏览器中打开:http://192.168.0.3/zabbix
  登录zabbix,先在“配置”-“主机”里添加主机监控,监控os资源:内存,cpu,io,负载,带宽等.
  登录zabbix,先在“配置”-“主机”里单击”创建主机”
http://s1.运维网.com/images/20171226/1514296272728516.png
http://s1.运维网.com/images/20171226/1514296347895691.png
  注意:下图中的“主机名称”要和zabbix_agentd.conf文件中设置的“Hostname”后面的名称一致!
  主机名称:192.168.0.6
  群组:Linux servers
  agent代理程序接口ip:192.168.0.6
  已启用:勾选
  其它选项默认即可
  切换到模板
http://s1.运维网.com/images/20171226/1514296380743388.png
  配置过一段时间后,观察下监控图效果出来了没:
http://s1.运维网.com/images/20171226/1514296411398004.png
  后期更新mysql数据库监控,网卡情况 短信以及邮箱报警!



页: [1]
查看完整版本: zabbix安装以及监控(一)