这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.

3 从源代码安装

您可以通过从源代码编译来使用最新版本的 get version。

此处提供了从源代码安装 Zabbix 的分步教程。

1 安装 Zabbix 守护进程

1 下载源代码归档

转至 Zabbix download page 并下载源代码归档文件。下载完成后,运行以下命令解压源代码:

tar -zxvf zabbix-7.0.0.tar.gz

在命令中输入正确的 Zabbix version。它必须与下载的归档文件名称匹配。

2 创建用户账户

所有Zabbix守护进程run在非特权系统用户下运行。 如果Zabbix守护进程由非特权用户账户启动,它将保持以该用户身份继续运行。

在默认配置中,如果守护进程以root身份启动,它将切换到zabbix用户账户,该账户必须存在。 要create一个zabbix系统用户和组,run以下列出的命令。

基于RedHat的系统:

groupadd --system zabbix
       useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

基于Debian的系统:

addgroup --system --quiet zabbix
       adduser --quiet --system --disabled-login --ingroup zabbix --home /var/lib/zabbix --no-create-home zabbix

无需为Zabbix前端create单独的用户账户。

安全建议

如果Zabbix serveragent run在同一台机器上运行,建议在不同的用户账户下run它们。 以相同用户身份运行允许agent访问服务器的配置file,这可能会将敏感信息(如数据库密码)暴露给Zabbix中的任何管理员级别用户。

rootbin或任何具有特殊权限的账户运行Zabbix存在安全风险。

主目录(可选)

Zabbix进程不需要主目录,因此通常不建议创建。 然而,如果您需要依赖主目录的功能(例如将MySQL凭据存储在$HOME/.my.cnf中),可以通过以下命令create实现。

在基于RedHat的系统上,run:

mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
       chown zabbix:zabbix /usr/lib/zabbix

在基于Debian的系统上,run:

mkdir -m u=rwx,g=rwx,o= -p /var/lib/zabbix chown zabbix:zabbix /var/lib/zabbix

3 创建 Zabbix 数据库

对于 Zabbix serverproxy 守护进程,以及 Zabbix 前端,都需要使用数据库。但不需要为 run Zabbix agent

创建数据库模式并插入数据集的 SQL scripts are provided。Zabbix proxy 数据库只需要模式,而 Zabbix server 数据库还需要在 Top 模式的基础上包含数据集。

创建完 Zabbix 数据库后,请继续进行 Zabbix 编译的后续步骤。

4 配置源代码

构建Zabbix server、Zabbix proxy或Zabbix agent需要支持GNU扩展的C99标准。 此version可通过设置CFLAGS="-std=gnu99"显式指定:

export CFLAGS="-std=gnu99"

如果从Zabbix Git repository安装, 需要先run:

./bootstrap.sh

在配置Zabbix server或proxy的源时,必须 指定要使用的数据库类型。只能使用一种数据库类型 一次编译一个server 或 proxy进程。

要查看所有支持的配置选项,请在解压后的 Zabbix源代码目录run:

./configure --help

要配置 Zabbix server 和 agent 的源,您可以 run 类似:

./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-ares

要配置Zabbix server(使用PostgreSQL等)的数据源,您 可以 run:

./configure --enable-server --with-postgresql --with-net-snmp

要配置 Zabbix proxy 的数据源(使用 SQLite 等),您可以 run:

./configure --prefix=/usr --enable-proxy --with-net-snmp --with-sqlite3 --with-ssh2

要配置 Zabbix agent 的源,您可以 run:

./configure --enable-agent

或者,对于Zabbix agent 2:

./configure --enable-agent2

构建Zabbix agent 2需要配置包含supported Go version的Go环境。

