1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
############################################
#Author:Lixiaosong
#lixiaosong8706@gmail.com
#For:Auto install zabbix-agent
#Version:1.0
##############################################
wget http://www.zabbix.com/downloads/2.4.1/zabbix_agents_2.4.1.win.zip -OutFile C:\zabbix_agent.zip
Function
Unzip
-File
()
{
param
(
[string]
$ZipFile
,
[string]
$TargetFolder
)
#确保目标文件夹必须存在
if
(!(
Test-Path
$TargetFolder
))
{
mkdir
$TargetFolder
}
$shellApp
=
New-Object
-ComObject Shell.Application
$files
=
$shellApp
.NameSpace(
$ZipFile
).Items()
$shellApp
.NameSpace(
$TargetFolder
).CopyHere(
$files
)
}
#将安装文件解压
Unzip
-File
-ZipFile C:\zabbix_agent.zip -TargetFolder C:\zabbix_agent
#删除默认配置文件
rm C:\zabbix_agent\conf\zabbix_agentd.win.conf
$hostname
=hostname
Add-Content
-value
"LogFile=C:\zabbix_agent\zabbix.log"
C:\zabbix_agent\conf\zabbix_agentd.win.conf
Add-Content
-value
"Server=1.1.1.1"
C:\zabbix_agent\conf\zabbix_agentd.win.conf
Add-Content
-value
"Hostname=$hostname"
C:\zabbix_agent\conf\zabbix_agentd.win.conf
Add-Content
-value
"ServerActive=1.1.1.1"
C:\zabbix_agent\conf\zabbix_agentd.win.conf
#判断系统类型
$sysinfo
=(systeminfo.exe)[14]
$sysinfonew
=
$sysinfo
.Replace(
"系统类型: "
,"
")
if ($sysinfonew -like "
x64-based PC
" ){
C:\zabbix_agent\bin\win64\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -i}
else {C:\zabbix_agent\bin\win32\zabbix_agentd.exe -c C:\zabbix_agent\conf\zabbix_agentd.win.conf -i}
Start-Service "
Zabbix Agent"
rm C:\zabbix_agent.zip
|
本文转自handsome7038 51CTO博客,原文链接:http://blog.51cto.com/lixiaosong/1663595