centos 下的zabbix以及常见问题

来源:互联网 发布:伤感好听的网络歌曲 编辑:程序博客网 时间:2024/06/07 17:18
准备工作搭建lamp

1、安装开发软件包

yum  -y groupinstall  "Development Tools"

2、安装所需的依赖包

yum -y install httpd mysql mysql-server php php-mysql php-common php-mbstring php-gd php-odbc php-pear curl curl-devel net-snmp net-snmp-devel perl-DBI php-xml ntpdate  php-bcmath

3、同步服务端的时间,保持所有服务器时间一致避免出现时间不同导致的不可用的监控数据

ntpdate pool.ntp.rog

4、创建zabbix服务运行所需要的用户和组

groupadd  -g 201  zabbix

useradd  -g zabbix  -u 201 -m zabbix

5、初始化mysql服务器

/etc/init.d/mysqld start

6、创建zabbix运行所需要的数据库及用户权限

mysqladmin  -uroot -h127.0.0.1  password "123456"

mysql -uroot -h127.0.0.1 -p

create database zabbix character set utf8;

grant all privileges on zabbix.* to zabbixuser@'%' identified by '123456';

flush privileges;

7、下载解压zabbix

wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz/download

cd /usr/src/

tar xf zabbix-2.2.2.tar.gz

8、将zabbix的初始数据导入到数据库中

cd zabbix-2.2.2
mysql -uzabbixuser -h(mysql的ip) -p zabbix <database/mysql/schema.sql

mysql -uzabbixuser -h192.168.239.130 -p zabbix <database/mysql/images.sql

mysql -uzabbixuser -h192.168.239.130 -p zabbix <database/mysql/data.sql

#登录数据库查看下表是否都创建成功

9、编译安装zabbix

./configure –sysconfdir=/etc/zabbix/ –enable-server –enable-agent –with-net-snmp –with-libcurl –with-mysql

make && make install

#此处指定sysconfdir配置文件的路径就在/etc/zabbix/目录下了,如果不指定默认在/usr/local/etc下

10、Copy zabbixserver端跟agent端的启动脚本,并设置执行权限

cp misc/init.d/tru64/zabbix_agentd /etc/init.d/

cp misc/init.d/tru64/zabbix_server /etc/init.d/

chmod +x /etc/init.d/zabbix_*

11、将zabbix的页面文件copy到指定目录(跟apache配置的相同即可)

mkdir /var/www/html/zabbix

