主要通过Agent/Snmp两种方式进行监控,下面分别介绍:
方法一:通过agent客户端
[Zabbix Agent介绍]
zabbix 自带的客户端程序(被动模式),zabbix server主动向它收集监控数据。agent提供丰富的key,包括不限于cpu、内存、网络、磁盘、web等等。如果你不介意或者系统支持安装此程序,那么他是首选的。
如果你需要针对服务器进行日志文件等检查,那么你也必须要Zabbix Agent客户端(主动模式)。
[Zabbix Agent部署]
AutoDeployWinAgent.ps1脚本:
wget https://www.zabbix.com/downloads/3.4.6/zabbix_agents_3.4.6.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=192.168.0.99" 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=192.168.0.99" C:\zabbix_agent\conf\zabbix_agentd.win.conf
Add-Content -value "EnableRemoteCommands=1" C:\zabbix_agent\conf\zabbix_agentd.win.conf
Add-Content -value "UnsafeUserParameters=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
wget https://www.zabbix.com/downloads/3.4.6/zabbix_agents_3.4.6.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=192.168.0.99" 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=192.168.0.99" C:\zabbix_agent\conf\zabbix_agentd.win.conf
Add-Content -value "EnableRemoteCommands=1" C:\zabbix_agent\conf\zabbix_agentd.win.conf
Add-Content -value "UnsafeUserParameters=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
执行完如上Powershell脚本后,检查配置文件:
启动Zabbix服务:
Zabbix新增监控主机:
导航路径:配置 > 主机 > 创建主机
主机配置 关键参数:
主机名称 > 此参数需要与Zabbix Client配置文件一致;
代理地址 > 此参数需要与Zabbix Client网络地址一致;
模板设置 [Template OS Windows]
检查确认新增监控状态
在这里插入图片描述
导航路径:监控中 > 最新数据 > 主机过滤 [ZServer04]
————————————————
方法一:通过snmp监控
[Zabbix SNMP介绍]
如果服务器无法安装第三方软件(如存储设备、网络设备、其他供应商维护系统),那么可以考虑Zabbix SNMP监控方式,他可以收集一些必要的设备信息,如存活、性能、网络等。
[SNMP配置]
InstallSNMP.ps1 脚本参考:
适用范围:Windows 2008, 2008 R2, 2012, 2012 R2, 2016
####################################
# Last update: 20190813
# Description: Powershell script to install and configure SNMP Services on Windows 2008R2, 2012, 2012R2 and 2016 Server (SNMP Service, SNMP WMI Provider)
# start As Administrator with C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -Command "&{ \\Servername\InstallSNMP\installsnmp.ps1}"
# Script Location: \\Servername\InstallSNMP\installsnmp.ps1
####################################
#Variables :)
$PManagers = @("192.168.0.99") # ADD YOUR MANAGER(s) in format @("manager1","manager2")
$CommString = @("zhong") # ADD YOUR COMM STRING(s) in format @("Community1","Community2")
#Import ServerManger Module
Import-Module ServerManager
#Check if SNMP-Service is already installed
$check = Get-WindowsFeature -Name SNMP-Service
If ($check.Installed -ne "True")
{
#Install/Enable SNMP-Service
Write-Host "SNMP Service Installing..."
# Get OS Version to use the right install command
[int]$verMajor = [environment]::OSVersion.Version | ft -property Major -HideTableHeaders -auto | Out-String
[int]$verMinor = [environment]::OSVersion.Version | ft -property Minor -HideTableHeaders -auto | Out-String
if ($verMajor -eq 6)
{
$winVer = switch ($verMinor)
{
0 {"Win2008"}
1 {"Win2008R2"}
2 {"Win2012"}
3 {"Win2012R2"}
}
}
if ($verMajor -eq 10)
{
$winVer = switch ($verMinor)
{
0 {"Win2016"}
}
}
#Install SNMP on 2008 (R2)
if ($winVer -eq "Win2008" -or $winVer -eq "Win2008R2")
{
Get-WindowsFeature -name SNMP* | Add-WindowsFeature | Out-Null
}
#Install SNMP on 20012 (R2)
if ($winVer -eq "Win2012" -or $winVer -eq "Win2012R2" -or $winVer -eq "Win2016")
{
Get-WindowsFeature -name SNMP* | Add-WindowsFeature -IncludeManagementTools | Out-Null
}
}
$check = Get-WindowsFeature -Name SNMP-Service
##Verify Windows Services Are Enabled
If ($check.Installed -eq "True")
{
Write-Host "Configuring SNMP Services..."
#Set SNMP Permitted Manager(s) ** WARNING : This will over write current settings **
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d localhost /f | Out-Null
#Set SNMP Traps and SNMP Community String(s) - *Read Only*
Foreach ($String in $CommString)
{
reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /f | Out-Null
# Set the Default value to be null
reg delete ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /ve /f | Out-Null
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v $String /t REG_DWORD /d 4 /f | Out-Null
$i = 2
Foreach ($Manager in $PManagers)
{
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\PermittedManagers" /v $i /t REG_SZ /d $manager /f | Out-Null
reg add ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\" + $String) /v $i /t REG_SZ /d $manager /f | Out-Null
$i++
}
}
}
Else
{
Write-Host "Error: SNMP Services Not Installed"
}
执行上述Powershell实施SNMP服务部署与配置,重启服务器才可以让SNMP Service完全生效。
检查SNMP Service服务状态。
[Zabbix配置]
Zabbix Server新建监控主机
导航路径:配置 > 主机 > 创建主机
主机配置 关键参数:
主机名称 > 此参数与监控主机主机名称一致;
代理地址 > 此参数与监控主机网络地址一致;
模板设置 [Template OS Windows SNMPv2]
检查确认新增监控状态
※ 如果失败,请检查[管理 > 一般 >宏]是否正常设置默认团体名。
导航路径:监控中 > 最新数据 > 主机过滤 [ZServer02]