我很黑! 发表于 2019-1-20 09:14:55

Centos7.2下搭建Zabbix3.2(简)

  一、简介   
      zabbix(音同 zbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
      zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
      zabbix由2部分构成,zabbix server与可选组件zabbix agent。
  zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
  

  二、实验环境
主机
操作系统IP地址主要软件Zabbix ServerCentos7.2192.168.1.103zabbix-3.2.4、httpd、mariadb、php等。Zabbix AgentCentos7.2192.168.1.105zabbix-3.2.4Zabbix AgentWindows Server 2008 R2192.168.1.106
  

  三、搭建Zabbix Server并添加主机
  

  1、安装Zabbix Server
  

  安装所需软件包
  # yum -y install gcc* make php php-gd php-mysql php-bcmath php-mbstring php-xml curl curl-devel net-snmp   net-snmp-devel perl-DBI httpd mariadb* mysql-devel libxml2-devel curl-devel unixODBC-devel net-snmp-devel OpenIPMI-devel vim
  

  创建zabbix用户
  # useradd zabbix
  

  关闭防火墙(由于本次是实验环境为了调试方便所以关闭防火墙,生产环境中一定要打开防火墙,并配置相关规则)
  # systemctl stop firewalld.service
  

  # tar xf zabbix-3.2.4.tar.gz

  # cd zabbix-3.2.4
  # ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc
  # make install
  

  启动数据库
  # systemctl start mariadb.service
  

  给数据库设置密码(本次试验中是新安装的数据库,所以将密码设置为linux.com123)
  # mysqladmin -u root -p password linux.com123
  Enter password:                     ←直接敲回车即可(新安装的数据库默认是没有密码的)
  # mysql -u root -p
  Enter password:                     ←输入刚刚设置的密码
  

  创建新用户,用户名为“zabbix”密码“zabbix”,并将zabbix数据库授权给zabbix用户
  MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
  MariaDB [(none)]> insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('zabbix'));
  MariaDB [(none)]> flush privileges;
  

  MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix' with grant option;
  

  MariaDB [(none)]> flush privileges;
  MariaDB [(none)]> quit
  

  导入Sql语句
  # mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
  # mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
  # mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
  

  在/etc/php.ini中添加或修改如下内容
  # vim /etc/php.ini
  878    date.timezone= Asia/Shanghai
  384    max_execution_time = 300
  672    post_max_size = 32M
  407    memory_limit = 128M
  1707mbstring.func_overload = 1
  

  将httpd、mariadb添加到系统启动
  # systemctl enable httpd.service
  # systemctl enable mariadb.service
  

  #cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
  #cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
  

  # chkconfig --add zabbix_server
  # chkconfig zabbix_server on
  

# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentd on
  # cp -r ./frontends/php/ /var/www/html/zabbix
  # chown -R apache.apache /var/www/html/zabbix
  

  启动httpd服务
  # systemctl start httpd.service
  

  Zabbix Agent配置(被监控端)
  # yum -y install gcc* make vim
  # setenforce 0
  # vim /etc/sysconfig/selinux
  # systemctl stop firewalld.service
  # setenforce 0
  # vim /etc/sysconfig/selinux
  # systemctl stop firewalld.service
  

  编译安装Zabbix Agent
  # ./configure --enable-agent
  # make install
  

  #cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
  # chkconfig --add zabbix_agentd
  # chkconfig zabbix_agentd on
  # chkconfig --list zabbix_agentd
  # useradd zabbix
  

  更改如下三项
  # vim /usr/local/etc/zabbix_agentd.conf
  Server=192.168.1.104
  ServerActive=192.168.1.104
  Hostname=Linux                ←需要和下文Web中添加的主机名一致
  # systemctl start zabbix_agentd.service
  

  Web端配置
  通过浏览器访问“http://192.168.0.104/zabbix”
  

  点击“next step”(如果出现红色选项需要在/etc/php.ini中将相应的值修改为与required相等)
  

  

