centos6.2 lnmp环境下安装 zabbix(中文环境)并且监控客户端
本来也是新学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)
正在保存至: “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” )
# 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 开始增加数据库
# 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
# cd zabbix-1.8.2/create/schema/
# cat mysql.sql | mysql -uroot -p123456 zabbix
# cd ../data/
# cat data.sql | mysql -uroot -p123456 zabbix# 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)
正在保存至: “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” )
# 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 编译
# ./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,安装该软件包,解决该问题。
yum install -y net-snmp-develconfig.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! *
* *
*********************************************************** 完成编译 make && make install
make: Nothing to be done for `install-data-am'.
make: Leaving directory `/home/data/install/zabbix-1.8.2'
make: 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.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服务对应的端口
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 http://blog.运维网.com/attachment/201312/103847922.jpg
vim /etc/services
拷贝zabbix的配置文件到etc下,web相关文件拷贝到web目录下
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
修改数据库连接的数据库用户和密码
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=123456http://blog.运维网.com/attachment/201312/104553971.jpg
修改nginx配置
vim /home/data/websrv/nginx/conf/nginx.conf
server {
listen 80;
server_name192.168.0.19;
#access_log logs/zabbix_access.logmain;
location / {
root /home/data/www/html/request;
indexindex.html index.htm index.php;
}
location ~ \.php$ {
root /home/data/www/html/request;
fastcgi_pass 127.0.0.1:9000;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
fastcgi_indexindex.php;
include fastcgi_params;
}
}
}# service nginx start
Starting nginx daemon: nginx
启动zabbix
# /home/data/websrv/zabbix/sbin/zabbix_server
/home/data/websrv/zabbix/sbin/zabbix_server : User zabbix does not exist.
/home/data/websrv/zabbix/sbin/zabbix_server : Cannot run as root ! 启动时报错
用下面方法解决:
# useradd zabbix
# /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.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安装
http://blog.运维网.com/attachment/201312/110435985.jpg
http://blog.运维网.com/attachment/201312/110441379.jpg
http://blog.运维网.com/attachment/201312/110447395.jpg
如果有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支持
然后重新初始化
# cd /home/data/install/lnmp/php-5.3.16/ext/bcmath/
# /home/data/websrv/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
# ./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/
http://blog.运维网.com/attachment/201312/115401384.jpg
http://blog.运维网.com/attachment/201312/115404596.jpg
ok 已经支持
http://blog.运维网.com/attachment/201312/115522913.jpg
又发现新的报错
继续解决
进入数据库赋予权限
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)http://blog.运维网.com/attachment/201312/115828881.jpg
http://blog.运维网.com/attachment/201312/120413177.jpg
http://blog.运维网.com/attachment/201312/120418165.jpg
http://blog.运维网.com/attachment/201312/120423478.jpg
http://blog.运维网.com/attachment/201312/120429490.jpg
http://blog.运维网.com/attachment/201312/120436611.jpg
修改配置文件 并且给予权限 解决
# 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 默认的
否则永远进不去
http://blog.运维网.com/attachment/201312/121021223.jpg
http://blog.运维网.com/attachment/201312/121028313.jpg
http://blog.运维网.com/attachment/201312/122807745.jpg
调试一下 就变成中文界面了哈哈 这点是最好的!
现在我们监控客户端
http://blog.运维网.com/attachment/201312/123050190.jpg
客户端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<
zabbix_agent 10050/tcp
zabbix_trap 10051/tcp
EOF# cp /root/zabbix-2.0.5/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentd on# 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# chown -R zabbix.zabbix /var/log/zabbix
# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd: [确定]
# netstat -tnlp | grep --color zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 8126/zabbix_agentd 在zabbix的服务端执行下面的命令测试与客户端是否联通
# /home/data/websrv/zabbix/bin/zabbix_get -s 192.168.0.20 -p10050 -k"net.if.in"
21280557
主机(Host)是zabbix监控的基本载体,所有的监控都是基于主机(host)的。
依次点击配置(Configure)-->主机(Hosts)-->创建主机(Create Host)
http://blog.运维网.com/attachment/201312/130654676.jpg
http://blog.运维网.com/attachment/201312/132930317.jpghttp://blog.运维网.com/attachment/201312/133028870.jpg
http://blog.运维网.com/attachment/201312/133048309.jpg
http://blog.运维网.com/attachment/201312/133110530.jpg
到此试验完成。
zabbix强大的自定义和批量群组管理功能十分好用.而且个人感觉画的图比cacti好看!
最后解决乱码问题
http://blog.运维网.com/attachment/201312/134634767.jpg
http://blog.运维网.com/attachment/201312/134644406.jpg
http://blog.运维网.com/attachment/201312/134651719.jpg
# vi ./include/defines.inc.php
修改配置文件 然后重启服务端即可!
页:
[1]