3 在macOS上构建Zabbix agent

概述

本节演示如何从源代码构建带或不带 TLS 的 Zabbix macOS agent 二进制文件。

先决条件

您需要命令行开发人员工具(不需要安装 Xcode)。 Automake、pkg-config 以及 PCRE(v8.x)或 PCRE2(v10.x)。如果您想要构建 agent 带有TLS的二进制文件,还需要OpenSSL或GnuTLS。

要安装 Automake 和 pkg-config,您将需要一个 Homebrew 软件包。 从 https://brew.sh/ 安装。要安装它,请打开终端并 run 以下命令:

`/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`

然后安装 Automake 和 pkg-config:

brew install automake
       brew install pkg-config

准备 PCRE、OpenSSL 和 GnuTLS 库取决于它们的安装方式 将链接到agent。

如果您打算在已安装的macOS计算机上run agent二进制文件,则 这些库,你可以使用由...提供的预编译库 Homebrew。这些通常是使用 Homebrew 进行 构建 Zabbix agent 二进制文件或其他用途。

如果将在没有agent的 macOS 机器上使用二进制文件,则 共享库的 version,您应从源代码编译静态库 源和链接 Zabbix agent 与它们相关。

使用共享库构建agent二进制文件

安装 PCRE2(如果需要,可将下面命令中的 pcre2 替换为 pcre):

brew install pcre2

在使用 TLS 构建时,安装 OpenSSL 和/或 GnuTLS:

brew install openssl
       brew install gnutls

下载 Zabbix 源码:

git clone https://git.zabbix.com/scm/zbx/zabbix.git

构建 agent(不启用 TLS):

cd zabbix
       ./bootstrap.sh
       ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6
       make
       make install

构建 agent(启用 OpenSSL):

cd zabbix
       ./bootstrap.sh
       ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-openssl=/usr/local/opt/openssl
       make
       make install

构建 agent(启用 GnuTLS):

cd zabbix-source/
       ./bootstrap.sh
       ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-gnutls=/usr/local/opt/gnutls
       make
       make install

不使用TLS的静态库构建agent二进制文件

假设 PCRE 静态库将安装在 $HOME/static-libs 中。我们将使用 PCRE2 10.39。

PCRE_PREFIX="$HOME/static-libs/pcre2-10.39"

下载并构建支持 Unicode 属性的 PCRE:

mkdir static-libs-source
       cd static-libs-source
       curl --remote-name https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.39/pcre2-10.39.tar.gz
       tar xf pcre2-10.39.tar.gz
       cd pcre2-10.39
       ./configure --prefix="$PCRE_PREFIX" --disable-shared --enable-static --enable-unicode-properties
       make
       make check
       make install

下载 Zabbix 源码并构建 agent:

git clone https://git.zabbix.com/scm/zbx/zabbix.git
       cd zabbix
       ./bootstrap.sh
       ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-libpcre2="$PCRE_PREFIX"
       make
       make install

使用OpenSSL的静态库构建agent二进制文件

构建OpenSSL时,建议在构建成功后运行run make test。即使构建成功,测试有时也会失败。如果出现这种情况,在继续之前应研究并解决问题。

我们假设PCRE和OpenSSL静态库将安装在$HOME/static-libs目录中。我们将使用PCRE2 10.39和OpenSSL 1.1.1a。

PCRE_PREFIX="$HOME/static-libs/pcre2-10.39"
       OPENSSL_PREFIX="$HOME/static-libs/openssl-1.1.1a"

static-libs-source目录中构建静态库:

mkdir static-libs-source
       cd static-libs-source

下载并构建支持Unicode属性的PCRE:

curl --remote-name https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.39/pcre2-10.39.tar.gz
       tar xf pcre2-10.39.tar.gz
       cd pcre2-10.39
       ./configure --prefix="$PCRE_PREFIX" --disable-shared --enable-static --enable-unicode-properties
       make
       make check
       make install
       cd ..

下载并构建OpenSSL:

curl --remote-name https://www.openssl.org/source/openssl-1.1.1a.tar.gz
       tar xf openssl-1.1.1a.tar.gz
       cd openssl-1.1.1a
       ./Configure --prefix="$OPENSSL_PREFIX" --openssldir="$OPENSSL_PREFIX" --api=1.1.0 no-shared no-capieng no-srp no-gost no-dgram no-dtls1-method no-dtls1_2-method darwin64-x86_64-cc
       make
       make test
       make install_sw
       cd ..

下载Zabbix源码并构建agent:

git clone https://git.zabbix.com/scm/zbx/zabbix.git
       cd zabbix
       ./bootstrap.sh
       ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-libpcre2="$PCRE_PREFIX" --with-openssl="$OPENSSL_PREFIX"
       make
       make install

使用GnuTLS的静态库构建agent二进制文件

GnuTLS 依赖于 Nettle 加密后端和 GMP 算术库。
本指南将使用包含在 Nettle 中的 mini-gmp,而不是完整的 GMP 库。

在构建 GnuTLS 和 Nettle 时,建议在构建成功后运行 run make check。即使构建成功,测试有时也会失败。如果出现这种情况,应在继续之前研究并解决问题。

假设 PCRE、Nettle 和 GnuTLS 静态库将安装在 $HOME/static-libs 中。我们将使用 PCRE2 10.39、Nettle 3.4.1 和 GnuTLS 3.6.5。

PCRE_PREFIX="$HOME/static-libs/pcre2-10.39"
       NETTLE_PREFIX="$HOME/static-libs/nettle-3.4.1"
       GNUTLS_PREFIX="$HOME/static-libs/gnutls-3.6.5"

static-libs-source 中构建静态库:

mkdir static-libs-source
       cd static-libs-source

下载并构建 Nettle:

curl --remote-name https://ftp.gnu.org/gnu/nettle/nettle-3.4.1.tar.gz
       tar xf nettle-3.4.1.tar.gz
       cd nettle-3.4.1
       ./configure --prefix="$NETTLE_PREFIX" --enable-static --disable-shared --disable-documentation --disable-assembler --enable-x86-aesni --enable-mini-gmp
       make
       make check
       make install
       cd ..

下载并构建 GnuTLS:

curl --remote-name https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/gnutls-3.6.5.tar.xz
       tar xf gnutls-3.6.5.tar.xz
       cd gnutls-3.6.5
       PKG_CONFIG_PATH="$NETTLE_PREFIX/lib/pkgconfig" ./configure --prefix="$GNUTLS_PREFIX" --enable-static --disable-shared --disable-guile --disable-doc --disable-tools --disable-libdane --without-idn --without-p11-kit --without-tpm --with-included-libtasn1 --with-included-unistring --with-nettle-mini
       make
       make check
       make install
       cd ..

下载 Zabbix 源码并构建 agent:

git clone https://git.zabbix.com/scm/zbx/zabbix.git
       cd zabbix
       ./bootstrap.sh
       CFLAGS="-Wno-unused-command-line-argument -framework Foundation -framework Security" \
       > LIBS="-lgnutls -lhogweed -lnettle" \
       > LDFLAGS="-L$GNUTLS_PREFIX/lib -L$NETTLE_PREFIX/lib" \
       > ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-libpcre2="$PCRE_PREFIX" --with-gnutls="$GNUTLS_PREFIX"
       make
       make install