安装zabbix server 5.0

系统:centos 7
环境:lnmp环境,php7.2 mysql5.6 nginx1.19 

步骤;
1、安装zabbix仓库
2、安装zabbix-server和zabbix-agent
3、创建数据库账号并导入数据库
4、修改zabbix配置文件
5、修改php.ini
6、创建zabbix的nginx配置文件

安装仓库

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all

安装zabbix server和zabbix agent

yum install zabbix-server-mysql zabbix-agent

注意:我本地测试经常下载不下来,可以直接下载对应的rpm文件然后手动传到服务器上再通过yum install xxx.rpm或rpm -ivh xxx.rpm 安装。

安装zabbix-web

rpm -ivh http://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.2-1.el7.noarch.rpm

如果不能安装可以直接浏览器下载,然后再传到服务器进行手动安装,http://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.2-1.el7.noarch.rpm

初始化数据库

因为我本地已经安装好了宝塔面板,所以数据库不需要另外安装,直接登录数据库,然后通过以下命令创建数据库。
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;

导入数据库

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

修改zabbix server的配置文件

vim /etc/zabbix/zabbix_server.conf
修改以下两个地方:
DBPassword=zabbix
DBSocket=/tmp/mysql.sock

DBSocket是因为默认zabbix server会去找/var/lib/mysql/mysql.sock这个socket,但是因为宝塔面板默认mysql.sock在/tmp目录下,所以需要改DBSocket这个值。

错误:connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through sock
et '/var/lib/mysql/mysql.sock' (2)

添加Nginx的配置文件

cd /www/server/panel/vhost/nginx
cat zabbix.conf
server {
        listen          80;
        server_name     zabbix.xiaozhenkai.com;

        root    /usr/share/zabbix;

        index   index.php;

        location = /favicon.ico {
                log_not_found   off;
        }

        location / {
                try_files       $uri $uri/ =404;
        }

        location /assets {
                access_log      off;
                expires         10d;
        }

        location ~ /\.ht {
                deny            all;
        }

        location ~ /(api\/|conf[^\.]|include|locale) {
                deny            all;
                return          404;
        }

        location ~ [^/]\.php(/|$) {
                #fastcgi_pass    unix:/var/opt/rh/rh-php72/run/php-fpm/zabbix.sock;
                fastcgi_pass    unix:/tmp/php-cgi-72.sock;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_index   index.php;

                fastcgi_param   DOCUMENT_ROOT   /usr/share/zabbix;
                fastcgi_param   SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
                fastcgi_param   PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name;

                include fastcgi_params;
                fastcgi_param   QUERY_STRING    $query_string;
                fastcgi_param   REQUEST_METHOD  $request_method;
                fastcgi_param   CONTENT_TYPE    $content_type;
                fastcgi_param   CONTENT_LENGTH  $content_length;

                fastcgi_intercept_errors        on;
                fastcgi_ignore_client_abort     off;
                fastcgi_connect_timeout         60;
                fastcgi_send_timeout            180;
                fastcgi_read_timeout            180;
                fastcgi_buffer_size             128k;
                fastcgi_buffers                 4 256k;
                fastcgi_busy_buffers_size       256k;
                fastcgi_temp_file_write_size    256k;
        }
}

配置里需要注意地方是fastcgi_pass这个值,配置成正确的位置。保存,检测语法并重新加载配置 nginx -t && nginx -s reload

修改php.ini

cd /www/server/php/72/etc/
cp php.ini{,.bak}
max_input_time = 300
extension=ldap.so //这个扩展可以直接在宝塔面板里php设置里的“安装扩展”里手动安装

然后把disable里的putenv函数放行,不然会报错。

保存退出。重启php
/etc/init.d/php-fpm-72 restart

启动Zabbix server和zabbix agent,并设置开机启动。

systemctl restart zabbix-server zabbix-agent
systemctl enable zabbix-server zabbix-agent

本地修改hosts,然后访问http://zabbix.xiaozhenkai.com/, 填写正确的配置后安装。

登录

默认账号密码:
Admin
zabbix