本来也是新学zabbix ,所以今天做个试验,写下试验步骤

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

特点:

- 支持多语言(包括中文)

- 免费开源

- 自动发现服务器与网络设备

- 分布式监视以及WEB集中管理功能

- 可以无agent监视

- 用户安全认证和柔软的授权方式

- 通过WEB界面设置或查看监视结果

- email等通知功能

Zabbix主要功能:

- CPU负荷

- 内存使用

- 使用

- 网络状况

- 端口监视

- 日志监视

zabbix服务端192.168.0.19

zabbix客户端192.168.0.20

都是centos6.2 64位系统内存1024M

常用参数说明

--enable-server #安装zabbix server

--enable-proxy #安装zabbix proxy

--enable-agent #安装zabbix agent(如果不监控本机也可以不装)

--with-mysql #使用mysql做数据库

--with-net-snmp #支持snmp协议

--with-libcurl #支持curl,用于web服务监控

服务端:192.168.0.19

因为我lnmp 脚本已经安装后 编译安装的

在lnmp环境安装好后下载资源,lnmp 环境yum包

yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath

wget http://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8.2/zabbix-1.8.2.tar.gz--2013-12-17 18:33:47--  http://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8.2/zabbix-1.8.2.tar.gz正在解析主机 nchc.dl.sourceforge.net... 211.79.60.17, 2001:e10:ffff:1f02::17正在连接 nchc.dl.sourceforge.net|211.79.60.17|:80... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:3706540 (3.5M) [application/x-gzip]正在保存至: “zabbix-1.8.2.tar.gz.1”57% [==============================================================================================================>                                                                                     ] 2,116,760    677K/s eta(英国中部时61% [========================================================================================================================>                                                                           ] 2,293,904    688K/s eta(英国中部时68% [======================================================================================================================================>                                                             ] 2,556,716    722K/s eta(英国中部时72% [=============================================================================================================================================>                                                      ] 2,700,248    752K/s eta(英国中部时79% [==========================================================================================================================================================>                                         ] 2,948,756    850K/s eta(英国中部时85% [======================================================================================================================================================================>                             ] 3,176,720    896K/s eta(英国中部时91% [=================================================================================================================================================================================>                  ] 3,381,452    937K/s eta(英国中部时97% [==============================================================================================================================================================================================>     ] 3,628,292    983K/s eta(英国中部时100%[===================================================================================================================================================================================================>] 3,706,540    993K/s   in 4.6s2013-12-17 18:33:52 (795 KB/s) - 已保存 “zabbix-1.8.2.tar.gz.1” [3706540/3706540])

[root@ceshi install]# tar zxvf zabbix-1.8.2.tar.gzzabbix-1.8.2/src/zabbix_server/discoverer/Makefile.amzabbix-1.8.2/src/zabbix_server/poller/zabbix-1.8.2/src/zabbix_server/poller/poller.hzabbix-1.8.2/src/zabbix_server/poller/checks_ssh.czabbix-1.8.2/src/zabbix_server/poller/checks_internal.czabbix-1.8.2/src/zabbix_server/poller/checks_internal.hzabbix-1.8.2/man/zabbix_agentd.manzabbix-1.8.2/man/zabbix_proxy.manzabbix-1.8.2/man/zabbix_sender.man

开始增加数据库

[root@ceshi install]# mysql -uroot -p123456Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.1.60-log Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database zabbix;Query OK, 1 row affected (0.23 sec)mysql> Ctrl-C -- exit!Aborted[root@ceshi install]# cd zabbix-1.8.2/create/schema/[root@ceshi schema]# cat mysql.sql | mysql -uroot -p123456 zabbix[root@ceshi schema]# cd ../data/[root@ceshi data]# cat data.sql | mysql -uroot -p123456 zabbix
[root@ceshi install]# wget http://iksemel.googlecode.com/files/iksemel-1.4.tar.gz--2013-12-17 18:44:56--  http://iksemel.googlecode.com/files/iksemel-1.4.tar.gz正在解析主机 iksemel.googlecode.com... 74.125.128.82, 2404:6800:4005:c00::52正在连接 iksemel.googlecode.com|74.125.128.82|:80... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:515581 (503K) [application/x-gzip]正在保存至: “iksemel-1.4.tar.gz”100%[======================================>] 515,581     1.06M/s   in 0.5s2013-12-17 18:44:57 (1.06 MB/s) - 已保存 “iksemel-1.4.tar.gz” [515581/515581])

