Zabbix 5.0全网监控搭建(LNMP版本)- 全网首发

Zabbix 5.0全网监控搭建(LNMP版本)**

zabbix 5.0 版本于 2020 年 5 月 11 日正式发布,是最新的 LTS(长期支持)版本,5.0 带来很多功能和特性,接下来,我们先把它部署上。

1.环境要求

一个软件刚刚更新发布新版本没多久,这时候不要去百度搜索什么的,资料很少的,我们直接去看官方文档,你想要的官方文档里都有,我们先看看官方文档上 zabbix 5.0 的安装要求。

REQUIRED SOFTWARE

Zabbix is built around modern web servers, leading database engines, and PHP scripting language.

在这里插入图片描述

FRONTEND

The minimum supported screen width for Zabbix frontend is 1200px.

在这里插入图片描述

注意:以上内容来自于 zabbix 官方文档

从这段资料中可以看出,zabbix 5.0 最大的变化,就是 php 版本要求 7.2 以上,而 centos7 的默认源 php 版本是 5.4,所以这里我们就要使用第三方 php 的 yum 源了

2.安装 php 7.2 以及 zabbix 所需的 php 扩展模块

安装 php 第三方源

yum install epel-release.noarch -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装 nginx、php7.2 和所需 php 扩展模块

yum install -y nginx  
yum install -y  php72w-cli php72w-fpm php72w-common php72w-mysqlnd php72w-mbstring  php72w-gd php72w-bcmath php72w-ldap php72w-xml 

注意:webtatic 源在国外,容易失败

修改 php 的配置文件

vim  /etc/php-fpm.d/www.conf
user = apache
group = apache
修改为
user = nginx
group = nginx

修改 nginx 的配置文件

vim  /etc/nginx/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /html;
            index  index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           /html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /html$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

启动 nginx 和 php-fpm

systemctl start nginx
systemctl enable nginx
systemctl start php-fpm
systemctl enable php-fpm

3.安装 zabbix-web

cd /opt/
#下载源码包
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.4.tar.gz
tar xf zabbix-5.0.4.tar.gz
mkdir /html
#拷贝zabbix-web到站点目录
cp -a zabbix-5.0.4/ui/* /html
#修改站点目录属主和属组
chown -R nginx:nginx /html

使用浏览器访问 http://<你的 ip>
在这里插入图片描述

发现页面打不开,不要慌,我们看下日志
cat /var/log/nginx/error.log

2020/10/08 10:29:01 [error] 12403#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning:  session_start(): open(/var/lib/php/session/sess_f8b4d79c68b0ec44a225bd3419783d60, O_RDWR) failed: No such file or directory (2) in /html/include/classes/core/CSession.php on line 45
PHP message: PHP Warning:  session_start(): Failed to read session data: files (path: */var/lib/php/session*) in /html/include/classes/core/CSession.php on line 45
PHP message: PHP Fatal error:  Uncaught Exception: Cannot start session. in /html/include/classes/core/CSession.php:46
Stack trace:
#0 /html/setup.php(66): CSession::start()
#1 {main}
  thrown in /html/include/classes/core/CSession.php on line 46" while reading response header from upstream, client: 192.168.2.8, server: localhost, request: "GET /setup.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.2.121"
 ls /var/lib/php/session
 ls: cannot access /var/lib/php/session: No such file or directory

这里可以发现,确实没有这个目录,php 执行函数 session_start 出错

解决方法:

mkdir /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session

再次刷新浏览器,问题解决
在这里插入图片描述
接下来,点击 Next step

会出现几个警告,处理方法:

vim /etc/php.ini
post_max_size = 8M
修改为
post_max_size = 16M

max_execution_time = 30
修改为
max_execution_time = 300

max_input_time = 60
修改为
max_input_time = 300

;date.timezone =
去掉注释,并修改为
date.timezone = Asia/Shanghai

#重启php-fpm,并刷新浏览器
systemctl restart php-fpm.service

干干净净,这下舒服了吗?
在这里插入图片描述
到这里,我们先等一等,先安装下数据库和 zabbix-server

4.安装 zabbix-server

linux上自带的mariadb启动即可。

yum reinstall -y mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service
建议执行下安全配置mysql_secure_installation

为zabbix创库授权

mysql -uroot -p


MariaDB [(none)]>  create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)

安装 zabbix-server

rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum install zabbix-server-mysql -y
#导入zabbix初始数据文件
zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz |mysql -uzabbix -p123456 zabbix

修改 zabbix-server 配置

vim /etc/zabbix/zabbix_server.conf
#配置下数据库的连接信息
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456

启动 zabbix-server

systemctl start zabbix-server.service
systemctl enable zabbix-server.service

#检查zabbix-server启动情况
[root@zabbix-5 opt]# netstat -lntup|grep 10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      13190/zabbix_server
tcp6       0      0 :::10051                :::*                    LISTEN      13190/zabbix_server

5.最后的安装

继续访问浏览器
在这里插入图片描述
一直进行下一步即可。

初始的用户是 Admin,密码 zabbix(注意大小写)

登录成功之后的页面
在这里插入图片描述

更多精彩内容,欢迎关注微信公众号

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45320660/article/details/109214598