本节展示了如何从源代码构建带有或不带有TLS的Zabbix Windows agent二进制文件。
This section contains instructions for building Zabbix agent with vcpkg, a package manager that simplifies dependency management and integration with C++ projects.
1. Download and install Build Tools for Visual Studio 2022. During installation, make sure to select the Desktop development with C++ workload, which includes the tools required for building the agent with vcpkg:
2. Initialize vcpkg and install the dependencies required for building Zabbix agent (note that this may take some time):
cd C:\Zabbix
vcpkg new --application
vcpkg add port pcre2
vcpkg add port openssl
vcpkg install --triplet x64-windows-static --x-install-root="C:\Program Files\Zabbix\x64"
3. Download the Zabbix source archive and extract it to C:\Zabbix\zabbix-7.0.0
.
4. Navigate to the Zabbix build directory (C:\Zabbix\zabbix-7.0.0\build\win32\project
) and create the following build.bat
script; make sure to correctly specify the directories where OpenSSL and PCRE2 are installed:
:: Set vcpkg installation path:
set vcpkg=C:\Program Files\Zabbix\x64\x64-windows-static
:: Run the build process:
nmake -f Makefile CPU=AMD64 ^
PCRE2INCDIR="%vcpkg%\include" ^
PCRE2LIBDIR="%vcpkg%\lib" ^
TLS=openssl ^
TLSINCDIR="%vcpkg%\include" ^
TLSLIBDIR="%vcpkg%\lib" ^
LIBS="$(LIBS) Crypt32.lib" ^
all
5. Compile Zabbix agent by executing the script:
After compilation, Zabbix component binaries will be located in C:\Zabbix\zabbix-7.0.0\bin\win64
. Zabbix agent configuration file is located in C:\Zabbix\zabbix-7.0.0\conf
.
To run the agent, copy zabbix_agent.exe
and its configuration file to a dedicated folder (e.g., C:\Zabbix\agent
) and then run the agent:
mkdir C:\Zabbix\agent
copy C:\Zabbix\zabbix-7.0.0\bin\win64\zabbix_agent.exe C:\Zabbix\agent\
copy C:\Zabbix\zabbix-7.0.0\conf\zabbix_agent.win.conf C:\Zabbix\agent\
C:\Zabbix\agent\zabbix_agent.exe -c C:\Zabbix\agent\zabbix_agent.win.conf
This method of building Zabbix agent is suitable for users who require full control over the build environment or are in a restricted environment where using vcpkg is not possible.
This section contains instructions for building Zabbix agent manually, which includes installing the required build tools and dependencies (Perl, OpenSSL, PCRE2), and then compiling the agent.
1. Download and install Build Tools for Visual Studio 2022. During installation, make sure to select the Desktop development with C++ workload, which includes the tools required for building the agent manually:
To compile Zabbix agent without TLS support, proceed to the Installing PCRE2 section.
1. Download and install Strawberry Perl (available as an MSI installer). During installation, make sure to specify C:\Zabbix\Strawberry
as the installation folder.
2. Install the Text::Template
Perl module:
3. Verify that the Netwide Assembler (NASM; required for compiling OpenSSL), was compiled during the installation of Strawberry Perl:
If NASM is not compiled, install it manually. For more information, refer to NASM documentation.
4. Download the OpenSSL source archive and extract it to C:\Zabbix\openssl-3.5.0
.
5. Navigate to the extracted directory and configure OpenSSL, for example:
cd C:\Zabbix\openssl-3.5.0
perl Configure VC-WIN64A no-shared no-capieng no-winstore no-srp no-gost no-dgram no-dtls1-method no-dtls1_2-method --api=1.1.0 --prefix="C:\Program Files\Zabbix\x64\OpenSSL" --openssldir="C:\Program Files\Zabbix\x64\OpenSSL"
If you choose a custom directory for OpenSSL when compiling Zabbix agent on Windows (e.g., C:\zabbix
or C:\openssl-64bit
), make sure to revoke write access from non-administrator users to this directory. Otherwise, the agent will load SSL settings from a path that can be modified by unprivileged users, resulting in a potential security vulnerability.
no-shared
option makes libcrypto.lib and libssl.lib OpenSSL static libraries self-contained, so Zabbix binaries include OpenSSL without needing external DLLs. This means that Zabbix binaries can be copied to other Windows machines without OpenSSL libraries; however, when a new OpenSSL bugfix version is released, Zabbix agent will need to be recompiled.no-shared
option, Zabbix relies on OpenSSL DLLs at runtime. This means that OpenSSL updates may not require recompiling Zabbix agent; however, when copying it to other machines, the OpenSSL DLLs must be also be copied.For more information about other OpenSSL configuration options, refer to OpenSSL documentation.
6. Compile OpenSSL and run tests (note that this may take some time):
Run the tests without administrative privileges; otherwise, it may lead to unexpected results or security risks. If some tests fail, refer to OpenSSL documentation for troubleshooting.
nmake
nmake test
...
All tests successful.
Files=325, Tests=3101, 822 wallclock secs ( 4.81 usr + 0.81 sys = 5.62 CPU)
Result: PASS
7. Install OpenSSL:
To install only software components (libraries, header files, but no documentation), you may use nmake install_sw
.
下载 PCRE 或 PCRE2 库 (https://pcre.org/).
解压缩到目录 E:\pcre2-10.39.
从 https://cmake.org/download/ 安装 CMake,在安装过程中选择:并确保 cmake\bin 在您的路径中(测试版本 3.9.4)。
创建一个新的、空的构建目录,最好是源目录的子目录。 例如,E:\pcre2-10.39\build。
打开命令行窗口,例如 VS 2017 的 x64 本机工具命令提示符,从该 shell 环境运行 cmake-gui。 不要尝试从 Windows 开始菜单启动 Cmake,因为这可能会导致错误。
分别输入 E:\pcre2-10.39 和 E:\pcre2-10.39\build 作为源目录和构建目录。
点击“配置”按钮。
在为该项目指定生成器时,选择“NMake Makefiles”。
创建一个新的、空的安装目录。例如,E:\pcre2-10.39-install。
GUI 将列出几个配置选项。确保选中以下选项:
再次点击“配置”。旁边的“生成”按钮现在应该是活动的。
点击“生成”。
如果出现任何错误,建议在尝试重复 CMake 构建过程之前删除 CMake 缓存。 在 CMake GUI 中,可以通过选择“文件 > 删除缓存”来删除缓存。
构建目录现在应该包含一个可用的构建系统 - Makefile。
打开命令行窗口,例如 VS 2017 的 x64 本机工具命令提示符,然后导航到上面提到的 Makefile。
运行 NMake 命令:
E:\pcre2-10.39\build> nmake install
以下步骤将帮助您在 MS Windows 10(64位)上从源代码编译 Zabbix。 编译 Zabbix 时,无论是否包含 TLS 支持,唯一的显著差异在于步骤 4。
git clone https://git.zabbix.com/scm/zbx/zabbix.git
cd zabbix
./bootstrap.sh
./configure --enable-agent --enable-ipv6 --prefix=`pwd`
make dbschema
make dist
在 Windows 机器上复制并解压缩归档文件,例如 zabbix-7.0.0.tar.gz
。
假设源代码位于 E:\zabbix-7.0.0。打开命令行窗口,例如 VS 2017 RC 的 x64 Native Tools Command Prompt。进入:
E:\\zabbix-7.0.0\\build\\win32\\project
不包含 TLS:
E:\zabbix-7.0.0\build\win32\project> nmake /K PCRE2INCDIR=E:\pcre2-10.39-install\include PCRE2LIBDIR=E:\pcre2-10.39-install\lib
包含 TLS:
E:\zabbix-7.0.0\build\win32\project> nmake /K -f Makefile_get TLS=openssl TLSINCDIR=C:\OpenSSL-Win64-111-static\include TLSLIBDIR=C:\OpenSSL-Win64-111-static\lib PCRE2INCDIR=E:\pcre2-10.39-install\include PCRE2LIBDIR=E:\pcre2-10.39-install\lib
E:\zabbix-7.0.0\build\win32\project> nmake /K -f Makefile_sender TLS=openssl TLSINCDIR="C:\OpenSSL-Win64-111-static\include TLSLIBDIR="C:\OpenSSL-Win64-111-static\lib" PCRE2INCDIR=E:\pcre2-10.39-install\include PCRE2LIBDIR=E:\pcre2-10.39-install\lib
E:\zabbix-7.0.0\build\win32\project> nmake /K -f Makefile_agent TLS=openssl TLSINCDIR=C:\OpenSSL-Win64-111-static\include TLSLIBDIR=C:\OpenSSL-Win64-111-static\lib PCRE2INCDIR=E:\pcre2-10.39-install\include PCRE2LIBDIR=E:\pcre2-10.39-install\lib