天天看點

windows bat腳本自動安裝與啟動zabbix agent 防火牆開通10050

我在公司搭建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           

繼續閱讀