zabbix使用tomcat进行web配置

tomcat安装和zabbix设置

tomcat的安装不做阐述,我是将已有的tomcat直接复制过来进行配置。
配置zabbix非常简单,进入zabbix压缩包的解压目录:

cp -r frontends/php/*   /tomcat/webapps/zabbix/

在tomcat的webapps目录下新建zabbix文件夹,将zabbix的php文件拷到这个目录下,必要时对相关文件进行权限修改:chmod 755,之后重新启动tomcat即可。访问http://10.x.x.107:8082/zabbix/setup.php 就可以看到zabbix的初始页面

zabbix初始化检查

参数错误

在访问zabbix初始页面后,到第二步会进行初始检查,得到错误信息如下:

Minimum required size of PHP post is 16M (configuration option "post_max_size").
Minimum required limit on execution time of PHP scripts is 300 (configuration option "max_execution_time").
Minimum required limit on input parse time for PHP scripts is 300 (configuration option "max_input_time").
Time zone for PHP is not set (configuration parameter "date.timezone").
PHP bcmath extension missing (PHP configuration parameter --enable-bcmath).
PHP gd JPEG image support missing.
PHP gd FreeType support missing.
PHP option "post_max_size"  8M  16M Fail
PHP option "max_execution_time" 30  300 Fail
PHP option "max_input_time" 60  300 Fail
PHP option "date.timezone"  unknown     Fail
PHP bcmath  off     Fail

前四个参数按照提示,修改/etc/php.ini中的参数:

post_max_size=16M
max_execution_time=300
max_input_time=300
date.timezone =Asia/Shanghai

修改完成重启php服务:

systemctl restart php-fpm

重新安装bcmatn

错误提示bcmath扩展缺失,所以需要重新安装。
通过yum install php-bcmath 安装后发现并没有生效。所以重新编译安装:
进入php解压文件 php-7.1.12/ext/bcmath/,之前通过make编译安装的,执行:

/usr/local/php7/bin/phpize 

此命令用于生产configure文件,结果报错:

Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

解决方案: yum install autoconf

生成configure文件成功后,执行:

./configure --with-php-config=/usr/local/php7/bin/php-config    #php安装目录
make
make install

执行成功后会在目录
/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303

下面生成一个bcmath.so文件,此时配置/etc/php.ini,指定拓展的路径

extension_dir =/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303
extension=bcmath.so
extension=gd.so    #后续添加
extension=libjpeg.so    #后续添加,继续阅读

重启php服务,成功解决bcmath的问题。

gd库jpeg和freetype支持

执行命令:

php -r 'print_r(gd_info());'

查看gd库支持的扩展如下:

PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'gd.so' in Unknown on line 0
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'libjpeg.so' in Unknown on line 0
Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 
    [XBM Support] => 1
    [WebP Support] => 
    [JIS-mapped Japanese Font Support] => 
)

可以看到,jpeg和freetype的状态都没有,未安装或者安装不正确。
我用yum安装:

yum install libjpeg
yum install libjpeg-devel
yum install freetype

安装完成并没有起作用,查找libjpeg.so 复制到**/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303**目录下,配置php.ini,增加 extension=libjpeg.so 重启php,依然没有作用。
将jpeg的tar.gz包下载下来,用make进行编译安装,重启php,没有作用。网上查找的具体解决方案是: 编译安装php的时候不要编译安装gd库,如果已经编译安装了要去掉–with-gd重新编译安装(试了多次先安装了gd库就是不成功),然后进入下列步骤。(注意此时jpeg和freetype已经安装了)

  1. 进入下载的源码包php-7.1.12/ext/gd目录下执行如下命令生成configure文件
/usr/local/php7/bin/phpize     
  1. 编译安装gd扩展
# ./configure --with-php-config=/usr/local/php7/bin/php-config --with-png-dir --with-freetype-dir 
--enable-shared --with-jpeg-dir  --enable-shared  --with-zlib-dir --with-gd
make
make test
make install

官方建议使用–enable-shared,安装成功会提示:/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303目录下会出现gd.so文件

  1. 把编译好的扩展添加到php.ini文件中
vi /etc/php.ini 
extension=gd.so   //添加gd扩展
  1. 完成后重启php。(如果要重新操作以上步骤,一定要在源码包gd目录下先执行make clean命令)

  2. 查看jpeg和freetype是否生效
    执行:

php -r 'print_r(gd_info());'

看到:

PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'libjpeg.so' in Unknown on line 0
Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 
    [XBM Support] => 1
    [WebP Support] => 
    [JIS-mapped Japanese Font Support] => 
)

jpeg和freetype扩展已经成功生效。重启php,重启zabbix_server,刷新页面,错误信息没有了。

zabbix页面错误总结

zabbi登录后提示:

A non well formed numeric value encountered [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CView->getOutput() → include() → make_status_of_zbx() → CFrontendSetup->checkRequirements() → CFrontendSetup->checkPhpMemoryLimit() → str2mem() in include/func.inc.php:410]
A non well formed numeric value encountered [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CView->getOutput() → include() → make_status_of_zbx() → CFrontendSetup->checkRequirements() → CFrontendSetup->checkPhpPostMaxSize() → str2mem() in include/func.inc.php:410]
A non well formed numeric value encountered [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CView->getOutput() → include() → make_status_of_zbx() → CFrontendSetup->checkRequirements() → CFrontendSetup->checkPhpUploadMaxFilesize() → str2mem() in include/func.inc.php:410]

网上查了一下,这是因为PHP 7.x版本类型强化,处理方法是找到Zabbix WEB目录下include/func.inc.php文件,修改它, 执行:

sed -i '/$last = strtolower(substr($val, -1));/a$val = substr($val,0,-1);' func.inc.php

问题依然未能解决,后来查看了一下func.inc.php代码,跳转到报错的位置#410,通过网上的解决方法分析,应该是val这个变量类型问题,在403行后添加一行

$val = substr($val,0,-1); 

保存修改后的文件,重新访问zabbix web界面即可.

首页底部区域黄色区域显示错误:

Zabbix server is not running:the information displayed may not be current

我的主要问题原因zabbix_server没有正确开启,之前没有注意,执行:

systemctl stop zabbix_server
systemctl start zabbix_server
 journalctl -xe

查看启动日志,发现是MySQL的连接问题:

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

可能还会有其他MySQL问题:权限、用户密码等等。根据 journalctl -xe或者/tmp/zabbix_server.log提示进行解决。


版权声明:本文为Ntozot原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。