Zabbix安装部署(for rhel5.7)
之前的 Nagios 与 Cacti 整合部署(for_RHEL_5.7) 与这篇 Zabbix 安装部署(for rhel5.7)都是学习监控时网络查询和实操所做,在这里非常感谢网友门的开源精神,大家共同学习,每天进步一点,积累就是收获 。 For Think email:cnbjthink@gmail.com (*^__^*) 。  
Word 导出 PDF,文档可能错位但不影响观看,请不要计较。

一> Zabbix简介
Zabbix 是一个提供 Web 管理界面的企业级的开源系统/网络监控分布式监控解决方案,由一个国外的团队持续维护更新,软件可以自由下载使用,运作团队靠提供收费的技术支持赢利。
官方网站:http://www.zabbix.com
Zabbix 1.8官方文档:http://www.zabbix.com/documentation/1.8/start
Zabbix通过C/S模式采集数据,通过B/S模式在web端展示和配置。
被监控端:主机通过安装agent方式采集数据,网络设备通过SNMP方式采集数据
Server端:通过收集SNMP和agent发送的数据,写入MySQL数据库,再通过php+apache在web前端展示。
Zabbix运行条件:
Server:
Zabbix Server需运行在LAMP(Linux+Apache+Mysql+PHP)环境下,对硬件要求低
Agent:
目前已有的agent基本支持市面常见的OS,包含Linux、HPUX、Solaris、Sun、windows
SNMP:
支持各类常见的网络设备

二> Zabbix功能
  具备常见的商业监控软件所具备的功能(主机的性能监控、网络设备性能监控、数据库性能监控、FTP等通用协议监控、多种告警方式、详细的报表图表绘制)
支持自动发现网络设备和服务器,支持分布式,能集中展示、管理分布式的监控点,扩展性强,server提供通用接口,可以自己开发完善各类监控

三>优劣势
优点:
开源,无软件成本投入
Server对设备性能要求低(实际测试环境:虚拟机Redhat EL AS5,2GCPU 1G内存,监控5台设备,CPU使用率基本保持在10%以下,内存剩余400M以上)
支持设备多
支持分布式集中管理
开放式接口,扩展性强
缺点:
全英文,界面不友好
无厂家支持,出现问题解决比较麻烦
需在被监控主机上安装agent

四>下载软件:

http://cdnetworks-kr-1.dl.source ... zabbix-1.8.9.tar.gz

http://www.zabbix.com/downloads/ ... nux2_6.amd64.tar.gz

http://www.zabbix.com/downloads/ ... inux2_6.i386.tar.gz

  安装前先配置好PHP,要求支持 php-gd、php-bcmath、php-xml、php-mysql、php-net-socket、php-mbstring,即 configure 参数中加上 –with-gd –enable-bcmath –enable-xml –with-mysql –enable-sockets –enable-mbstring


  由于zabbix是基于web界面将存储在数据库中的数据成图表显示出来,所以zabbix需要运行在web和数据库的平台上, 在这里我们使用lemp环境。 Linuxtone提供了自动部署lemp的脚本,只需下载后解压运行里面的lemp.sh即可,或者leam脚本(Apache与Nginx看需求)基 于lemp改编的,可以问我要

lemp下载地址:http://bbs.linuxtone.org/docs/autoinstall/lemp_auto_v1.0.6.tar.gz



五>开始安装:redhat 提前安装好YUM确保能用,安装zabbix所需的组件

[root@rhel ~]# yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath

1> install lemp.sh

[root@rhel ~]# cd /usr/local/src/
[root@rhel src]# wget http://bbs.linuxtone.org/docs/autoinstall/lemp_auto_v1.0.6.tar.gz
[root@rhel src]# tar xzvf lemp_auto_v1.0.6.tar.gz
[root@rhel src]# cd lemp
[root@rhel lemp]# ./lemp.sh        (估计半小时左右,依据个人网络和机器性能而定)

2> install zabbix        (为zabbix创建自己的数据库,以便zabbix可以把收集到的数据信息存放在那里调用)

[root@rhel src]# useradd zabbix
[root@rhel src]# passwd zabbix
[root@rhel src]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.56-LTOPS-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql> create database zabbix;
Query OK, 1 row affected (0.02 sec)
mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix' ;
Query OK, 0 rows affected (0.08 sec)
mysql> quit
Bye