编译选项注意事项:

  • --enable-agent - 编译 Zabbix agent,以及 Zabbix getZabbix sender 命令行工具。
  • --with-libcurl - 虚拟机监控、SMTP认证及web.page.* Zabbix agent items所必需。另请参阅:serverproxy(libcurl)。
  • --with-libxml2 - 虚拟机监控所必需的。
  • --with-libpcre[=DIR] - Zabbix始终使用PCRE库进行编译;此选项仅允许指定自定义的PCRE安装路径。
  • --with-mysql=/path/to/mysql_config - 指定特定MySQL客户端库配置文件的路径。当系统安装多个MySQL版本或mariadb时特别有用。
  • --with-oracle - 指定Oracle调用接口(OCI) API的位置
  • --enable-static - 静态链接库(在Solaris上不受支持)。如果计划将编译后的二进制文件分发到没有所需库的系统,请使用此选项。在构建Zabbix server时不推荐使用。要静态构建服务器,需要每个外部库的静态version版本。configure脚本不会自动检查这一点。
  • --with-stacksize=<value> - 设置每个线程的堆栈大小(单位为KB,例如--with-stacksize=512)。如果Zabbix因堆栈溢出(例如在preprocessing时)导致崩溃或冻结,可以增加此值(适用于默认线程堆栈限制较低的系统)。

如果 ./configure 由于缺少库或其他 问题 而失败,请检查 config.log file 以获取详细的错误信息。

例如,如果缺少libssl,即时错误信息可能会产生误导:

checking for main in -lmysqlclient... no
       configure: error: Not found mysqlclient library

在这种情况下,config.log揭示了实际原因:

/usr/bin/ld: cannot find -lssl
       /usr/bin/ld: cannot find -lcrypto

另请参阅:

5 编译并安装所有内容

若从Zabbix Git repository安装, 需先run:

$ make dbschema

make install

此步骤应通过具备足够权限的用户(通常为 'root',或使用sudo)执行run。

默认情况下,运行make install会将守护进程二进制文件 (zabbix_server、zabbix_agentd、zabbix_proxy)安装至/usr/local/sbin, 客户端二进制文件(zabbix_get、zabbix_sender)安装至/usr/local/bin。

若要指定非/usr/local的安装路径,可在配置源码阶段 使用--prefix参数,例如--prefix=/home/zabbix。此时守护进程二进制文件 将安装至<prefix>/sbin,工具程序安装至<prefix>/bin, 手册页则安装至<prefix>/share目录。

6 审查并编辑配置文件
  • 编辑 Zabbix agent 配置文件 file /usr/local/etc/zabbix_agentd.conf

您需要为每台安装了 zabbix_agentd 的 主机 配置此 file。

必须在 file 中指定 Zabbix server 的 IP 地址,来自其他 主机 的连接将被拒绝。

  • 编辑 Zabbix server 配置文件 file /usr/local/etc/zabbix_server.conf

必须指定数据库名称、用户名和密码(如果使用的话)。

如果您是小型部署(监控不超过十个 主机),其余参数保持默认即可。但若想最大化 Zabbix 服务器(或 proxy)性能,则应修改默认参数。

  • 如果安装了 Zabbix proxy,请编辑 proxy 配置文件 file /usr/local/etc/zabbix_proxy.conf

必须指定服务器 IP 地址和 proxy 主机名(必须为服务器所知),以及数据库名称、用户名和密码(如果使用的话)。

使用 SQLite 时必须指定数据库 file 的完整路径;无需数据库用户名和密码。

7 启动守护进程

在服务器端运行zabbix_server。

zabbix_server

确保您的系统允许分配36MB(或稍多)的共享memory,否则服务器可能无法启动, 您将在服务器日志file中看到"无法为<缓存类型>分配共享memory"的错误信息。 这种情况可能发生在FreeBSD、Solaris 8.系统上。

在所有被监控机器上运行zabbix_agentd。

zabbix_agentd

确保您的系统允许分配2MB的共享memory,否则agent可能无法启动, 您将在agent日志file中看到"无法为收集器分配共享memory"的错误信息。 这种情况可能发生在Solaris 8.系统上。

如果您已安装Zabbix proxy,请run zabbix_proxy。

zabbix_proxy

2 安装 Zabbix Web 界面

复制PHP文件

