目錄
寫在前面:不建議使用官網教程在Centos6 安裝Zabbix4.2
背景:
在以下環境安裝 zabbix 4.2(參考官網教程)
OS:CentOS release 6.10 (Final) ;
httpd :Server version: Apache/2.2.15 (Unix)
PHP:5.3 (由於不支持zabbix4.2 ,將PHP5.4以上版本)
啓動 zabbix-server zabbix-agent httpd 三個服務後 訪問 http://ip:port/zabbix/
問題1描述:
-
頁面提示如下錯誤 (500)
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.2.15 (CentOS) Server at 172.16.18.36 Port 8080
-
error_log日誌顯示:
[crit] [client 172.16.10.193] configuration error: couldn't perform authentication. AuthType not set!: /zabbix/
原因:
Apache httpd 服務器不同版本的權限設置問題
解決:
打開配置文件,
# vim /etc/zabbix/zabbix_server.conf
註釋掉第三行(以標紅)
7 <Directory "/usr/share/zabbix">
8 Options FollowSymLinks
9 AllowOverride None
10 #Require all granted
因爲該環境的httpd版本是 2.2 小於2.4 ,大於等於2.4的版本使用上述語句。
重啓服務器 :
#service httpd restart
問題2描述:
- 頁面顯示:(403 Forbidden)
Forbidden
You don't have permission to access /zabbix/ on this server.
Apache/2.2.15 (CentOS) Server at 172.16.18.36 Port 8080
- error_log日誌顯示:
[error] [client 172.16.10.193] Directory index forbidden by Options directive: /usr/share/zabbix/
原因:
/etc/httpd/conf.d 目錄下缺少 php.conf 文件
解決:
在/etc/httpd/conf.d 目錄下 添加
php.conf 文件,內容爲
#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
#
# Allow php to handle Multiviews
#
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following lines to allow PHP to pretty-print .phps
# files as PHP source code:
#
#<FilesMatch \.phps$>
# SetHandler application/x-httpd-php-source
#</FilesMatch>
#
# Apache specific PHP configuration options
# those can be override in each configured vhost
#
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
問題3描述:
打開網頁無法正常顯示
httpd日誌顯示:Parse error: syntax error, unexpected '[' **** in /usr/share/zabbix/index.php on line 29
原因:
php版不支持,Zabbix 3.0 以上的版本需要 PHP 5.4.0以上版本支持
PHP | 5.4.0 or later |
解決:
卸載原裝php安裝新的php,具體安裝方法參考下面的問題3參考。
問題4描述:
運行#service httpd restart
出現:
Starting httpd: Syntax error on line 31 of /etc/httpd/conf.d/php.conf:
Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
[FAILED]
原因:
php 版本不匹配
解決:
修改 /etc/httpd/conf/httpd.conf 文件 ;
添加 LoadModule php5_module modules/libphp5.so
問題5描述:
運行網頁無法打開,
打開httpd日誌 (# tail /var/log/httpd/error_log) 顯示如下錯誤
PHP Fatal error: Call to undefined function bccomp() in /usr/share/zabbix/include/classes/setup/CFrontendSetup.php on line 122
原因:
php 不支持,需安裝更新包
解決:
安裝 php-bcmath 、 php-mbstring, 重啓 httpd 服務
# yum -y install php-bcmath
# yum -y install php-mbstring
# service httpd restart
問題6描述:
- 打開網頁顯示:404
Not Found
The requested URL /zabbix/ was not found on this server.
Apache/2.2.15 (CentOS) Server at 172.16.18.36 Port 80
- httpd日誌顯示:
[error] [client 172.16.10.193] File does not exist: /var/www/html/zabbix
原因:
/etc/httpd/conf.d 目錄下缺少 zabbix.conf (zabbix的配置)文件
解決:
從/usr/share/doc/zabbix-web-4.2.1/ 目標下複製 httpd22-example.conf (因爲環境的httpd的版本是2.2 ,如果是2.4 複製httpd24-example.conf)文件到 /etc/httpd/conf.d ;
修改 時區:php_value date.timezone Asia/ShangHai
重啓httpd服務;
#cp /usr/share/doc/zabbix-web-4.2.1/httpd22-example.conf /etc/httpd/conf.d/
#vim /etc/httpd/conf.d/httpd22-example.conf
#service httpd restart
如果沒有找到httpd22-example.conf文件,在/etc/httpd/conf.d/ 目錄建立 zabbix.conf (適用於httpd2.2版本) 文件 內容如下:
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/ShangHai
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/app">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/include">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/local">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
這裏附錄httpd 2.4需要的zabbix.conf 文件內容。
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/ShangHai
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/app">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/include">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/local">
Require all denied
</Directory>
問題7描述:
打開網頁無法正常顯示,亂碼如下:
[T_ZBX_STR, O_NO, null, null, 'isset({enter}) && {enter} != "'.ZBX_GUEST_USER.'"', _('Username')], 'password' => [T_ZBX_STR, O_OPT, null, null, 'isset({enter}) && {enter} != "'.ZBX_GUEST_USER.'"'], 'sessionid' => [T_ZBX_STR, O_OPT, null, null, null], 'reconnect' => [T_ZBX_INT, O_OPT, P_SYS, null, null], 'enter' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'autologin' => [T_ZBX_INT, O_OPT, null, null, null], 'request' => [T_ZBX_STR, O_OPT, null, null, null], 'form' => [T_ZBX_STR, O_OPT, null, null, null] ]; check_fields($fields); if (hasRequest('reconnect') && CWebUser::isLoggedIn()) { CWebUser::logout(); } $config = select_config(); $autologin = hasRequest('enter') ? getRequest('autologin', 0) : getRequest('autologin', 1); $request = getRequest('request', ''); if ($request) { $test_request = []; preg_match('/^\/?(?[a-z0-9\_\.]+\.php)(?\?.*)?$/i', $request, $test_request); $request = (array_key_exists('filename', $test_request) && file_exists('./'.$test_request['filename'])) ? $test_request['filename'].(array_key_exists('request', $test_request) ? $test_request['request'] : '') : ''; } if (!hasRequest('form') && $config['http_auth_enabled'] == ZBX_AUTH_HTTP_ENABLED && $config['http_login_form'] == ZBX_AUTH_FORM_HTTP && !hasRequest('enter')) { redirect('index_http.php'); exit; } // login via form if (hasRequest('enter') && CWebUser::login(getRequest('name', ZBX_GUEST_USER), getRequest('password', ''))) { if (CWebUser::$data['autologin'] != $autologin) { API::User()->update([ 'userid' => CWebUser::$data['userid'], 'autologin' => $autologin ]); } $redirect = array_filter([CWebUser::isGuest() ? '' : $request, CWebUser::$data['url'], ZBX_DEFAULT_URL]); redirect(reset($redirect)); exit; } if (CWebUser::isLoggedIn() && !CWebUser::isGuest()) { redirect(CWebUser::$data['url'] ? CWebUser::$data['url'] : ZBX_DEFAULT_URL); } $messages = clear_messages(); (new CView('general.login', [ 'http_login_url' => $config['http_auth_enabled'] == ZBX_AUTH_HTTP_ENABLED ? (new CUrl('index_http.php'))->setArgument('request', getRequest('request')) : '', 'guest_login_url' => CWebUser::isGuestAllowed() ? (new CUrl())->setArgument('enter', ZBX_GUEST_USER) : '', 'autologin' => $autologin == 1, 'error' => hasRequest('enter') && $messages ? array_pop($messages) : null ])) ->disableJsLoader() ->render();
原因:
查看/etc/httpd/conf.d 目錄下的 php.conf 文件 的如下兩項是否被註釋掉,如果沒有則添加
#php_value session.save_handler "files"
#php_value session.save_path "/var/lib/php/session"
解決:
將/etc/httpd/conf.d 目錄下的 php.conf 文件 的 最後兩行的註釋去掉,如果沒有則添加如下兩項。
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
也可能是缺少php 組件,安裝 php-bcmath 、 php-mbstring
問題8描述:
打開網頁,設置過程顯示:
Check of pre-requisites
- PHP xmlwriter extension missing.
- PHP xmlreader extension missing.
原因:
php 組件不支持需安裝
解決:
安裝 php-xmlwriter
#yum install php-xmlwriter
問題9描述:
配置zabbix Web界面的Mysql端口和密碼,頁面出現如下錯誤提示:
Error connecting to database: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
原因:
安裝的Mysql 是8.0以上版本,使用的新的鑑權插件‘caching_sha2_password’與zabbix的mysql客戶端程序的鑑權插件不一樣。
解決:
使用 mysql_native_password
鑑權插件,用root用戶登錄mysql,執行如下命令:
ALTER USER 'zabbix_username’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘zabbix_password’;
參考:
問題1參考:
https://stackoverflow.com/questions/21265191/apache-authtype-not-set-500-error
https://boinc.berkeley.edu/dev/forum_thread.php?id=8603
問題3參考:
https://support.zabbix.com/browse/ZBX-11009
centos6升級php5.4以上版本:
卸載原版本: https://blog.csdn.net/dc_726/article/details/9519293
升級新版本:https://www.tecmint.com/install-php-5-4-php-5-5-or-php-5-6-on-centos-6/
問題4參考:
https://talk.plesk.com/threads/solved-latest-php-5-3-26-yum-update-from-art-breaks-apache.287767/
問題5參考:
https://bugs.launchpad.net/ubuntu/+source/zabbix/+bug/1673462
問題8參考:
https://stackoverflow.com/questions/6384979/how-to-enable-xmlwriter-after-php-having-been-compiled
問題9參考: