2022 Zabbix中国峰会
2022 Zabbix中国峰会

2 在macOS上安装zabbix agent

总览

本节演示如何从包含或不包含TLS的源代码安装Zabbix agent二进制文件(macOS)

先决条件

您将需要命令行开发人员工具(不需要Xcode),Automake,pkg-config和PCRE(v8.x) 如果要使用TLS构建agent二进制文件,则还需要OpenSSL或GnuTLS

要安装Automake和pkg-config,您将需要来自https://brew.sh/的Homebrew软件包管理器。 要安装它,请打开终端并运行以下命令:

$ /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计算机上运行agent二进制文件,则可以使用Homebrew提供的预编译库。 这些通常是使用Homebrew来构建Zabbix agent二进制文件或用于其他目的的macOS计算机

如果agent二进制文件将在没有共享库版本的macOS计算机上使用,则应从源代码编译静态库并将Zabbix agent与它们链接

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

安装 PCRE:

$ brew install pcre

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

$ brew install openssl
       $ brew install gnutls

下载Zabbix源码:

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

不使用TLS构建agent:

$ cd zabbix/
       $ git checkout 5.0.1 -b 5.0.1 # replace 5.0.1 with the latest release available
       $ ./bootstrap.sh
       $ ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6
       $ make
       $ make install

使用OpenSSL构建agent:

$ cd zabbix/
       $ git checkout 5.0.1 -b 5.0.1 # replace 5.0.1 with the latest release available
       $ ./bootstrap.sh
       $ ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-openssl=/usr/local/opt/openssl
       $ make
       $ make install

使用GnuTLS构建agent:

$ cd zabbix/
       $ git checkout 5.0.1 -b 5.0.1 # replace 5.0.1 with the latest release available
       $ ./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”中。我们将使用PCRE 8.42

$ PCRE_PREFIX="$HOME/static-libs/pcre-8.42"

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

$ mkdir static-libs-source
       $ cd static-libs-source
       $ curl --remote-name https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
       $ tar xf pcre-8.42.tar.gz
       $ cd pcre-8.42
       $ ./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/
       $ git checkout 5.0.1 -b 5.0.1 # replace 5.0.1 with the latest release available
       $ ./bootstrap.sh
       $ ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-libpcre="$PCRE_PREFIX"
       $ make
       $ make install

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

构建OpenSSL时,建议在成功构建后运行“make test”。 即使构建成功,测试有时也会失败。 在这种情况下,应进行研究并解决问题,然后再继续

让我们假设PCRE和OpenSSL静态库将安装在“$HOME/static-libs”中。我们将使用PCRE 8.42和OpenSSL 1.1.1a

$ PCRE_PREFIX="$HOME/static-libs/pcre-8.42"
       $ 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://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
       $ tar xf pcre-8.42.tar.gz
       $ cd pcre-8.42
       $ ./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/
       $ git checkout 5.0.1 -b 5.0.1 # replace 5.0.1 with the latest release available
       $ ./bootstrap.sh
       $ ./configure --sysconfdir=/usr/local/etc/zabbix --enable-agent --enable-ipv6 --with-libpcre="$PCRE_PREFIX" --with-openssl="$OPENSSL_PREFIX"
       $ make
       $ make install

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

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

构建GnuTLS和Nettle时,建议在成功构建后运行“make check”。 即使构建成功,测试有时也会失败。 在这种情况下,应进行研究并解决问题,然后再继续

假设PCRE,Nettle和GnuTLS静态库将安装在“ $ HOME / static-libs”中。 我们将使用PCRE 8.42,Nettle 3.4.1和GnuTLS 3.6.5

$ PCRE_PREFIX="$HOME/static-libs/pcre-8.42"
       $ 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/
       $ git checkout 5.0.1 -b 5.0.1 # replace 5.0.1 with the latest release available
       $ ./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-libpcre="$PCRE_PREFIX" --with-gnutls="$GNUTLS_PREFIX"
       $ make
       $ make install