Zabbix前端使用PHP编写,因此要run它,需要一个支持PHP的Web服务器。
安装只需将ui目录中的PHP文件复制到Web服务器的HTML文档目录中即可。

Apache Web服务器HTML文档目录的常见位置包括:

  • /usr/local/apache2/htdocs(从源代码安装Apache时的默认目录)
  • /srv/www/htdocs(OpenSUSE、SLES)
  • /var/www/html(Debian、Ubuntu、Fedora、RHEL)

建议使用子目录而不是HTML根目录。
要create一个子目录并将Zabbix前端文件copy到该目录中,请execute执行以下命令,并将<htdocs>替换为实际目录:

mkdir <htdocs>/zabbix
       cd ui
       cp -a . <htdocs>/zabbix

如果计划使用除英语之外的其他语言,请参阅Installation of additional frontend languages以获取相关说明。

安装前端

有关 Zabbix 前端安装向导的信息,请参见 Web interface installation 页面。

3 Installing Zabbix agent 2 loadable plugins

Installing Zabbix agent 2 loadable plugins is only required if you want to monitor targets not covered by built-in plugins (e.g., MongoDB servers or clusters, PostgreSQL and its forks, etc.). See the full list of loadable plugins and built-in plugins.

Before installing a plugin, please check its README file. It may contain specific requirements and installation instructions.

To install from sources, first download and extract the loadable plugin source archive.

To compile the plugin, navigate to the extracted plugin directory and run make:

make

A supported Go version is required for building Zabbix agent 2.

The plugin executable may be placed anywhere as long as it is loadable by Zabbix agent 2. Specify the path to the plugin binary in the plugin configuration file, e.g. in postgresql.conf for the PostgreSQL plugin:

Plugins.PostgreSQL.System.Path=/path/to/executable/zabbix-agent2-plugin-postgresql

The path to the plugin configuration file must be specified in the Include parameter of the Zabbix agent 2 configuration file:

Include=/path/to/plugin/configuration/file/postgresql.conf

Proceed to setup for more details on configuring plugins.

Loadable plugins provided by Zabbix use simple makefiles with the following build targets:

  • make - build the plugin
  • make clean - delete all files that are created by building the plugin
  • make check - run self-tests (requires a real monitoring target, e.g., a PostgreSQL database)
  • make style - check Go code style with golangci-lint
  • make format - format Go code with go fmt
  • make dist - create a source archive including all dependencies

4 安装Java网关

只有在需要监控JMX时才需要安装Java网关 应用程序。Java 网关轻量且不需要 数据库

从源代码安装,首先 1-下载源代码归档 和 提取源代码归档文件。

要编译 Java 网关,run 使用 ./configure 脚本。 --enable-java 选项。建议您指定 --prefix 请求安装路径(非默认路径 /usr/local)的选项, 因为安装 Java 网关会 create 一个完整的目录树,而不是 只是一个可执行文件。

./configure --enable-java --prefix=$PREFIX

要将 Java 网关编译并打包成 JAR 文件,请执行 run make。注意 请注意,对于此步骤,您的系统中需要包含 javacjar 可执行文件。 路径。

make

现在您有了一个 zabbix-java-gateway-$VERSION.jar file 文件。 src/zabbix_java/bin。如果您习惯运行Java网关 从发行版目录中的 src/zabbix_java,然后你可以 继续查看配置和运行 文件概览 的说明。 否则,请确保您有足够的权限并且 run make install

make install

Proceed to setup 以了解详细信息 关于配置和运行 Java 网关。

5 安装Zabbix web服务

仅当您希望使用scheduled reports时,才需要安装Zabbix Web服务。

如需从源码安装,请首先1-下载源代码归档并解压源码包。

要编译Zabbix Web服务,请使用--enable-webservice选项运行run的./configure脚本。

构建Zabbix Web服务需要配置好的Go环境,并安装agent-2

在安装了Web服务的机器上运行zabbix_web_service:

zabbix_web_service

有关配置定时报告生成的更多细节,请继续查看setup