[root@ceshi install]# tar zxvf iksemel-1.4.tar.gziksemel-1.4/src/Makefile.amiksemel-1.4/src/io-posix.ciksemel-1.4/src/base64.ciksemel-1.4/src/Makefile.iniksemel-1.4/src/dom.ciksemel-1.4/src/utility.ciksemel-1.4/config.subiksemel-1.4/Makefile.amiksemel-1.4/aclocal.m4iksemel-1.4/configureiksemel-1.4/install-shiksemel-1.4/NEWS

编译

[root@ceshi iksemel-1.4]# ./configurechecking whether we are using the GNU Fortran 77 compiler... yeschecking whether g77 accepts -g... yeschecking the maximum length of command line arguments... 100663296checking command to parse /usr/bin/nm -B output from gcc object... okchecking for objdir... .libschecking for ar... ar86_64) supports shared libraries... yeschecking whether -lc should be explicitly linked in... nochecking dynamic linker characteristics... GNU/Linux ld.sochecking how to hardcode library paths into programs... immediatechecking whether stripping libraries is possible... yesconfig.status: executing depfiles commands

make && make install

cd zabbix-1.8.2

./configure --prefix=/home/data/websrv/zabbix --enable-server --enable-agent --enable-proxy \

--with-mysql=/home/data/websrv/mysql/bin/mysql_config --with-net-snmp --with-libcurl

checking for hstrerror... yes

checking for atoll... yes

checking for getopt_long... yes

checking for strcasestr... yes

checking for getenv... yes

checking for putenv... yes

checking if Oracle support is enabled... no

checking for mysql_config... /home/data/websrv/mysql/bin/mysql_config

checking for main in -lmysqlclient ... yes

checking for function PQserverVersion()... no

checking for Zabbix server database selection... ok

checking for pkg-config... /usr/bin/pkg-config

checking pkg-config is at least version 0.9.0... yes

checking for gawk... (cached) gawk

checking for curl-config... /usr/bin/curl-config

checking for the version of libcurl... 7.19.7

checking for libcurl >= version 7.13.1... yes

checking for main in -lcurl... yes

checking whether libcurl is usable... yes

checking for curl_free... yes

checking for net-snmp-config... no

configure: error: Invalid NET-SNMP directory - unable to find net-snmp-config

报错信息

编译安装zabbix时,配置时报错以上,导致检测系统环境不成功。提示unable to find net-snmp-config,说明缺少相关的依赖性。

这是因为,在linux中,大多数软件都是开源的,并且可以自由使用。因此在开发时可以用到其他的软件包时我们直接就拿来了,不用在花功夫去重新编写,这就造成了所谓的依赖性。

那么怎么解决该问题那?

解决办法一

找出net-snmp-config属于哪个软件包,然后安装即可。

yum search net-snmp-config,发现net-snmp-config属于软件包net-snmp-devel,安装该软件包,解决该问题。

yum install -y net-snmp-devel
config.status: creating src/zabbix_proxy/heart/Makefileconfig.status: creating src/zabbix_proxy/housekeeper/Makefileconfig.status: creating src/zabbix_proxy/proxyconfig/Makefileconfig.status: creating src/zabbix_proxy/datasender/Makefileconfig.status: creating upgrades/Makefileconfig.status: creating man/Makefileconfig.status: creating include/config.hconfig.status: executing depfiles commandsConfiguration:  Detected OS:           linux-gnu  Install path:          /home/data/websrv/zabbix  Compilation arch:      linux  Compiler:              gcc  Compiler flags:        -g -O2   -I/home/data/websrv/mysql/include/mysql  -g -DUNIV_LINUX     -I/usr/include/rpm -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include  Enable server:         yes  With database:         MySQL  WEB Monitoring via:    cURL  Native Jabber:         no  SNMP:                  net-snmp  IPMI:                  no  Linker flags:                  -L/home/data/websrv/mysql/lib/mysql    -lcurl  -L/usr/lib64 -lnetsnmp -lcrypto  -L/usr/lib64 -lnetsnmp -lcrypto  Libraries:             -lm  -lresolv -liconv    -lmysqlclient    -lcurl  -lnetsnmp  Enable proxy:          yes  With database:         MySQL  WEB Monitoring via:    cURL  SNMP:                  net-snmp  IPMI:                  no  Linker flags:                  -L/home/data/websrv/mysql/lib/mysql   -lcurl  -L/usr/lib64 -lnetsnmp -lcrypto  -L/usr/lib64 -lnetsnmp -lcrypto  Libraries:             -lm  -lresolv -liconv    -lmysqlclient   -lcurl  -lnetsnmp  Enable agent:          yes  Linker flags:  Libraries:             -lm  -lresolv -liconv  LDAP support:          no  IPv6 support:          no************************************************************            Now run 'make install'                       **                                                         **            Thank you for using Zabbix!                  **              
************************************************************

