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

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

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包

1
yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath
1
2
3
4
5
6
7
8
9
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.6s
2013-12-17 18:33:52 (795 KB/s) - 已保存 “zabbix-1.8.2.tar.gz.1” [3706540/3706540])
1
2
3
4
5
6
7
8
9
10
[root@ceshi install]# tar zxvf zabbix-1.8.2.tar.gz
zabbix-1.8.2/src/zabbix_server/discoverer/Makefile.am
zabbix-1.8.2/src/zabbix_server/poller/
zabbix-1.8.2/src/zabbix_server/poller/poller.h
zabbix-1.8.2/src/zabbix_server/poller/checks_ssh.c
zabbix-1.8.2/src/zabbix_server/poller/checks_internal.c
zabbix-1.8.2/src/zabbix_server/poller/checks_internal.h
zabbix-1.8.2/man/zabbix_agentd.man
zabbix-1.8.2/man/zabbix_proxy.man
zabbix-1.8.2/man/zabbix_sender.man

开始增加数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@ceshi install]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.60-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
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
1
2
3
4
5
6
7
8
9
[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.5s
2013-12-17 18:44:57 (1.06 MB/s) - 已保存 “iksemel-1.4.tar.gz” [515581/515581])
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@ceshi install]# tar zxvf iksemel-1.4.tar.gz
iksemel-1.4/src/Makefile.am
iksemel-1.4/src/io-posix.c
iksemel-1.4/src/base64.c
iksemel-1.4/src/Makefile.in
iksemel-1.4/src/dom.c
iksemel-1.4/src/utility.c
iksemel-1.4/config.sub
iksemel-1.4/Makefile.am
iksemel-1.4/aclocal.m4
iksemel-1.4/configure
iksemel-1.4/install-sh
iksemel-1.4/NEWS

编译

1
2
3
4
5
6
7
8
9
10
11
12
[root@ceshi iksemel-1.4]# ./configure
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether g77 accepts -g... yes
checking the maximum length of command line arguments... 100663296
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for objdir... .libs
checking for ar... ar86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
config.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,安装该软件包,解决该问题。

1
yum install -y net-snmp-devel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
config.status: creating src/zabbix_proxy/heart/Makefile
config.status: creating src/zabbix_proxy/housekeeper/Makefile
config.status: creating src/zabbix_proxy/proxyconfig/Makefile
config.status: creating src/zabbix_proxy/datasender/Makefile
config.status: creating upgrades/Makefile
config.status: creating man/Makefile
config.status: creating include/config.h
config.status: executing depfiles commands
Configuration:
  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!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

完成编译 make && make install

1
2
3
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安装配置需求

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

添加zabbix服务对应的端口

1
2
3
4
5
6
7
8
com-bardac-dw   48556/tcp               # com-bardac-dw
com-bardac-dw   48556/udp               # com-bardac-dw
iqobject        48619/tcp               # iqobject
iqobject        48619/udp               # iqobject
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

vim /etc/services

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

1
2
3
4
cd zabbix-1.8.2
mkdir -p /etc/zabbix
cp misc/conf//etc/zabbix
cp -r frontends/php /home/data/www/html/request

vi /etc/zabbix/zabbix_server.conf

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

修改nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
vim /home/data/websrv/nginx/conf/nginx.conf
server {
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;
}
}
}
1
2
[root@ceshi zabbix-1.8.2]# service nginx start
Starting nginx daemon: nginx

启动zabbix

1
2
3
[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

1
2
3
4
5
6
7
8
9
10
11
12
如果其他启动报错、
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.conf
ldconfig
* 启动 Zabbix Agentd
/etc/init.d/zabbix-agentd start
# /etc/init.d/zabbix-agentd start
Starting 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安装

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

如果有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支持

然后重新初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[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/phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
[root@ceshi bcmath]# ./configure --with-php-config=/home/data/websrv/php/bin/php-config
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
make && make install
Installing shared extensions:     /home/data/websrv/php/lib/php/extensions/no-debug-non-zts-20090626/
vim php.ini
extension=/home/data/websrv/php/lib/php/extensions/no-debug-non-zts-20090626/

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

ok 已经支持

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

又发现新的报错

继续解决

1
2
3
4
5
进入数据库赋予权限
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)

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

1
2
3
4
5
6
7
8
9
10
11
12
13
14
修改配置文件 并且给予权限 解决
[root@ceshi php]# chmod 777 conf
vi zabbix.conf.php.example
global $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 默认的

否则永远进不去

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

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

现在我们监控客户端

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

客户端192.168.0.20

1
2
3
4
5
6
7
8
9
10
# 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<
zabbix_agent 10050/tcp
zabbix_trap 10051/tcp
EOF
1
2
3
4
[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
1
2
3
4
5
6
7
8
9
# vim /usr/local/zabbix/etc/zabbix_agentd.conf
Server=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
1
2
3
4
5
[root@puttet zabbix-2.0.5]# chown -R zabbix.zabbix /var/log/zabbix
[root@puttet zabbix-2.0.5]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd:                                    [确定]
[root@puttet zabbix-2.0.5]# netstat -tnlp | grep --color zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      8126/zabbix_agentd

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

1
2
[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)

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrongcentos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

到此试验完成。

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

最后解决乱码问题

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

centos6.2 lnmp环境下安装 zabbix(中文环境)-chenhao&rongrong

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

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