https://s2.运维网.com/wyfs02/M01/8E/A8/wKioL1jIm13haI2BAAEYgzz8eVI120.png
  

  输入数据库名、用户名以及密码
https://s2.运维网.com/wyfs02/M02/8E/AA/wKiom1jIm12T6BgoAACL7Obpwp0545.png
  

  输入主机名
https://s2.运维网.com/wyfs02/M02/8E/A8/wKioL1jIm13Q4SuPAAB1N2AC0p0788.png
  

  确认信息是否正确
https://s1.运维网.com/wyfs02/M00/8E/A8/wKioL1jIm16QU4y1AACkhAiJjbs887.png
  

  

  zabbix对网页目录权限不足,所以需要我们手动下载配置文件,并放到网页中提示的位置(1、点击Download the configuration file。 2、将该文件存放到“/var/www/html/zabbix/conf/zabbix.conf.php”)
https://s1.运维网.com/wyfs02/M00/8E/AA/wKiom1jIm16zjC78AAB2imv0v6E055.png
  

  刷新网页发现已经找到该配置文件
https://s2.运维网.com/wyfs02/M00/8E/A8/wKioL1jIm3yhLxr_AAB6YGcvfjM868.png
  

  

  

  

  

  默认用户名“Admin”、密码“zabbix”
https://s3.运维网.com/wyfs02/M00/8E/AA/wKiom1jImdfQ-8JjAABRXHgXP0w969.png
  

  进入到zabbix首页面发现zabbix服务显示没有启动,但通过shell查看服务的状态发现服务已经启动
  # systemctl status zabbix_server.service
  ● zabbix_server.service - SYSV: Starts and stops Zabbix Server using chkconfig
     Loaded: loaded (/etc/rc.d/init.d/zabbix_server; bad; vendor preset: disabled)
   Active: active (running) since 三 2017-03-15 09:20:20 CST; 30min ago
  

  这是由于selinux机制限制所造成的,关闭selinux机制即可
  # setenforce 0
  

  将SELINUX项更改为disabled
  # vim /etc/sysconfig/selinux
  SELINUX=disabled
  

https://s1.运维网.com/wyfs02/M00/8E/A8/wKioL1jImdiAkpuHAAEauQMFPS4337.png
  

  刷新页面即可
https://s3.运维网.com/wyfs02/M01/8E/AA/wKiom1jImdmgXGHuAAEP_VMRexU511.png
  

  点击“configuration → Host groups”并点击右上角的“create host group”创建一个新的host group
  

https://s2.运维网.com/wyfs02/M01/8E/AA/wKiom1jImduxhr2RAAEQDVFMIrE224.png
  

  数据新建host group的名称,并选择需要用到的模板(添加到该组的主机默认会使用添加该模板)
https://s2.运维网.com/wyfs02/M01/8E/A8/wKioL1jImduwBR1jAADJV9pE5lg351.png
  

  2、添加主机
  点击“configuration→hosts”然后点击右上角的create host新建主机
  输入主机名、选择主机组、填写被监控主机的IP地址
https://s4.运维网.com/wyfs02/M02/8E/AB/wKiom1jIqn-w_Yv4AAEPEaqGf3Q469.png
  

  

  点击templates并添加相应模板https://s4.运维网.com/wyfs02/M00/8E/A9/wKioL1jIqoChYnIpAACptUB-AWg568.png
  

  等待Availability中的ZBX变为绿色即表示可以与被监控主机正常通信
https://s5.运维网.com/wyfs02/M01/8E/AB/wKiom1jIqoHx6ljPAAD3vicCPYE934.png
  

  

  

  

  

  

  

  

  点击“Monitoring→graphs在右上角选择主机后即可查看被监控主机的数据
https://s2.运维网.com/wyfs02/M00/8E/A9/wKioL1jIrPGDuUPMAADithTzHEA886.png
  

  添加网卡监控项目
  进入到“configuration→templates→选择需要添加网卡监控的模板→itmes”本次笔者选择的是Template OS Linux模板添加网卡监控
