本身环境zabbix之前同事安装,是采用的lamp环境rpm包去安装zabbix的。现在要换成nginx做为web服务。
替换思路 : zabbix的web服务是用php写的,httpd 只是一个web服务器。有了替换思路我们就进行下一步,我们首先找到php程序存放的目录。
找到zabbix.conf并打开文件 /etc/httpd/conf.d/zabbix.conf,根据路径来看不难判断这个文件应该就是httpd配置文件,打开文件根据Directory可以判 断/usr/share/zabbix为程序所在目录。
找到zabbix程序所在目录后,我们就着手配置nginx就好了,进入nginx的配置目录并打开 /etc/nginx/conf.d/default.conf文件(或者另外创建一个zabbix.conf 的文件)
安装好lnmp环境,nginx是基于php-fpm,rhel7.4只有php相关rpm包,但没有php-fpm的rpm包,所以需要自己下载相应版本的php-fpm的rpm包并安装
编辑default.conf为下面的内容:
采用别名方式: # vi /etc/nginx/conf.d/default.conf server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; 采用别名zabbix方式:http://IP/zabbix,这样去访问,就不用nginx默认/目录了 location /zabbix { alias /usr/share/zabbix; #是zabbix前端的PHP文件所在目录 index index.html index.htm index.php; } #设置下面几个目录 不允许外部访问 location ^~ /app { deny all; } location ^~ /conf { deny all; } location ^~ /local { deny all; } location ^~ /include { deny all; } #error_page 404 /404.html; # 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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # # 配置nginx和php-fpm通信 # 我们使用端口的形式来进行通讯 # 前面注释去掉并修改成你需要的 location ~ ^/zabbix/.+\.php$ { #fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
配置好之后保存文件
启动服务:
systemctl start php-fpm systemctl restart nginx systemctl restart zabbix-server zabbix-agent
开机启动:
systemctl enable php-fpm systemctl enable zabbix-server zabbix-agent nginx
访问zabbix服务:http:/IP/zabbix
到上面为止,我们就替换zabbix默认web服务器httpd为nginx。但是我们还没有结束,是的,还没有结束!!!
我们登录后可能会出现如下报错,这个是需要设置php.ini参数date.timezone设置php的默认时区,设置好后点重试,即可打开首页了
当跳转到首页,右下角dashboard模块下 Status of Zabbix 有几个红色的异常
1、date.timezone => 没有设置php的默认时区
2、max_input_time 60
3、max_execution_time 30
4、post_max_size 8M
这四个是php配置问题,我们只需要编辑php.ini就好了
#vi /etc/php.ini post_max_size = 16M max_input_time = 300 max_execution_time = 300 date.timezone = Asia/Shanghai
到些完成结束了!