第一部分:系統準備與SolarWinds安裝
1. 系統準備
1.1 安裝Windows Server 2022
-
從Microsoft官網下載ISO鏡像
-
使用Rufus等工具創建啓動U盤
-
完成基本安裝(選擇"帶GUI的服務器")
1.2 系統更新與基礎配置
# 以管理員身份打開PowerShell執行以下命令
# 檢查並安裝Windows更新
Install-Module -Name PSWindowsUpdate -Force
Import-Module PSWindowsUpdate
Get-WindowsUpdate -AcceptAll -Install -AutoReboot
# 啓用遠程桌面
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -DisplayGroup "遠程桌面"
# 設置服務器靜態IP(根據實際網絡調整)
New-NetIPAddress -IPAddress "192.168.1.100" -PrefixLength 24 -DefaultGateway "192.168.1.1" -InterfaceIndex (Get-NetAdapter).InterfaceIndex
Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).InterfaceIndex -ServerAddresses ("8.8.8.8", "8.8.4.4")
# 更改計算機名並重啓
Rename-Computer -NewName "SOLARWINDS-MONITOR" -Restart
2. 安裝SQL Server 2019(SolarWinds依賴)
2.1 下載SQL Server 2019
# 下載SQL Server 2019 Developer Edition(免費用於開發測試)
$url = "https://go.microsoft.com/fwlink/?linkid=866662"
$output = "$env:USERPROFILE\Downloads\SQLServer2019-SSEI-Dev.exe"
Invoke-WebRequest -Uri $url -OutFile $output
# 啓動安裝程序
Start-Process -FilePath $output
2.2 圖形界面安裝步驟
-
選擇"基本"安裝類型
-
接受許可條款
-
指定安裝位置(建議保持默認)
-
點擊"安裝"按鈕
-
安裝完成後記下顯示的SQL Server名稱(通常為"主機名\SQLEXPRESS")
2.3 驗證SQL Server安裝
# 檢查SQL Server服務狀態
Get-Service -Name "MSSQL`$SQLEXPRESS"
# 應該看到狀態為"Running"
3. 安裝SolarWinds Orion
3.1 下載SolarWinds Orion安裝包
# 從SolarWinds官網下載評估版(需要註冊)
# 以下為示例命令,實際URL需從官網獲取
$url = "https://downloads.solarwinds.com/solarwinds/Release/Orion/2020.2.1/OrionInstaller.exe"
$output = "$env:USERPROFILE\Downloads\OrionInstaller.exe"
Invoke-WebRequest -Uri $url -OutFile $output
# 啓動安裝程序
Start-Process -FilePath $output
3.2 圖形界面安裝步驟
-
接受許可協議
-
選擇"Complete Installation"
-
輸入SQL Server信息:
-
Server Name: 本地服務器名(如
SOLARWINDS-MONITOR\SQLEXPRESS) -
Authentication: Windows Authentication
-
-
設置主賬户信息:
-
Username: admin
-
Password: 設置強密碼(建議包含大小寫字母、數字和特殊字符)
-
-
選擇安裝組件(全選)
-
點擊"Install"開始安裝
-
安裝完成後啓動"Orion Web Console"
第二部分:添加網絡設備監控
1. 配置SNMP服務(用於本地測試)
# 安裝SNMP服務
Install-WindowsFeature -Name SNMP-Service
# 配置SNMP團體字符串
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities" /v public /t REG_DWORD /d 4 /f
# 允許來自任何主機的SNMP查詢
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers" /v 1 /t REG_SZ /d "*" /f
# 重啓SNMP服務
Restart-Service -Name SNMP
2. 添加思科設備
-
登錄SolarWinds Web控制枱(http://localhost:8787)
-
導航至"Settings" > "Network Discovery"
-
點擊"New Discovery"
-
配置發現參數:
-
Discovery Type: IP Range
-
IP Address Range: 輸入思科設備IP範圍(如192.168.1.1-192.168.1.10)
-
SNMP Credentials: 添加新的SNMP憑據
-
Community String: public(或設備實際團體字)
-
Version: v2c
-
-
-
在"Select Pollers"中勾選:
-
Cisco Discovery
-
Interface Statistics
-
Node Performance
-
-
點擊"Discover Now"
3. 添加華為設備
-
導航至"Settings" > "Network Discovery"
-
點擊"New Discovery"
-
配置發現參數:
-
Discovery Type: IP Range
-
IP Address Range: 輸入華為設備IP範圍
-
SNMP Credentials: 使用與思科相同的憑據或創建新的
-
-
在"Select Pollers"中勾選:
-
Generic SNMP Device Discovery
-
Interface Statistics
-
Node Performance
-
-
點擊"Advanced" > "SNMP Options":
-
添加華為特定OID: 1.3.6.1.4.1.2011
-
-
點擊"Discover Now"
4. 添加華三設備
-
導航至"Settings" > "Network Discovery"
-
點擊"New Discovery"
-
配置發現參數:
-
Discovery Type: IP Range
-
IP Address Range: 輸入華三設備IP範圍
-
SNMP Credentials: 使用現有憑據
-
-
在"Select Pollers"中勾選:
-
Generic SNMP Device Discovery
-
Interface Statistics
-
Node Performance
-
-
點擊"Advanced" > "SNMP Options":
-
添加華三特定OID: 1.3.6.1.4.1.25506
-
-
點擊"Discover Now"
5. 添加鋭捷設備
-
導航至"Settings" > "Network Discovery"
-
點擊"New Discovery"
-
配置發現參數:
-
Discovery Type: IP Range
-
IP Address Range: 輸入鋭捷設備IP範圍
-
SNMP Credentials: 使用現有憑據
-
-
在"Select Pollers"中勾選:
-
Generic SNMP Device Discovery
-
Interface Statistics
-
Node Performance
-
-
點擊"Advanced" > "SNMP Options":
-
添加鋭捷特定OID: 1.3.6.1.4.1.4881
-
-
點擊"Discover Now"
第三部分:告警配置
1. 配置郵件通知
-
導航至"Settings" > "All Settings" > "Alerting" > "Mail Server"
-
配置SMTP服務器:
-
SMTP Server: 輸入郵件服務器地址(如smtp.office365.com)
-
Port: 587(TLS)或465(SSL)
-
Authentication: 選擇"Basic"
-
Username: 發件郵箱地址
-
Password: 郵箱密碼
-
From Address: 發件人郵箱
-
-
點擊"Test"驗證配置
-
點擊"Save"
2. 配置短信通知(以Twilio為例)
-
導航至"Settings" > "All Settings" > "Alerting" > "Custom Scripts"
-
創建新腳本:
-
Name: Twilio SMS Alert
-
Script Type: PowerShell
-
-
輸入以下腳本(替換Twilio賬户信息):
param($Subject, $Message, $Recipients)
$AccountSid = "YOUR_TWILIO_ACCOUNT_SID"
$AuthToken = "YOUR_TWILIO_AUTH_TOKEN"
$FromNumber = "YOUR_TWILIO_PHONE_NUMBER"
$TwilioApiUrl = "https://api.twilio.com/2010-04-01/Accounts/$AccountSid/Messages.json"
foreach ($recipient in $Recipients) {
$Body = @{
From = $FromNumber
To = $recipient
Body = "$Subject`n$Message"
}
$Bytes = [System.Text.Encoding]::UTF8.GetBytes("$AccountSid`:$AuthToken")
$Base64 = [System.Convert]::ToBase64String($Bytes)
$Headers = @{
Authorization = "Basic $Base64"
}
try {
Invoke-RestMethod -Uri $TwilioApiUrl -Method Post -Body $Body -Headers $Headers
} catch {
Write-Error "Failed to send SMS to $recipient: $_"
}
}
-
點擊"Save"
3. 創建CPU使用率告警
-
導航至"Alert Central"
-
點擊"Create New Alert"
-
選擇"Node CPU Load"
-
配置條件:
-
Trigger when: CPU Load > 80%
-
For at least: 5 minutes
-
-
配置動作:
-
添加郵件通知:選擇之前配置的郵件服務器
-
添加短信通知:選擇Twilio SMS Alert腳本
-
-
點擊"Save"
4. 創建接口丟包告警
-
導航至"Alert Central"
-
點擊"Create New Alert"
-
選擇"Interface Packet Loss"
-
配置條件:
-
Trigger when: Packet Loss > 1%
-
For at least: 3 minutes
-
-
配置動作:
-
添加郵件和短信通知
-
-
點擊"Save"
5. 創建設備宕機告警
-
導航至"Alert Central"
-
點擊"Create New Alert"
-
選擇"Node Down"
-
配置條件:
-
Trigger when: Node is down
-
For at least: 1 minute
-
-
配置動作:
-
添加郵件和短信通知
-
-
點擊"Save"
第四部分:系統測試
1. 設備監控測試
# 測試思科設備SNMP可達性
Test-NetConnection -ComputerName <思科設備IP> -Port 161
# 使用SNMPWalk測試(需安裝SNMP工具)
snmpwalk -v 2c -c public <思科設備IP> .1.3.6.1.2.1.1.1.0
2. 告警觸發測試
# 模擬高CPU負載(在目標設備上)
# 對於Windows設備:
Start-Job -ScriptBlock { while($true) { } }
# 對於Linux設備(通過SSH):
Invoke-Command -ComputerName <Linux設備IP> -ScriptBlock { while true; do :; done } -Credential (Get-Credential)
第五部分:Python一鍵部署腳本
創建deploy_solarwinds.py文件:
import os
import subprocess
import time
import requests
import winreg
import ctypes
def run_powershell(cmd, admin=False):
if admin:
ctypes.windll.shell32.ShellExecuteW(None, "runas", "powershell.exe", f"-Command {cmd}", None, 1)
else:
subprocess.run(["powershell", "-Command", cmd], check=True)
def install_prerequisites():
print("安裝系統更新和必要組件...")
commands = [
"Install-Module -Name PSWindowsUpdate -Force -Confirm:$false",
"Import-Module PSWindowsUpdate",
"Get-WindowsUpdate -AcceptAll -Install -AutoReboot",
"Install-WindowsFeature -Name SNMP-Service",
"Set-ItemProperty -Path 'HKLM:\\System\\CurrentControlSet\\Control\\Terminal Server' -Name 'fDenyTSConnections' -Value 0",
"Enable-NetFirewallRule -DisplayGroup '遠程桌面'"
]
for cmd in commands:
try:
run_powershell(cmd, admin=True)
except subprocess.CalledProcessError as e:
print(f"執行命令失敗: {cmd}\n錯誤: {e}")
def configure_snmp():
print("配置SNMP服務...")
try:
# 設置SNMP團體字符串
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities",
0, winreg.KEY_SET_VALUE)
winreg.SetValueEx(key, "public", 0, winreg.REG_DWORD, 4)
winreg.CloseKey(key)
# 允許所有管理器
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers",
0, winreg.KEY_SET_VALUE)
winreg.SetValueEx(key, "1", 0, winreg.REG_SZ, "*")
winreg.CloseKey(key)
# 重啓SNMP服務
run_powershell("Restart-Service -Name SNMP", admin=True)
except Exception as e:
print(f"配置SNMP失敗: {e}")
def download_and_install(url, file_name, install_args=None):
print(f"下載並安裝 {file_name}...")
try:
# 下載文件
download_path = os.path.join(os.environ["USERPROFILE"], "Downloads", file_name)
response = requests.get(url, stream=True)
with open(download_path, "wb") as f:
for chunk in response.iter_content(chunk_size=8192)