完成编译 make && make install

make[2]: Nothing to be done for `install-data-am'.make[2]: Leaving directory `/home/data/install/zabbix-1.8.2'make[1]: Leaving directory `/home/data/install/zabbix-1.8.2'

修改PHP配置文件php.ini内容使其满足zabbix安装配置需求

sed -i 's/^\(.*\)date.timezone =.*$/date.timezone = Asia\/Shanghai/g' /home/data/websrv/php/etc/php.inised -i 's/^\(.*\)post_max_size =.*$/post_max_size = 16M/g' /home/data/websrv/php/etc/php.inised -i 's/^\(.*\)max_execution_time =.*$/max_execution_time = 300/g' /home/data/websrv/php/etc/php.inised -i 's/^\(.*\)max_input_time =.*$/max_input_time = 300/g' /home/data/websrv/php/etc/php.ini

添加zabbix服务对应的端口

com-bardac-dw   48556/tcp               # com-bardac-dwcom-bardac-dw   48556/udp               # com-bardac-dwiqobject        48619/tcp               # iqobjectiqobject        48619/udp               # iqobjectzabbix-agent 10050/tcp Zabbix Agentzabbix-agent 10050/udp Zabbix Agentzabbix-trapper 10051/tcp Zabbix Trapperzabbix-trapper 10051/udp Zabbix Trapper

vim /etc/services

拷贝zabbix的配置文件到etc下,web相关文件拷贝到web目录下

cd zabbix-1.8.2mkdir -p /etc/zabbixcp misc/conf/*  /etc/zabbixcp -r frontends/php /home/data/www/html/request

vi /etc/zabbix/zabbix_server.conf

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

DBName=zabbix### Option: DBUser#       Database user. Ignored for SQLite.## Mandatory: no# Default:# DBUser=DBUser=zabbix### Option: DBPassword#       Database password. Ignored for SQLite.#       Comment this line if no password is used.## Mandatory: no# Default:DBPassword=123456

修改nginx配置

vim /home/data/websrv/nginx/conf/nginx.confserver {listen       80;server_name  192.168.0.19;#access_log   logs/zabbix_access.log  main;location / {root   /home/data/www/html/request;index  index.html index.htm index.php;}location ~ \.php$ {root   /home/data/www/html/request;fastcgi_pass   127.0.0.1:9000;fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;fastcgi_index  index.php;include        fastcgi_params;}}}
[root@ceshi zabbix-1.8.2]# service nginx startStarting nginx daemon: nginx

启动zabbix

[root@ceshi zabbix-1.8.2]# /home/data/websrv/zabbix/sbin/zabbix_server/home/data/websrv/zabbix/sbin/zabbix_server [7375]: User zabbix does not exist./home/data/websrv/zabbix/sbin/zabbix_server [7375]: Cannot run as root !

启动时报错

用下面方法解决:

[root@ceshi zabbix-1.8.2]# useradd zabbix

[root@ceshi zabbix-1.8.2]# /home/data/websrv/zabbix/sbin/zabbix_server

如果其他启动报错、zabbix_server: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory因为我的 mysql client 库不在系统默认库中,做以下修改后重新启动就可以了:echo /usr/local/mysql/lib/mysql/ >> /etc/ld.so.confldconfig* 启动 Zabbix Agentd/etc/init.d/zabbix-agentd start# /etc/init.d/zabbix-agentd startStarting zabbix_agentd: /home/data/websrv/zabbix/sbin/zabbix_agentd: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such fileor directory用下面方法解决:# echo /usr/local/lib/ >> /etc/ld.so.conf# ldconfig

进行zabbix安装

如果有faild的项目,请以如下方法逐一解决:

PHP version:PHP版本,要求5.1.6以上
PHP memory limit:修改php.ini文件“memory_limit”参数
PHP post max size:修改php.ini文件“post_max_size”参数
PHP upload max filesize:修改php.ini文件“upload_max_filesize”参数
PHP max execution time:修改php.ini文件“max_execution_time”参数
PHP max input time:修改php.ini文件“max_input_time”参数
PHP timezone:修改php.ini文件“date.timezone”参数,改为Asia/Shanghai
PHP database support:如果使用的是MySQL数据库,则需要安装php-mysql库支持,我的系统是CentOS 5,因此我直接yum install php-mysql即可
PHP BC math:需要安装BC_math库
PHP MB string:需要安装php-mbstring库,我直接yum install php-mbstring就装好了
PHP Sockets:需要安装php socket库
PHP GD:需要安装php-gd库,yum install php-gd
GD PNG Support:需要安装GD库的PNG扩展支持
libxml module:需要安装php-xml库,yum install php-xml
ctype module:需要php ctype支持

然后重新初始化

[root@ceshi php-5.3.16]# cd /home/data/install/lnmp/php-5.3.16/ext/bcmath/[root@ceshi bcmath]# /home/data/websrv/php/bin/phpizeConfiguring for:PHP Api Version:         20090626Zend Module Api No:      20090626Zend Extension Api No:   220090626[root@ceshi bcmath]# ./configure --with-php-config=/home/data/websrv/php/bin/php-configappending configuration tag "CXX" to libtoolconfigure: creating ./config.statusconfig.status: creating config.hmake && make installInstalling shared extensions:     /home/data/websrv/php/lib/php/extensions/no-debug-non-zts-20090626/vim php.iniextension=/home/data/websrv/php/lib/php/extensions/no-debug-non-zts-20090626/

ok 已经支持

又发现新的报错

继续解决

进入数据库赋予权限mysql> grant all on *.* to 'zabbix'@'%' identified by '123456';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

修改配置文件 并且给予权限 解决[root@ceshi php]# chmod 777 confvi zabbix.conf.php.exampleglobal $DB;$DB["TYPE"]     = 'MYSQL';$DB["SERVER"]       = '192.168.0.19';$DB["PORT"]     = '3306';$DB["DATABASE"]     = 'zabbix';$DB["USER"]     = 'zabbix';$DB["PASSWORD"]     = '123456';$ZBX_SERVER     = '192.168.0.19';$ZBX_SERVER_PORT    = '10051';$IMAGE_FORMAT_DEFAULT   = IMAGE_FORMAT_PNG;?>

用户名是admin,密码zabbix 默认的

否则永远进不去

调试一下 就变成中文界面了哈哈 这点是最好的!

现在我们监控客户端

客户端192.168.0.20

# wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.5/zabbix-2.0.5.tar.gz# tar xvf zabbix-2.0.5.tar.gz# cd zabbix-2.0.5# ./configure --prefix=/usr/local/zabbix --enable-agent# make && make install添加服务cat>>/etc/services
[root@puttet zabbix-2.0.5]# cp /root/zabbix-2.0.5/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/[root@puttet zabbix-2.0.5]# sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd[root@puttet zabbix-2.0.5]# chkconfig --add zabbix_agentd[root@puttet zabbix-2.0.5]# chkconfig zabbix_agentd on
# vim /usr/local/zabbix/etc/zabbix_agentd.confServer=192.168.0.20              //配置zabbix服务器的IP地址Hostname=linux_client           //配置主机名PidFile=/var/tmp/zabbix_agentd.pid //指定pid路径LogFile=/var/log/zabbix/zabbix_agentd.log   //指定日志文件保存退出#mkdir /var/log/zabbix#touch /var/log/zabbix/zabbix_agentd.log#chown -R zabbix.zabbix /var/log/zabbix
[root@puttet zabbix-2.0.5]# chown -R zabbix.zabbix /var/log/zabbix[root@puttet zabbix-2.0.5]# /etc/init.d/zabbix_agentd startStarting zabbix_agentd:                                    [确定][root@puttet zabbix-2.0.5]# netstat -tnlp | grep --color zabbixtcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      8126/zabbix_agentd

在zabbix的服务端执行下面的命令测试与客户端是否联通

[root@ceshi php]# /home/data/websrv/zabbix/bin/zabbix_get -s 192.168.0.20 -p10050 -k"net.if.in[eth0,bytes]"21280557

 
主机(Host)是zabbix监控的基本载体,所有的监控都是基于主机(host)的。

依次点击配置(Configure)-->主机(Hosts)-->创建主机(Create Host)

到此试验完成。

zabbix强大的自定义和批量群组管理功能十分好用.而且个人感觉画的图比cacti好看!

最后解决乱码问题

[root@ceshi php]# vi ./include/defines.inc.php

修改配置文件 然后重启服务端即可!