本篇文章記錄了zabbix結合apache服務器和nginx服務器的搭建過程。
1. 安裝yum源
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
yum clean all
2. 安裝依賴插件
yum provides '*/applydeltarpm'
yum -y install deltarpm
3. 安裝Zabbix server,Web前端,agent(客戶端,只負責採集數據,不依賴數據庫),java-gateway(監控jvm進程)
yum -y install zabbix-server-pgsql zabbix-web-pgsql zabbix-agent zabbix-java-gateway
4. 創建初始數據庫和數據庫用戶(在數據庫服務器執行)
zabbix和數據庫不在同一臺服務器上需要在數據庫服務器創建zabbix用戶
groupadd -r zabbix
useradd -g zabbix -r -s /sbin/nologin zabbix
sudo -u postgres createuser --pwprompt zabbix
sudo -u postgres createdb -O zabbix zabbix
5. 導入Zabbix初始數據(在數據庫服務器執行,如果zabbix和數據庫不在一臺服務器,需要把文件拷到數據庫服務器上執行)
zcat /usr/share/doc/zabbix-server-pgsql*/create.sql.gz | sudo -u zabbix psql zabbix
6. 配置Zabbix服務端數據庫
zabbix和數據庫不在同一臺服務器上需要
DBHost=
vim /etc/zabbix/zabbix_server.conf 內容如下:
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
JavaGateway=192.168.56.100 ### java-gateway ip地址
StartJavaPollers=5 ### 預啓動進程輪訓個數
7. 爲Zabbix前端配置PHP
vim /etc/httpd/conf.d/zabbix.conf
把php_value date.timezone Europe/Riga 前面的註釋去掉
8. 啓動Zabbix server和agent進程(使用apache做web服務器)
systemctl start/restart/stop zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd
9. 配置Zabbix前端
http://192.168.56.100/zabbix
除了數據庫配置和zabbix服務端配置,其他的直接下一步就可以了
默認賬號/密碼:Admin/zabbix
10. 點擊用戶頭像可以設置用戶屬性,包括修改監控界面語言
------------------ 監控 springboot項目待研究 ---------------------------------------
11. 配置java-gateway
vim /etc/zabbix/zabbix_java_gateway.conf
12. 啓動zabbix_java_gateway
systemctl restart zabbix-java-gateway
systemctl enable zabbix-java-gateway
----------------------------------------------------------------------------------------------
13. 查看zabbix-server日誌:
cat /var/log/zabbix/zabbix_server.log
--------------------- 使用nginx做web服務器 ------------------------------------
14. 安裝php-fpm(裝zabbix時默認會裝PHP。但是默認用的是apache服務器,不會裝php-fpm)
yum -y install php-fpm
配置文件路徑: /etc/php-fpm.conf /etc/php-fpm.d/www.conf(子配置文件)
15. 配置php時區(默認是UTC),不配置的話也面登錄的時候會報錯
vim /etc/php.ini
date.timezone = PRC
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
16. 啓動php-fpm
systemctl enable php-fpm
systemctl start php-fpm
17. 配置nginx支持php-cgi(common gate-way interface),/etc/nginx/conf.d目錄(該目錄下的配置文件會被主配置文件引入)下新建zabbix.conf配置文件內容如下
server {
listen 8081;
server_name localhost;
access_log /data/log/zabbix/zabbix_access.log main;
error_log /data/log/zabbix/zabbix_error.log; # 如果遇到問題,要善用這個錯誤日誌文件
#location / {
# root /usr/share/zabbix;
# index zabbix.html zabbix.php;
#}
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/zabbix; # 這個一定要配,起初我以爲只要在location / 配了更目錄這裏就不用配了,結果折騰了半天 $document_root就是指向這個目錄的
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
18. 頁面訪問
http://192.168.56.100:8081/index.php
19. zabbix-agent配置(agent和server不在同一臺服務去)
vim /etc/zabbix/zabbix_agentd.conf
Server= [zabbix 服務端ip]
ServerActive=[zabbix 服務端ip]
Hostname=[zabbix客戶端主機名]