2 Windows에서 Zabbix agent 2 빌드하기
원본 보기2 Windows에서 Zabbix agent 2 빌드
개요
이 페이지는 Windows 10 (64비트 또는 32비트)에서 소스로부터 Zabbix agent 2를 빌드하는 방법을 설명합니다.
32비트와 64비트 버전 모두 64비트 플랫폼에서 빌드할 수 있지만, 32비트 플랫폼에서는 32비트 버전만 빌드할 수 있습니다.
Zabbix agent 2 빌드에 필요한 요소:
- MinGW 빌드 도구
- Go 프로그래밍 언어
- OpenSSL (Zabbix의 암호화 기능용)
- PCRE2 (Perl Compatible Regular Expressions; Zabbix의 정규 표현식 패턴 매칭 기능용)
다음 방법 중 하나를 사용하여 Zabbix agent 2를 빌드할 수 있습니다:
- vcpkg 사용—C++ 패키지 매니저를 사용하여 종속성 관리를 단순화하는 자동화된 방법입니다.
- 수동 빌드—에이전트를 컴파일하기 전에 모든 종속성을 수동으로 설치해야 하는 방법입니다.
빌드 프로세스를 시작하기 전에 다음 사항을 유의하시기 바랍니다:
vcpkg로 Zabbix agent 2 빌드하기
이 섹션에서는 C++ 프로젝트의 의존성 관리와 통합을 단순화하는 패키지 매니저인 vcpkg를 사용하여 Zabbix agent를 빌드하는 방법을 설명합니다.
1. Build Tools for Visual Studio 2022를 다운로드하고 설치합니다. 설치 중에 vcpkg 패키지 매니저가 포함된 Desktop development with C++ 워크로드를 선택해야 합니다.
2. Go를 다운로드하고 설치합니다 (MSI 설치 프로그램으로 제공).
설치 중에 설치 폴더를 C:\Zabbix\Go로 지정해야 합니다.
3. Microsoft Visual C 런타임 라이브러리를 사용하는 MinGW 배포판을 다운로드합니다. 예를 들어:
- 64비트 빌드용:
x86_64-15.1.0-release-win32-seh-msvcrt-rt_v12-rev0.7z - 32비트 빌드용:
i686-15.1.0-release-win32-dwarf-msvcrt-rt_v12-rev0.7z
그런 다음 C:\Zabbix\mingw64(또는 32비트 빌드의 경우 C:\Zabbix\mingw32)에 압축을 해제합니다.
4. vcpkg를 초기화하고 Zabbix agent 2 빌드에 필요한 의존성을 설치합니다 (시간이 걸릴 수 있습니다):
cd C:\Zabbix
set PATH=%PATH%;"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\vcpkg"
vcpkg new --application
vcpkg add port pcre2
vcpkg add port libiconv
vcpkg add port openssl
# 64비트 빌드의 경우:
set PATH=C:\Zabbix\mingw64\bin;%PATH%
vcpkg install --triplet x64-mingw-static --x-install-root=x64
# 32비트 빌드의 경우:
set PATH=C:\Zabbix\mingw32\bin;%PATH%
vcpkg install --triplet x86-mingw-static --x-install-root=x86
5. Zabbix 소스 아카이브를 다운로드하고 C:\Zabbix\zabbix-7.0.0에 압축을 해제합니다.
6. Zabbix 빌드 디렉토리(C:\Zabbix\zabbix-7.0.0\build\mingw)로 이동하여 다음 build.bat 스크립트를 생성합니다:
- 64비트 빌드의 경우:
:: 현재 세션의 시스템 `PATH` 변수에 MinGW와 Go를 추가:
set PATH=C:\Zabbix\mingw64\bin;%PATH%
set PATH=C:\Zabbix\Go\bin;%PATH%
:: vcpkg 설치 경로 설정:
set vcpkg="C:\Zabbix\x64\x64-mingw-static"
:: Crypt32 라이브러리의 링커 플래그 설정:
SET CGO_LDFLAGS="-lCrypt32"
:: 빌드 프로세스 실행:
mingw32-make GOFLAGS="-buildvcs=false" ARCH=AMD64 ^
PCRE2="%vcpkg%" ^
OPENSSL="%vcpkg%" ^
all
- 32비트 빌드의 경우:
:: 현재 세션의 시스템 `PATH` 변수에 MinGW와 Go를 추가:
set PATH=C:\Zabbix\mingw32\bin;%PATH%
set PATH=C:\Zabbix\Go\bin;%PATH%
:: vcpkg 설치 경로 설정:
set vcpkg="C:\Zabbix\x86\x86-mingw-static"
:: Crypt32 라이브러리의 링커 플래그 설정:
SET CGO_LDFLAGS="-lCrypt32"
:: 빌드 프로세스 실행:
mingw32-make GOFLAGS="-buildvcs=false" ARCH=x86 ^
PCRE2="%vcpkg%" ^
OPENSSL="%vcpkg%" ^
all
7. 스크립트를 실행하여 Zabbix agent 2를 컴파일합니다:
build.bat
컴파일 후 Zabbix agent 2 바이너리는 C:\Zabbix\zabbix-7.0.0\bin\win64(64비트 빌드의 경우) 또는 C:\Zabbix\zabbix-7.0.0\bin\win32(32비트 빌드의 경우)에 위치합니다.
Zabbix agent 2 설정 파일은 C:\Zabbix\zabbix-7.0.0\src\go\conf에 있습니다.
에이전트를 실행하려면 zabbix_agent2.exe와 설정 파일을 전용 폴더(예: C:\Zabbix\agent2)로 복사한 다음 에이전트를 실행합니다:
mkdir C:\Zabbix\agent2
# 64비트 빌드의 경우:
copy C:\Zabbix\zabbix-7.0.0\bin\win64\zabbix_agent2.exe C:\Zabbix\agent2\
# 32비트 빌드의 경우:
copy C:\Zabbix\zabbix-7.0.0\bin\win32\zabbix_agent2.exe C:\Zabbix\agent2\
copy C:\Zabbix\zabbix-7.0.0\src\go\conf\zabbix_agent2.win.conf C:\Zabbix\agent2\
xcopy /E /I C:\Zabbix\zabbix-7.0.0\src\go\conf\zabbix_agent2.d C:\Zabbix\agent2\zabbix_agent2.d\
C:\Zabbix\agent2\zabbix_agent2.exe -c C:\Zabbix\agent2\zabbix_agent2.win.conf
필요한 경우 Zabbix agent 2 로드 가능한 플러그인 컴파일을 계속 진행합니다.
Zabbix agent 2 로드 가능한 플러그인 컴파일하기
1. Zabbix agent 2 버전과 일치하는 Zabbix 플러그인 소스를 다운로드하고(예: zabbix-agent2-plugin-postgresql-7.0.0.tar.gz) C:\Zabbix에 압축을 해제합니다.
플러그인을 설치하기 전에 README 파일을 확인해주세요. 특정 요구사항과 설치 지침이 포함되어 있을 수 있습니다.
2. 압축 해제된 플러그인 디렉토리로 이동하고 플러그인을 컴파일합니다:
cd C:\Zabbix\zabbix-agent2-plugin-ember-plus-7.0.0
# 64비트 빌드의 경우:
mingw32-make ARCH=AMD64
# 32비트 빌드의 경우:
mingw32-make ARCH=x86
컴파일 후, Zabbix agent 2 플러그인 바이너리와 해당 설정 파일이 같은 플러그인 디렉토리에 위치하게 됩니다.
플러그인 실행 파일은 Zabbix agent 2에서 로드할 수 있다면 어디에든 배치할 수 있습니다. 플러그인 설정 파일에서 플러그인 바이너리의 경로를 지정하세요. 예를 들어 PostgreSQL 플러그인의 postgresql.conf에서:
Plugins.PostgreSQL.System.Path=/path/to/executable/zabbix-agent2-plugin-postgresql
플러그인 설정 파일의 경로는 Zabbix agent 2 설정 파일의 Include 매개변수에서 지정해야 합니다:
Include=/path/to/plugin/configuration/file/postgresql.conf
플러그인 설정에 대한 자세한 내용은 설정으로 진행하세요.
Zabbix agent 2 수동 빌드
이 Zabbix agent 2 빌드 방법은 빌드 환경에 대한 완전한 제어가 필요하거나 vcpkg 사용이 불가능한 제한된 환경에 있는 사용자에게 적합합니다.
이 섹션에는 필요한 빌드 도구와 종속성을 설치한 다음 에이전트를 컴파일하는 것을 포함하여 Zabbix agent 2를 수동으로 빌드하는 방법에 대한 지침이 포함되어 있습니다.
빌드 도구 설정
1. MSYS2를 다운로드하고 설치하세요 (MSI 설치 프로그램으로 제공됩니다).
설치 중에 설치 폴더로 C:\Zabbix\msys64를 지정해야 합니다.
2. Go를 다운로드하고 설치하세요 (MSI 설치 프로그램으로 제공됩니다; 현재 지원되는 Go 버전을 참조하세요).
설치 중에 설치 폴더로 C:\Zabbix\Go를 지정해야 합니다.
3. Microsoft Visual C 런타임 라이브러리를 사용하는 MinGW 배포판을 다운로드하세요. 예를 들어:
- 64비트 빌드의 경우:
x86_64-15.1.0-release-win32-seh-msvcrt-rt_v12-rev0.7z - 32비트 빌드의 경우:
i686-15.1.0-release-win32-dwarf-msvcrt-rt_v12-rev0.7z
그런 다음, C:\Zabbix\mingw64 (또는 32비트 빌드의 경우 C:\Zabbix\mingw32)에 압축을 해제하세요.
Installing OpenSSL
To compile Zabbix agent without TLS support, proceed to the Installing PCRE2 section.
1. Open the MSYS2 MSYS terminal with administrator privileges and run the following commands:
pacman -S perl-Locale-Maketext-Simple
pacman -S nasm
pacman -S make
pacman -S cmake
2. Download the OpenSSL source archive and extract it to C:\Zabbix\openssl-3.5.0.
3. Navigate to the extracted OpenSSL directory and create the following build.sh script:
- For 64-bit builds:
#!/usr/bin/env bash
export PATH="/c/Zabbix/mingw64/bin:$PATH"
export d="/c/Zabbix/x64/OpenSSL-Win64-350-static"
perl Configure mingw64 no-shared no-capieng no-winstore no-srp no-gost no-dgram no-dtls1-method no-dtls1_2-method thread_scheme=winthreads --api=1.1.0 --prefix=$d --openssldir=$d
make
make install
- For 32-bit builds:
#!/usr/bin/env bash
export PATH="/c/Zabbix/mingw32/bin:$PATH"
export d="/c/Zabbix/x86/OpenSSL-Win64-350-static"
perl Configure mingw no-shared no-capieng no-winstore no-srp no-gost no-dgram no-dtls1-method no-dtls1_2-method thread_scheme=winthreads --api=1.1.0 --prefix=$d --openssldir=$d
make
make install
Make sure to revoke write access from non-administrator users to the C:\Zabbix\x64\OpenSSL-Win64-350-static directory.
Otherwise, the agent will load SSL settings from a path that can be modified by unprivileged users, resulting in a potential security vulnerability.
- The
no-sharedoption 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. - Without the
no-sharedoption, 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.
4. Configure and install OpenSSL by executing the script (note that this may take some time):
cd /c/Zabbix/openssl-3.5.0
./build.sh
Installing PCRE2
1. Download PCRE2 source archive and extract it to C:\Zabbix\pcre2-10.45.
2. Open the MSYS2 MSYS terminal with administrator privileges.
Then, create a build directory in the extracted PCRE2 directory and navigate to it:
mkdir /c/Zabbix/pcre2-10.45/build
cd /c/Zabbix/pcre2-10.45/build
3. Configure PCRE2:
# For 64-bit builds:
export PATH="/c/Zabbix/mingw64/bin:$PATH"
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_C_FLAGS="-O2 -g" -DCMAKE_INSTALL_PREFIX="/c/Zabbix/x64/PCRE2" ..
# For 32-bit builds:
export PATH="/c/Zabbix/mingw32/bin:$PATH"
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_C_FLAGS="-m32 -O2 -g" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-mi386pe" -DCMAKE_INSTALL_PREFIX="/c/Zabbix/x86/PCRE2" ..
If any errors occur, it is recommended to delete the CMake cache before attempting to repeat the CMake build process.
The cache (CMakeCachecache.txt) can be located in the build directory of the extracted PCRE2 directory.
4. Install PCRE2:
make install
Compiling Zabbix agent 2
1. Download the Zabbix source archive and extract it to C:\Zabbix\zabbix-7.0.0.
If you need to generate a source archive from the raw source repository (e.g., to apply custom patches or build from the latest source code), run the following commands on a Linux machine with Go installed (required for configuring Zabbix agent 2):
git clone https://git.zabbix.com/scm/zbx/zabbix.git
cd zabbix
./bootstrap.sh
./configure --enable-agent2 --enable-ipv6 --prefix=`pwd`
make dist
This will create a source archive, which can then be copied to a Windows machine.
2. Open the Command Prompt with administrator privileges. Then, navigate to the Zabbix build directory and compile Zabbix agent; make sure to correctly specify the directories where OpenSSL and PCRE2 are installed:
- For 64-bit builds:
cd C:\Zabbix\zabbix-7.0.0\build\mingw
set PATH=C:\Zabbix\mingw64\bin;%PATH%
mklink /D C:\Zabbix\x64\OpenSSL-Win64-350-static\lib C:\Zabbix\x64\OpenSSL-Win64-350-static\lib64
# With TLS support:
mingw32-make ARCH=AMD64 PCRE2="C:\Zabbix\x64\PCRE2" OPENSSL="C:\Zabbix\x64\OpenSSL-Win64-350-static"
# Without TLS support:
mingw32-make ARCH=AMD64 PCRE2="C:\Zabbix\x64\PCRE2"
- For 32-bit builds:
cd C:\Zabbix\zabbix-7.0.0\build\mingw
set PATH=C:\Zabbix\mingw32\bin;%PATH%
# With TLS support:
mingw32-make ARCH=x86 PCRE2="C:\Zabbix\x86\PCRE2" OPENSSL="C:\Zabbix\x86\OpenSSL-Win64-350-static"
# Without TLS support:
mingw32-make ARCH=x86 PCRE2="C:\Zabbix\x86\PCRE2"
After compilation, the Zabbix agent 2 binary will be located in C:\Zabbix\zabbix-7.0.0\bin\win64 (or C:\Zabbix\zabbix-7.0.0\bin\win32 for 32-bit builds).
Zabbix agent 2 configuration files are located in C:\Zabbix\zabbix-7.0.0\src\go\conf.
To run the agent, copy the zabbix_agent2.exe binary and its configuration files to a dedicated folder (e.g., C:\Zabbix\agent2) and then run the agent:
mkdir C:\Zabbix\agent2
copy C:\Zabbix\zabbix-7.0.0\bin\win64\zabbix_agent2.exe C:\Zabbix\agent2\
copy C:\Zabbix\zabbix-7.0.0\src\go\conf\zabbix_agent2.win.conf C:\Zabbix\agent2\
xcopy /E /I C:\Zabbix\zabbix-7.0.0\src\go\conf\zabbix_agent2.d C:\Zabbix\agent2\zabbix_agent2.d\
C:\Zabbix\agent2\zabbix_agent2.exe -c C:\Zabbix\agent2\zabbix_agent2.win.conf
If necessary, continue with compiling Zabbix agent 2 loadable plugins.