环境:windows server 2008 r2,zabbix_agent-4.4.4-windows-amd64
本文脚本适用:windows
自己写了一个Zabbix agent批处理文件,将脚本放在zabbixl目录下双击运行,然后输入服务器IP,就可以配置安装并启动服务,脚本运行位置如下图所示:
脚本代码如下:
::设置标题
title Installing Zabbix-Agent
@echo off
setlocal enabledelayedexpansion
::配置文件中的默认文本赋值给变量
set oldip1=127.0.0.1
set oldname=Windows host
::输入zabbix server的IP,并确认
:inputip
set sure=yes
set /p serverip=Please input server ip:
set /p sure=Are you sure ip=%serverip%[yes/no default:yes]:
::不确认就返回在输入一次
if %sure% == no (
goto :inputip
)
::获取本机的地址,然后保存到变量,后面将配置文件中的主机名更换为本机IP
ipconfig | find "IPv4" > installing
for /f "tokens=15 delims=: " %%a in (installing) do (
set localip=%%a
)
del /f installing
::替换配置文件中原有的信息
for /f "delims=" %%a in (./conf/zabbix_agentd.conf) do (
set "text=%%a"
set "text=!text:%oldip1%=%serverip%!"
set "text=!text:%oldname%=%localip%!"
echo !text! >> $
)
move $ ./conf/zabbix_agentd.conf
echo installing "Zabbix Agent"...
cd bin
::安装zabbix客户端
zabbix_agentd.exe -c ../conf/zabbix_agentd.conf -i
echo Start "Zabbix Agent" service...
::启动zabbix agent服务
sc start "Zabbix Agent"
echo Service starting
echo Install success!
pause
运行结果如下图:
参考资料
zabbix安装:https://blog.csdn.net/alfiy/article/details/124783719
bat修改文件内容:https://blog.csdn.net/everdayPHP/article/details/78919020
2302



被折叠的 条评论
为什么被折叠?