https://s4.运维网.com/wyfs02/M00/8E/A9/wKioL1jIsmPw8Ee4AAECNRLg9NU092.png
  

  添加网卡监控需要添加两个Item(因为网卡流量是一进一出)
  添加In方向item
  1、在Name中填写In方向的名字本次实验使用的是“Incoming network traffic on Networkinterfacecard”
  2、type中选择“Zabbix_agent”
  3、key中输入“Net_incoming”
  4、Type of information中选择“Numeric(float)”
  5、Units选择Bps

  6、其他按照下图中更改即可
  

https://s4.运维网.com/wyfs02/M02/8E/AB/wKiom1jIs8Dw77suAAE1NzciU1g703.png
  

  添加Out方向item
1、在Name中填写In方向的名字本次实验使用的是“Net_Outgoing network traffic on Networkinterfacecard”
2、type中选择“Zabbix_agent”
3、key中输入“Net_Outgoing”
4、Type of information中选择“Numeric(float)”
5、Units选择Bps

6、其他按照下图中更改即可
https://s4.运维网.com/wyfs02/M02/8E/AB/wKiom1jItvOhZv4rAAE2mWgMqI0151.png


添加完In、Out方向的item之后需要回到“configuration→templates→选择需要添加网卡监控的模板→graphs”
https://s5.运维网.com/wyfs02/M01/8E/AB/wKiom1jIt4WRf_BbAAIYZzxdSrs470.png


点击右上角的"Create graph"并在items中添加刚刚添加的两个item
https://s4.运维网.com/wyfs02/M00/8E/A9/wKioL1jIuLiy4FUWAAEOQ1Ee4lw725.png


在“monitoring→graphs”中查看

https://s4.运维网.com/wyfs02/M02/8E/AB/wKiom1jIuTWSccvnAAHV2_8YCQs176.png


添加Windows监控
在官网下载Zabbix Agent windows版http://www.zabbix.com/downloadhttps://s1.运维网.com/wyfs02/M01/8E/AD/wKiom1jI117gyA2uAAG3inY5Jcw596.png


将文件解压放到windows的c盘下
https://s3.运维网.com/wyfs02/M02/8E/AD/wKiom1jI19Pjek-LAABrU9mN0vE539.png


编辑conf/zabbix_agentd.win.conf(建议使用notepad++编辑)
修改如下项:(和linux上类似)
Hostname=WindowsServer2008R2
ServerActive=192.168.1.104
Server=192.168.1.104


打开cmd,输入如下信息(将zabbix_agent添加到服务中)
c:\bin\win64\zabbix_agentd.exe -c c:\conf\zabbix_agentd.win.conf -i


启动服务
c:\bin\win64\zabbix_agentd.exe -c c:\conf\zabbix_agentd.win.conf -s


  使用netstat -an | find "10050"查看端口是否启用
https://s1.运维网.com/wyfs02/M01/8E/AE/wKiom1jI2kHyLBcwAABfa9D8oqM817.png
  

  打开服务控制台也可以看到
https://s4.运维网.com/wyfs02/M01/8E/AC/wKioL1jI2p3SW70XAAEGVGL_F5Q697.png
  

  在Zabbix Server web界面中添加主机
  进入到“configuration→hosts”点击“create host”输入主机名、主机IP等信息
https://s1.运维网.com/wyfs02/M00/8E/AC/wKioL1jI3DvTr6ouAAEc4vRi6zA754.png
  

  点击templates选择windows模板
https://s5.运维网.com/wyfs02/M01/8E/AE/wKiom1jI3Dyzv78iAAC6Y8Vj8fo974.png
  

  添加完成
https://s2.运维网.com/wyfs02/M01/8E/AC/wKioL1jI3D2xr4ghAAEsdg4wVMk622.png
  

  点击“monitoring→graph”并在右上角选择刚刚添加的windows主机查看图像