cp -a  zabbix-2.2.2/frontends/php/* /var/www/html/zabbix/

chown -R  apache.apache /var/www/html/zabbix/

12、配置php文件,适应zabbix安装所需的参数

vim /etc/php.ini

date.timezone = Asia/Chongqing

max_execution_time = 300

max_input_time = 300

post_max_size = 32M

memory_limit = 128M

mbstring.func_overload = 2

13、配置apache文件,定义安装访问zabbix的虚拟主机

vim /etc/httpd/conf/httpd.conf

ServerName 127.0.0.1

<VirtualHost *:80>

 DocumentRoot  "/var/www/html"

 ServerName 192.168.239.130

</VirtualHost>

14、配置zabbix server端的文件,定义数据库的IP、用户名、密码

vim /etc/zabbix/etc/zabbix_server.conf

DBHost=192.168.239.130              # 本机ip

DBName= zabbix 

DBUser=zabbixuser

DBPassword=123456

StartPollers=30                         #开启多线程数,一般不要超过30个

StartTrappers=20                        #trapper线程数

StartPingers=10                         #fping线程数

StartDiscoverers=120            

MaxHousekeeperDelete=5000       

CacheSize=1024M                         #用来保存监控数据的缓存数,根据监控主机的数量适当调整

StartDBSyncers=8                        #数据库同步时间

HistoryCacheSize=1024M          

TrendCacheSize=128M                     #总趋势缓存大小

HistoryTextCacheSize=512M

AlertScriptsPath=/etc/zabbix/alertscripts

LogSlowQueries=1000

15、启动apache服务跟zabbix服务

/etc/init.d/httpd start

/etc/init.d/zabbix_server start

16、访问安装界面按照界面提示一步一步的完成安装

http://192.168.239.130/zabbix/setup.php
     a) 进入安装界面点击Next
     b) 确保所有的监测项都是OK,点击Next
                c) 填写zabbix数据库的用户名、密码、地址等信息,点击Test connection,OK后点击Next
                 d) 填写zabbix服务器的信息,主机名,server程序监听的的端口,主机IP地址等,如果server跟web在一台服务器上保持默认即可,点击Next
                  e) 确认前面几部填写的信息没有问题的话点击Next
                f) 进入登录界面点击登录,默认admin  zabbix
#至此,server端的安装完成

Agent端

1、安装开发软件包

yum -y groupinstall "Development Tools"

yum –y install ntpdate

2、同步客户端时间,防止跟服务器端不一致,导致检测到不可用的监控数据

ntpdate pool.ntp.org

3、创建zabbix运行所需要的用户跟组

groupadd  -g 201 zabbix

useradd -g zabbix -u 201 -m zabbix

4、解压安装zabbixagent端

cd /usr/src/

tar xf zabbix-2.2.2.tar.gz

cd zabbix-2.2.2

./configure –sysconfdir=/etc/zabbix –enable-agent

make && make install

5、copy agent端运行所需要的脚本

cp misc/init.d/tru64/zabbix_agentd /etc/init.d/

chmod +x /etc/init.d/zabbix_agentd

6、配置agent端配置文件

vim /etc/zabbix/zabbix_agentd.conf       #此处千万别写成了zabbix_agent.conf,否则配置了不生效

Server=192.168.239.130                   #填写Server的IP地址

ServerActive=192.168.239.130             #修改为Server的IP地址

Hostname=Centos-03                       #填写本机的HostName,注意Server端要能解析

UnsafeUserParameters=1                   #是否允许自定义的key,1为允许,0为不允许

Include= etc/zabbix/zabbix_agentd.conf.d/#自定义的agentd配置文件(key)可以在这里面写;

7、启动zabbix agent端

/etc/init.d/zabbix_agentd start



问题汇总
     

在linux系统中,几乎所有运行的服务都会产生相对就的日志(log),所运行的程序在出错时都会有错误提示,即使没有任何提示也可以通过“echo $”来查看运行是否成功。使用zabbix已经有一段时间了,整理一下遇到过的问题和解决的方法以。
zabbix的日志存放在/tmp下,服务器端对应的日志是zabbix_server.log,被监控端对应的日志是zabbix_agentd.log.
一,zabbix服务是否已经开启成功
查看系统是否已经有zabbix进程正在运行 # ps aux |grep zabbix 查看系统是否已监听zabbix server和zabbix agent所使用的10050、10051端口 # netstat -nplut |grep zabbix 如果没有,则开启:#/etc/init.d/zabbix_server_ctl start #/etc/init.d/zabbix_agent_ctl start
特别需要注意的是:每次修改完配置文件之后都需要重新启动对应的zabbix server或者zabbix agentd。
部分运行脚本在做restart时无法关闭zabbix导致服务无法重新启动,可用kill的命令把zabbix相关的进程杀掉再启动。

二、zabbix_server.log出现的提示
2009:20121023:193549.354 Sending list of active checks to [192.168.30.3] failed: host [CentOS-3] not found
这是因为zabbix_agentd.conf配置文件中的Hostname与web中的主机名对应。

三、网页中了出现的错误
(1)

Get value from agent failed: cannot connect to [[192.168.30.2]:10050]: [111] Connection refused
192.168.30.2是我的zabbix server服务器,本身也有监控自己本身的agent功能。出现这种错误是因为忘记在zabbix服务器开户zabbix_agentd。在Last 20 issues中也有提示
Last 20 issues



HostIssueLast changeAgeAckActionsZabbix serverServer Zabbix server is unreachable23 Oct 2012 18:42:146m 57sNo
-
解决方法:开启zabbix_agentd即可。



(2)

Get value from agent failed: cannot connect to [[192.168.30.3]:10050]: [113] No route to host
看提示“No route to host”,与网络连接有关。排除的方法如下:
a)查看192.168.30.3这台机器是否已开机
b)在zabbix server端向这台机器ping,看网络是否通
c)用telnet 登录10050和10051端口,看该主机是否允许这两个端口通讯
d)查看iptables防火墙规则是否拦截10050、10051端口



(3)
网页中不停地有以下红色提示:
zabbix server is not running: the information displayed may not be current.

zabbix 遇到上面的问题

可以从以下几个方面入手检查,当然先查日志,如果不想查日志,先检查下面几项是否正常

1. selinux是否关闭。

2. zabbix web目录下面  $ZBX_SERVER 是否为ip,如果是localhost,ping下localhost是否能解析。

3.查看php的fsockopen模块是否启用。


zabbix server is running | No.
查看/tmp/zabbix_server.log和/tmp/zabbix_agent.log无任何异常。看zabbix_server和zabbix_agent进程、端口都正常……几翻google以后并尝试,终于得到了解决!
http://www.zabbix.com/forum/showthread.php?t=23878&page=3 这里面有说到zabbix受selinux的影响而已有这种错误提示。
http://www.zabbix.com/forum/showthread.php?t=25321 这里面说到了修改hostname为IP的做法。
我具体的做法是:
①查看selinux产生的log,确实有错误提示:

#tail -f /var/log/audit/audit.log
type=AVC msg=audit(1351863204.990:32): avc:  denied  { name_connect } for  pid=1575 comm="httpd" dest=10051 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1351863204.990:32): arch=40000003 syscall=102 success=no exit=-13 a0=3 a1=bfd494b0 a2=b76b0ad8 a3=d items=0 ppid=1434 pid=1575 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
②然后让selinux允许它通过
setsebool -P httpd_can_network_connect on
③编辑zabbix.conf.php文件,把$ZBX_SERVER的值改为本机的IP地址
$ZBX_SERVER  = '192.168.30.2'; #######用IP代替
④OK
四、
tail /tmp/zabbix_server.log  显示
50952:20141012:195519.884 One child process died (PID:51233,exitcode/signal:255). Exiting ...
表示一个子进程死掉,是一个zabbix内存溢出错误 (此错误同样会造成上面红色的闪烁)
更正:
  • vim /etc/zabbix/zabbix_server.conf
  • CacheSize=512M
  • 修改此值后OK


五、 tail /tmp/zabbix_server.log 显示
   2552:20141012:211700.552 [Z3001] connection to database 'zabbix' failed: [1040] Too many connections
是由于连接到数据库的数量比较多,mysql 默认的连接数是100,一般设置到500~1000比较合适,我们可以调大这个值:修改/etc/my.cnf这个文件,在[mysqld]中新增max_connections=1000
然后重启mysql和zabbix_server zabbix_agent

用户自定义脚本监控:
a)
有时候用户自定义的脚本运行的时间可能比较长,如超过10秒的20秒的。这时在执行zabbix_agentd -p 或者zabbix_agentd -t时就可能出现“Alarm clock”,从而得不到想要的结果。这是因为zabbix agentd配置文件中定义Timeout时间默认为3秒,脚本运行取结果的时间超过了3秒就会出现这种情况。
解决方法:编辑配置文件/etc/zabbix/zabbix_agentd.conf,找到"Timeout"把它定义为30秒或小于30秒。
b)
对a中的情况还需要注意对zabbix服务器端的配置,如我自己定义的脚本
UserParameter=ping.avgtime,ping 192.168.30.2 -c 10 -w 29 |grep 'avg' |awk -F "/" '{print $5}' 对192.168.30.2 ping 10取平均值,-w参数是对ping限定时间为29秒
这个脚本运行的大概时间为10秒左右,此时在agent端虽然可以用zabbix_agentd -t得到结果,但是在zabbix服务器端日志会不断的出现

1762:20121023:191941.360 resuming Zabbix agent checks on host [Zabbix server]: connection restored
  1761:20121023:191952.149 Zabbix agent item [ping.avgtime] on host [CentOS-3] failed: first network error, wait for 15 seconds
  1762:20121023:192010.610 Zabbix agent item [ping.avgtime] on host [CentOS-3] failed: another network error, wait for 15 seconds
  1762:20121023:192028.628 Zabbix agent item [ping.avgtime] on host [CentOS-3] failed: another network error, wait for 15 seconds

这样的错误日志,并且在web端也没有画出图来。
解决方法:
①编辑zabbix服务器端的配置文件/etc/zabbix/zabbix_server.conf找到"Timeout"把它定义为30秒或小于30秒。
②如果还有类似提示则应该是zabbix服务器的内存设置得太小了,加大服务器内存便可
④OK

原创粉丝点击