3 Компилација Zabbix агента на macOS-у

Преглед

Ова секција показује како компилирати бинарне датотеке Zabbix агента за macOS из извора, са или без TLS-а.

Предуслови

Потребни су вам алати за програмирање командне линије (Xcode није потребан), Automake, pkg-config и PCRE (v8.x) или PCRE2 (v10.x). Ако желите да направите бинарне датотеке агента са TLS-ом, биће вам потребан и OpenSSL или GnuTLS.

Да бисте инсталирали Automake и pkg-config, биће вам потребан Homebrew менаџер пакета са https://brew.sh/. Да бисте га инсталирали, отворите терминал и покрените следећу команду:

/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 библиотека зависи од начина на који ће бити повезане са агентом.

Ако намеравате да покрећете бинарне датотеке агента на macOS машини која већ има ове библиотеке, можете користити претходно компајлиране библиотеке које пружа Homebrew. То су обично macOS машине које користе Homebrew за изградњу бинарних датотека Zabbix агента или у друге сврхе.

Ако ће се бинарне датотеке агента користити на macOS машинама које немају дељену верзију библиотека, требало би да компајлирате статичке библиотеке из извора и повежете Zabbix агент са њима.

Компилирање бинарних датотека агента са дељеним библиотекама

Инсталирајте 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

Компилирање агента без TLS-а:

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

Компилирање агента са OpenSSL-ом:

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

Компилирање агента са 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-а

Претпоставимо да ће PCRE статичке библиотеке бити инсталиране у $HOME/static-libs. Ми ћемо користити PCRE2 10.39.

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

Преузмите и компајлирајте PCRE са подршком за Unicode својства:

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-а и компилирајте агента:

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

Building agent binaries with static libraries with OpenSSL

When building OpenSSL, it's recommended to run make test after successful building. Even if building was successful, tests sometimes fail. If this is the case, problems should be researched and resolved before continuing.

Let's assume that PCRE and OpenSSL static libraries will be installed in $HOME/static-libs. We will use PCRE2 10.39 and OpenSSL 1.1.1a.

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

Let's build static libraries in static-libs-source:

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

Download and build PCRE with Unicode properties support:

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 ..

Download and build 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 ..

Download Zabbix source and build 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

Building agent binaries with static libraries with GnuTLS

GnuTLS depends on the Nettle crypto backend and GMP arithmetic library. Instead of using full GMP library, this guide will use mini-gmp which is included in Nettle.

When building GnuTLS and Nettle, it's recommended to run make check after successful building. Even if building was successful, tests sometimes fail. If this is the case, problems should be researched and resolved before continuing.

Let's assume that PCRE, Nettle and GnuTLS static libraries will be installed in $HOME/static-libs. We will use PCRE2 10.39, Nettle 3.4.1 and 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"

Let's build static libraries in static-libs-source:

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

Download and build 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 ..

Download and build 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 ..

Download Zabbix source and build 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