[root@rhel src]# tar xzvf zabbix-1.8.9.tar.gz
[root@rhel src]# cd zabbix-1.8.9
[root@rhel zabbix-1.8.9]# mysql -u root zabbix < create/schema/mysql.sql
[root@rhel zabbix-1.8.9]# mysql -u root zabbix < create/data/data.sql
[root@rhel zabbix-1.8.9]# mysql -u root zabbix < create/data/p_w_picpaths_mysql.sql
[root@rhel zabbix-1.8.9]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql=/usr/local/mysql-5.1.56/bin/mysql_config --with-net-snmp --with-libcurl

--prefix指定zabbix安装目录,--enable-server 支持zabbix服务器,--enable-agent支持zabbix代理,--enable-proxy 支持zabbix代理服务器,--with-mysql 使用MySQL客户端库可以选择指定路径mysql_config,--with-net-snmp 使用net-snmp软件包,择性地指定路径net-snmp配置, --with-libcurl 使用curl包

[root@rhel zabbix-1.8.9]# make && make install

添加zabbix服务对应的端口

[root@rhel zabbix-1.8.9]# cat >> /etc/services << EOF
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper
EOF

[root@rhel zabbix-1.8.9]#
[root@rhel zabbix-1.8.9]# mkdir /etc/zabbix
[root@rhel zabbix-1.8.9]# cp misc/conf/* /etc/zabbix/
cp: omitting directory `misc/conf/zabbix_agentd'
[root@rhel zabbix-1.8.9]# cp -r frontends/php/ /data/www/wwwroot/zabbix

修改zabbix连接的数据库的用户名和密码

[root@rhel zabbix-1.8.9]# vim /etc/zabbix/zabbix_server.conf        (set nu)

86 DBName=zabbix
102 DBUser=zabbix
112 DBPassword=zabbix

为 zabbix 的启动、关闭和重启的脚本文件做链接,方便系统可以找得到

[root@rhel zabbix-1.8.9]# cd /usr/local/zabbix/bin/
[root@rhel bin]# for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done
[root@rhel bin]# cd /usr/local/zabbix/sbin/
[root@rhel sbin]# for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done

把mysql的lib库文件添加到系统动态库配置文件中,方便系统可以找到mysql的lib库

[root@rhel sbin]# echo "/usr/local/mysql-5.1.56/lib/mysql/" >> /etc/ld.so.conf
[root@rhel sbin]# ldconfig        (立即生效)

将zabbix相关的启动脚本等文件拷贝的/etc/init.d/下,方便日后对 zabbix 的启动关闭操作

[root@rhel sbin]# cd /usr/local/src/zabbix-1.8.9
[root@rhel zabbix-1.8.9]# cp misc/init.d/redhat/8.0/zabbix_server /etc/init.d/
[root@rhel zabbix-1.8.9]# chmod +x /etc/init.d/zabbix_server
[root@rhel zabbix-1.8.9]# cp misc/init.d/redhat/8.0/zabbix_agentd /etc/init.d/
[root@rhel zabbix-1.8.9]# chmod +x /etc/init.d/zabbix_agentd

修改zabbix server和agentd程序目录的位置

[root@rhel zabbix-1.8.9]# vim /etc/init.d/zabbix_server                (set nu)

17 progdir="/usr/local/zabbix/sbin/"

[root@rhel zabbix-1.8.9]# vim /etc/init.d/zabbix_agentd                (set nu)

17 progdir="/usr/local/zabbix/sbin/"

添加开机启动服务

[root@rhel zabbix-1.8.9]# chkconfig --add zabbix_server
[root@rhel zabbix-1.8.9]# chkconfig --add zabbix_agentd
[root@rhel zabbix-1.8.9]# chkconfig --level 345 zabbix_server on
[root@rhel zabbix-1.8.9]# chkconfig --level 345 zabbix_agentd on
[root@rhel zabbix-1.8.9]# chkconfig --list | grep zabbix               
(使用 chkconfig --list 检查一下)

在 nginx 配置文件中建立 zabbix 虚拟机的配置文件

[root@rhel zabbix-1.8.9]# cat > /usr/local/nginx/conf/vhosts/monitor.conf << EOF
server {
listen       80;
server_name  zabbix.test.com;
#access_log   logs/zabbix_access.log  main;
location / {
root   /data/www/wwwroot/zabbix;
index  index.html index.htm index.php;
}
location ~ \.php$ {
root   /data/www/wwwroot/zabbix;
fastcgi_pass   127.0.0.1:9000;
fastcgi_param  SCRIPT_FILENAME  
$document_root$fastcgi_script_name;
fastcgi_index  index.php;
include        fastcgi_params;
}
}
EOF

对php配置文件做相应的调整,使其满足zabbix运行的最低环境要求

[root@rhel zabbix-1.8.9]# vim /usr/local/php-5.2.17/etc/php.ini

255 max_execution_time = 300     
256 max_input_time = 300   
439 post_max_size = 16M
663 [Date]
664 ; Defines the default timezone used by the date functions
665 date.timezone = Asia/Shanghai

[root@rhel ~]# cd /data/www/wwwroot/zabbix/
[root@rhel zabbix]# chmod 777 conf                (权限不给的话web界面安装到最后一步会报错)
[root@rhel ~]# /etc/init.d/zabbix_agentd restart
[root@rhel ~]# /etc/init.d/zabbix_server restart
[root@rhel ~]# /etc/init.d/fastcgi restart
[root@rhel ~]# /etc/init.d/mysqld restart
[root@rhel ~]# /etc/init.d/snmpd restart

web enter install zabbix:http://IP/zabbix/,用户名和密码为默认:admin/zabbix,进入zabbix安装界面,同意许可协议,环境最低 要求(前面对 php 配置文件的修改),数据库连接配置 (连接mysql的用户名和密码之前以配置,zabbix/zabbix),zabbix server的信息,next,next,完成安装,

对zabbix进行汉化,中文的监控界面

wget http://www.hiadmin.com/wp-conten ... _zh.inc.php_.tar.gz

解压后的文件复制到 /data/www/wwwroot/zabbix/include/locales下覆盖原来的文件,重启zabbix

登陆zabbix监控界面,点击zabbix首页右上角 porfile,language中选择Chinese(CN)保存即可,完成看监控页面屏幕。

相关配置很简单自己倒腾下或者百度去,这里就不介绍了。



zabbix客户端软件安装配置(Linux操作系统)

groupadd zabbix
useradd zabbix -g zabbix
password zabbix

从zabbix Server上拷贝一份zabbix.agentd.conf 拷贝配置文件到/etc/zabbix目录下,修改配置文件中主机名和监控服务器

vim /etc/zabbix/zabbix_agentd.conf         (set nu)

     81 Server=服务器断IP
     92 Hostname=被监控端IP


在客户端服务器上添加zabbix监控端口

cat >> /etc/services << EOF
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper
EOF


软件下载地址:

http://www.zabbix.com/downloads/ ... nux2_6.amd64.tar.gz
http://www.zabbix.com/downloads/ ... inux2_6.i386.tar.gz

tar -xzvf zabbix_agents_1.8.5.linux2_6.i386.tar.gz -C /usr/local/zabbix

拷贝启动脚本到/etc/init.d目录下

cd /usr/local/zabbix/sbin/
cp zabbix_agentd /etc/init.d/
chmod a+x /etc/init.d/zabbix_agentd

/etc/init.d/zabbix_agentd start
ps -ef | grep zabbix_agentd

iptables -A INPUT -p tcp -s 服务器IP -m multiport --dports 10050,10051 -jACCEPT

 

下面是win服务器监控的配置,有兴趣的童鞋也可以看一下:

 

1.首先下载zabbix_agents_1.8.5_win_zip 这个客户端包到需要监控服win服务器上,然后解压。

2.解压出来后会多出两个文件夹,分别是win_64和win_32 根据系统的类型,拷贝相关文件夹里的安装文件到c:\zabbix下面。然后新建zabbix_agentd.conf 文件,这个文件可以从服务器端的配置文件里考,也可以自己新建,里面只要有几行关键的内容就可以了。

 
  
  1. LogFile=c:\zabbix\zabbix_agentd.log 
  2.  
  3. PidFile=c:\zabbix\zabbix_agentd.pid 
  4.  
  5. Server=<服务端IP地址> 
  6.  
  7. Hostname=<客户端主机名> 

修改好相关内容后,就可以安装了。

 

3.安装其实很简单,只需要在dos下输入一条命令就可以了。

C:\zabbix\zabbix_agentd.exe --install 

这里的路径一定要正确

如果不出意外,系统会提示安装成功。

然后进入win的服务里面。启动zabbix服务就可以了。