编译安装zabbix5.0


一,zabbix的用途:

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案 zabbix能监视各种网络参数,保证服务器系统的安全运营;

并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题

zabbix由2部分构成: zabbix server/运行在被监控端的zabbix agent

二,准备好lnmp环境:

1,需要的环境文档:

     https://www.zabbix.com/documentation/current/manual/installation/requirements

2,需要的软件环境

    php:7.2.0及以上

    mysql: 5.5.62及以上

    需要的php扩展包括

    gd: 2.0.28及以上

    bcmath ctype

    libXML: 2.6.15及以上

    session s

    ockets

    mbstring

    ttext 

三,下载zabbix的源码安装包

    1,官方下载站: http://repo.zabbix.com/zabbix/ 清华的国内镜像站: https://mirrors.tuna.tsinghua.edu.cn/zabbix/

    2,创建下载目录: [root@blog zabbix]# mkdir /usr/local/source/zabbix

    3,下载: [root@blog zabbix]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz

四,安装zabbix5.0

 1,官方的安装文档地址:

      https://www.zabbix.com/documentation/current/manual/installation/install

 2,解压缩:

     [root@blog zabbix]# tar -zxvf zabbix-5.0.0.tar.gz

     [root@blog zabbix]# cd zabbix-5.0.0/

3,创建zabbix用户

    [root@blog zabbix-5.0.0]# groupadd --system zabbix

    root@blog zabbix-5.0.0]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

4,创建zabbix账号的home目录

    [root@blog zabbix-5.0.0]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix

    [root@blog zabbix-5.0.0]# chown zabbix:zabbix /usr/lib/zabbix

5,创建zabbix数据库

    创建数据库的文档地址 https://www.zabbix.com/documentation/current/manual/appendix/install/db_scripts

    创建数据库 create database zabbix character set utf8 collate utf8_bin

    创建zabbix数据库账号 create user 'zabbix'@'127.0.0.1' identified by 'zabbixpass';

    给zabbix数据库账号授权 grant all privileges on zabbix.* to 'zabbix'@'127.0.0.1';

    刷新数据库权限数据 flush PRIVILEGES;

6,导入数据:

    说明:切换到源码目录/database/mysql/目录下后执行:

    [root@blog mysql]$ /usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < schema.sql

                                    mysql: [Warning] Using a password on the command line interface can be insecure.

    [root@blog mysql]$ /usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < images.sql

                                    mysql: [Warning] Using a password on the command line interface can be insecure

    [root@blog mysql]$ /usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < data.sql

                                   mysql: [Warning] Using a password on the command line interface can be insecure. 

7,configure与安装

   在源码目录下执行configure

   [root@blog zabbix-5.0.0]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

  安装

   [root@blog zabbix-5.0.0]# make install

  说明:configure时报错的解决:

   报错1: configure: error: MySQL library not found

   解决: [root@blog zabbix-5.0.0]# dnf install mysql-devel

   报错2: configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

    [root@blog zabbix-5.0.0]# dnf install -y net-snmp-devel

   报错3: configure: error: Unable to use libevent (libevent check failed)

   解决: [root@blog zabbix-5.0.0]# dnf install libevent-devel -y

  报错4: configure: error: Unable to use libpcre (libpcre check failed)

    解决: [root@blog zabbix-5.0.0]# dnf -y install pcre*

                     yum install curl-devel curl -y

                    yum install libxml2-devel -y(make 报错)

8,查看安装效果:

查看zabbix_server的版本

[root@blog zabbix-5.0.0]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_server --version

zabbix_server (Zabbix) 5.0.0

Revision 9665d62db0 11 May 2020, compilation time: May 17 2020 09:37:03

Copyright (C) 2020 Zabbix SIA License GPLv2+: GNU GPL version 2 or later . This is free software: you are free to change and redistribute it according to the license. There is NO WARRANTY, to the extent permitted by law.

五,配置zabbix_server

编辑配置文件

[root@blog etc]# vi zabbix_server.conf

主要配置项: LogFile=/data/zabbix_server/logs/zabbix_server.log DBHost=localhost DBName=zabbix DBUser=zabbix DBPort=3306

创建日志目录:[root@blog etc]# mkdir /data/zabbix_server/log

六,配置zabbix_agentd

编辑配置文件 [root@blog etc]# vi zabbix_agentd.conf

主要配置项: LogFile=/data/zabbix_agentd/logs/zabbix_agentd.log Server=127.0.0.1 ServerActive=127.0.0.1 Hostname=jdweb

 创建日志目录 [root@blog etc]# mkdir /data/zabbix_agentd/logs

七,启动zabbix_server

[root@blog etc]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_server

八,启动zabbix_agentd

[root@blog etc]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_agentd

九,为nginx配置zabbix用来做web管理的虚拟主机

创建网站root目录 [root@blog conf.d]# mkdir /data/dweb/zabbix

配置虚拟主机:

说明:这个文件要放到nginx的配置文件所在目录下,

           我的机器上是:/usr/local/openresty/nginx/conf/conf.d,

          大家根据自己机器上nginx的安装情况创建这个虚拟主机即可

即可

[root@blog conf.d]# vi zabbix.conf   

       server {

      listen 80;

      server_name zabbix.lhdtest.net;

      root         /data/dweb/zabbix/html; index index.php index.html index.shtml index.htm;

      access_log /data/logs/nginxlogs/zabbix.access_log;

       error_log /data/logs/nginxlogs/zabbix.error_log;

       location / {

                         try_files $uri $uri/ /index.php?$args;

          }

      location ~ \.php$ {

             fastcgi_pass     127.0.0.1:9000;

             fastcgi_index     index.php;

             fastcgi_buffer_size 32k;

             fastcgi_buffers 10240 32k;

             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

             include          fastcgi_params;

      }

配置完成后重启nginx

九,配置web界面

1,复制ui目录下的文件到虚拟主机目录下

[root@blog ui]# pwd /usr/local/source/zabbix/zabbix-5.0.0/ui

[root@blog ui]# cp -axv ./ /data/dweb/zabbix/html/

2,访问url

http://zabbix.lhdtest.net/

会自动跳转到: http://zabbix.lhdtest.net/setup.php