我在公司搭建zabbix server 之后,想要将公司所有的windows服务器加入zabbix ,但是由于服务器有很多,如果一台一台安装zabbix agent 那么会浪费很多时间。所以这里我们使用bat脚本来部署zabbix agent
创建bat脚本
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd \
Set zabbix_server_ip="ip"
mkdir c:\zabbix
mkdir c:\zabbix\log
mkdir c:\zabbix\win
xcopy \\ip\share\zabbix_adents_3.4.0.win c:\zabbix\ /s
::copy /y c:\zabbix\conf\zabbix_agent.win.conf c:\zabbix\
if %process_architecture% EQU x86 copy /y c:\zabbix\bin\win32 c:\zabbix\win
if %process_architecture% EQU AMD64 copy /y c:\zabbix\bin\win64 c:\zabbix\win
::安装zabbix_agent
c:\zabbix\win\zabbix_agentd.exe -i -c c:\zabbix\conf\zabbix_agentd.win.conf
net start "zabbix Agent"
::入站规则
netsh advfirewall firewall add rule name="zabbix_agent_10050" dir=in protocol=tcp action=allow localport=10050
::出站规则
netsh advfirewall firewall add rule name="zabbix_agent_10050" dir=out protocol=tcp action=allow localport=10050