https://s2.运维网.com/wyfs02/M00/8E/AC/wKioL1jI3MyxZ3ezAAEwjoXiLtQ319.png
  

  3、添加邮件报警
  # yum -y install mailx
  

  添加如下几行
  # vim /etc/mail.rc
  set from=1861097xxxx@163.com                ←发送邮件的邮箱地址
  set smtp=smtp.163.com
  set smtp-auth-user=1861097xxxx@163.com       ←同上,发送邮件的邮箱地址
  set smtp-auth-password=lx3768150                ←笔者使用的是163的邮箱,需要使用授权码登录
  set smtp-auth=login
  bogon ~]# systemctl start mailx.service
  

  发送邮件测试
  # echo "zabbix test" | mail -s "zabbix" 1247718627@qq.com
  

  编写发送脚本
  #vim /usr/local/share/zabbix/alertscripts/sendmail.sh
  #!/bin/sh
  #
  #echo "$3" | mail -s "$2" $1
  echo "$3" | sed s/'\r'//g | mail -s "$2" $1
  

  # chmod +x /usr/local/share/zabbix/alertscripts/sendmail.sh
  

  接下来需要在Web中配置报警
  

  打开“Administrator→media type →create media type”

https://s5.运维网.com/wyfs02/M01/8E/B1/wKiom1jJBMrgjFpwAACncBWSWfo314.png
  

  打开“Administrator→user”点击admin,选择“media”并点击“add”
https://s3.运维网.com/wyfs02/M02/8E/AF/wKioL1jJBVWx9SR9AADKmp2RkT8817.png
  

  点击update更新
https://s3.运维网.com/wyfs02/M00/8E/B1/wKiom1jJBVajOXCfAACY5jQ0WXg810.png
  

  关闭Windows Server 2008 R2邮箱收到报警信息
https://s1.运维网.com/wyfs02/M01/8E/AF/wKioL1jJBcug2U83AAH7YpxYpk8647.png
  

  问题汇总:
  将zabbix更改为中文之后图像乱码
https://s1.运维网.com/wyfs02/M00/8E/AF/wKioL1jJBoGilQhuAAIVEUI7s4g769.png
  

  解决方法:
  这个问题是由于zabbix的web端没有中文字库,我们最需要把中文字库加上即可。
  1、选择C:\Windows\Fonts\选择一种中文字库例如“简体字”。点击右键复制
  https://s3.运维网.com/wyfs02/M00/8E/B1/wKiom1jJCevjWZg8AAJKQvJ7D3I329.png
  

  将字体上传到“Zabbix Server”的zabbix自体库中
  https://s5.运维网.com/wyfs02/M02/8E/AF/wKioL1jJCojQ-SidAAA-bcm8BaI349.png
  

  

  将刚刚上传的文件名改为小写
  # mv SIMFANG.TTF simfang.ttf
  

  在如下两行中将默认的“DejaVuSans”更改为刚刚上传的“simfang”
  # vim /var/www/html/zabbix/include/defines.inc.php
  //define('ZBX_FONT_NAME', 'DejaVuSans');
  define('ZBX_FONT_NAME', 'simfang');
  

  //define('ZBX_GRAPH_FONT_NAME',         'DejaVuSans');
  define('ZBX_GRAPH_FONT_NAME',         'simfang');
  

  刷新网页
https://s1.运维网.com/wyfs02/M02/8E/AF/wKioL1jJDPDyIO3VAAI1EbzqxFc316.png
  

  相关资料:
  百度知道zabbix

  zabbix中文乱码

  《Zabbix监控深度实践》
  

        笔者最近刚刚开始使用Zabbix,还不是特别的熟悉,如有哪里写错或者忘写的地方还请大家指出,谢谢!
  

  

  




页: [1]
查看完整版本: Centos7.2下搭建Zabbix3.2(简)