自动化安装zabbix agent在windows2012

来源:互联网 发布:手机上怎样申请淘宝号 编辑:程序博客网 时间:2024/06/08 17:28


通过winrm自动化安装zabbix agent.

1. 设置winrm

2. 下载zabbix安装包到http server下

3. 通过winrm接口执行powershell script,或通过ansible, 先下载脚本,再执行脚本

ansible 10.0.202.219 -m win_command -a "powershell.exe invoke-webrequest -uri http://10.0.202.210:18083/repo/windows/zabbix/zabbix_install.ps1 -outfile C:\zabbix_install.ps1"
ansible 10.0.202.219 -m win_command -a "powershell.exe invoke-webrequest -uri http://10.0.202.210:18083/repo/windows/zabbix/zabbix-win.zip -outfile C:\zabbix\zabbix-win.zip"
ansible 10.0.202.219 -m win_shell -a "C:\zabbix_install.ps1"

=============================================================

zabbix install powershell script:

[root@cop zabbix]# cat zabbix_install.ps1 
param($win_repo_ip,$zabbixserverip)
mkdir C:\zabbix
invoke-webrequest -uri http://$win_repo_ip:18083/repo/windows/zabbix/zabbix-win.zip -outfile C:\zabbix\zabbix-win.zip
$file = "C:\zabbix\zabbix-win.zip"
$shell = New-Object -ComObject shell.application
$zip = $shell.NameSpace($file)
$dest =  $shell.NameSpace((Split-Path $file -Parent))
$dest.CopyHere($zip.Items())


Copy-Item C:\zabbix\zabbix-win\bin\win64\*.exe C:\zabbix\zabbix-win
Copy-Item C:\zabbix\zabbix-win\conf\zabbix_agentd.win.conf C:\zabbix\zabbix-win
Rename-Item C:\zabbix\zabbix-win\zabbix_agentd.win.conf  zabbix_agentd.conf 
Remove-Item C:\zabbix\zabbix-win.zip


$conf= Get-Content C:\zabbix\zabbix-win\zabbix_agentd.conf -Encoding UTF8
$conf= $conf.Replace("LogFile=c:\zabbix_agentd.log", "LogFile=c:\zabbix\zabbix_agentd.log")
$conf= $conf.Replace("Server=127.0.0.1", "Server=$zabbixserverip")
$conf= $conf.Replace("ServerActive=127.0.0.1", "ServerActive=$zabbixserverip:10051")
$conf= $conf.Replace("Hostname=Windows host", "Hostname=${Env:COMPUTERNAME}")
#$conf= $conf.Replace("# HostnameItem=system.hostname", "HostnameItem=system.hostname")
$conf= $conf.Replace("# HostMetadata=", "HostMetadata=")


[IO.File]::WriteAllLines("C:\zabbix\zabbix-win\zabbix_agentd.conf", $conf)


cd  C:\zabbix\zabbix-win
.\zabbix_agentd.exe -i -c C:\zabbix\zabbix-win\zabbix_agentd.conf
.\zabbix_agentd.exe -s -c zabbix_agentd.conf
if (-not(Get-NetFirewallRule | where Name -eq "Zabbix Agent"))
{
    New-NetFirewallRule `
        -Name "Zabbix Agent" `
        -DisplayName "Zabbix Agent" `
        -Description "for Zabbix Agent" `
        -Group "Zabbix" `
        -Enabled True `
        -Profile Any `
        -Direction Inbound `
        -Action Allow `
        -EdgeTraversalPolicy Block `
        -LooseSourceMapping $False `
        -LocalOnlyMapping $False `
        -OverrideBlockRules $False `
        -Program Any `
        -LocalAddress Any `
        -RemoteAddress Any `
        -Protocol TCP `
        -LocalPort 10050 `
        -RemotePort Any `
        -LocalUser Any `
        -RemoteUser Any


}
else
{
        echo "Windows PowerShell Remoting port TCP 10050 was alredy opend. Show Rule"
        Get-NetFirewallPortFilter -Protocol TCP | where Localport -eq 10050
}

=====================================


ansible 10.0.202.219 -m win_command -a "powershell.exe invoke-webrequest -uri http://10.0.202.210:18083/repo/windows/zabbix/zabbix_install.ps1 -outfile C:\zabbix_install.ps1"
ansible 10.0.202.219 -m win_shell -a "C:\zabbix_install.ps1"

阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小泰迪剃毛多少钱 萨摩耶掉毛 猫掉毛 给泰迪修毛 毛织厂 狗掉毛 小狗掉毛 貂毛 柯基犬掉毛吗 泰迪狗几个月剃毛 狗狗剃毛要多少钱 狗皮肤病掉毛 毛毛衣 猫剃毛 狗狗剃毛 拔毛 毛织网 比熊剃毛 翻毛 毛粘布 蓝毛 狗掉毛皮肤病 剃完毛的泰迪 羊吃毛 如何给泰迪狗狗剃毛 羊绒衫掉毛 毛芋艿 顺毛 毛选 毛背心 毛领子 灯芯绒粘毛 狗狗掉毛 毛巾掉毛 土毛酒 不掉毛的毛巾 fgobx毛 多毛的 毛丽 毛乐 毛人