只支持64位系统,zabbix_agent2-6.0.25-windows-amd64-openssl.msi安装文件跟bat脚本放同一个目录。
zabbix_agent2.conf 是用来配置HostMetadata 自动注册的。
根据自身环境,更改zabbix服务器IP:
SERVER=192.168.1.245
SERVERACTIVE=192.168.1.245
@echo off
mode con cols=120 lines=30 & color 3f
set current_dir=%~dp0
cd /d %current_dir%
rem 判断是否以管理员运行
net.exe session 1>NUL 2>NUL && ( goto Checksys ) || ( goto not_admin )
:not_admin
echo.
echo.
echo "*********请以管理员权限运行此脚本*********"
echo.
echo.
pause
exit
rem 判断是否64位系统
:Checksys
if "%PROCESSOR_ARCHITECTURE%"=="x86" (goto x86) else goto CheckService
:x86
echo.
echo.
echo "*********不支持32位系统*********"
echo.
echo.
pause
exit
rem 判断agent是否已经安装
:CheckService
sc query "Zabbix Agent 2" > nul
if errorlevel 1060 (goto InstallAgent) else goto ServiceExist
:ServiceExist
echo.
echo.
echo "******* 本机已安装 Zabbix Agent 2 *******"
echo.
echo.
pause
exit
rem 开始安装agent
:InstallAgent
SET INSTALLFOLDER=C:\Program Files\Zabbix Agent 2
echo "正在安装agent..."
msiexec /l*v zabbix-agent2-installlog.txt /i zabbix_agent2-6.0.25-windows-amd64-openssl.msi /qn SERVER=192.168.1.245 LISTENPORT=10050 SERVERACTIVE=192.168.1.245 INSTALLFOLDER="%INSTALLFOLDER%"
echo "Copy conf file..."
copy /y zabbix_agent2.conf "%INSTALLFOLDER%\zabbix_agent2.conf"
ping 127.0.0.1 -n 10 >NUL && net stop "Zabbix Agent 2" && net start "Zabbix Agent 2"
sc query |find /i "Zabbix Agent 2" >nul 2>nul
if not errorlevel 1 (goto ServiceStart) else goto ServiceEnd
:ServiceStart
echo.
echo.
echo "******* Zabbix Agent 2 安装成功 *******"
echo.
echo.
pause
exit
:ServiceEnd
echo.
echo.
echo "******* Zabbix Agent 2 安装失败 *******"
echo.
echo.
pause
exit