Stories

Detail Return Return

SolarWinds監控系統在Windows Server 2022上的完整安裝與配置指南 - Stories Detail

第一部分:系統準備與SolarWinds安裝

1. 系統準備

1.1 安裝Windows Server 2022

  • 從Microsoft官網下載ISO鏡像

  • 使用Rufus等工具創建啓動U盤

  • 完成基本安裝(選擇"帶GUI的服務器")

1.2 系統更新與基礎配置

powershell
 
# 以管理員身份打開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

powershell
 
# 下載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 圖形界面安裝步驟

  1. 選擇"基本"安裝類型

  2. 接受許可條款

  3. 指定安裝位置(建議保持默認)

  4. 點擊"安裝"按鈕

  5. 安裝完成後記下顯示的SQL Server名稱(通常為"主機名\SQLEXPRESS")

2.3 驗證SQL Server安裝

powershell
 
# 檢查SQL Server服務狀態
Get-Service -Name "MSSQL`$SQLEXPRESS"

# 應該看到狀態為"Running"

3. 安裝SolarWinds Orion

3.1 下載SolarWinds Orion安裝包

powershell
 
# 從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 圖形界面安裝步驟

  1. 接受許可協議

  2. 選擇"Complete Installation"

  3. 輸入SQL Server信息:

    • Server Name: 本地服務器名(如SOLARWINDS-MONITOR\SQLEXPRESS

    • Authentication: Windows Authentication

  4. 設置主賬户信息:

    • Username: admin

    • Password: 設置強密碼(建議包含大小寫字母、數字和特殊字符)

  5. 選擇安裝組件(全選)

  6. 點擊"Install"開始安裝

  7. 安裝完成後啓動"Orion Web Console"

第二部分:添加網絡設備監控

1. 配置SNMP服務(用於本地測試)

powershell
 
# 安裝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. 添加思科設備

  1. 登錄SolarWinds Web控制枱(http://localhost:8787)

  2. 導航至"Settings" > "Network Discovery"

  3. 點擊"New Discovery"

  4. 配置發現參數:

    • Discovery Type: IP Range

    • IP Address Range: 輸入思科設備IP範圍(如192.168.1.1-192.168.1.10)

    • SNMP Credentials: 添加新的SNMP憑據

      • Community String: public(或設備實際團體字)

      • Version: v2c

  5. 在"Select Pollers"中勾選:

    • Cisco Discovery

    • Interface Statistics

    • Node Performance

  6. 點擊"Discover Now"

3. 添加華為設備

  1. 導航至"Settings" > "Network Discovery"

  2. 點擊"New Discovery"

  3. 配置發現參數:

    • Discovery Type: IP Range

    • IP Address Range: 輸入華為設備IP範圍

    • SNMP Credentials: 使用與思科相同的憑據或創建新的

  4. 在"Select Pollers"中勾選:

    • Generic SNMP Device Discovery

    • Interface Statistics

    • Node Performance

  5. 點擊"Advanced" > "SNMP Options":

    • 添加華為特定OID: 1.3.6.1.4.1.2011

  6. 點擊"Discover Now"

4. 添加華三設備

  1. 導航至"Settings" > "Network Discovery"

  2. 點擊"New Discovery"

  3. 配置發現參數:

    • Discovery Type: IP Range

    • IP Address Range: 輸入華三設備IP範圍

    • SNMP Credentials: 使用現有憑據

  4. 在"Select Pollers"中勾選:

    • Generic SNMP Device Discovery

    • Interface Statistics

    • Node Performance

  5. 點擊"Advanced" > "SNMP Options":

    • 添加華三特定OID: 1.3.6.1.4.1.25506

  6. 點擊"Discover Now"

5. 添加鋭捷設備

  1. 導航至"Settings" > "Network Discovery"

  2. 點擊"New Discovery"

  3. 配置發現參數:

    • Discovery Type: IP Range

    • IP Address Range: 輸入鋭捷設備IP範圍

    • SNMP Credentials: 使用現有憑據

  4. 在"Select Pollers"中勾選:

    • Generic SNMP Device Discovery

    • Interface Statistics

    • Node Performance

  5. 點擊"Advanced" > "SNMP Options":

    • 添加鋭捷特定OID: 1.3.6.1.4.1.4881

  6. 點擊"Discover Now"

第三部分:告警配置

1. 配置郵件通知

  1. 導航至"Settings" > "All Settings" > "Alerting" > "Mail Server"

  2. 配置SMTP服務器:

    • SMTP Server: 輸入郵件服務器地址(如smtp.office365.com)

    • Port: 587(TLS)或465(SSL)

    • Authentication: 選擇"Basic"

    • Username: 發件郵箱地址

    • Password: 郵箱密碼

    • From Address: 發件人郵箱

  3. 點擊"Test"驗證配置

  4. 點擊"Save"

2. 配置短信通知(以Twilio為例)

  1. 導航至"Settings" > "All Settings" > "Alerting" > "Custom Scripts"

  2. 創建新腳本:

    • Name: Twilio SMS Alert

    • Script Type: PowerShell

  3. 輸入以下腳本(替換Twilio賬户信息):

powershell
 
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: $_"
    }
}
  1. 點擊"Save"

3. 創建CPU使用率告警

  1. 導航至"Alert Central"

  2. 點擊"Create New Alert"

  3. 選擇"Node CPU Load"

  4. 配置條件:

    • Trigger when: CPU Load > 80%

    • For at least: 5 minutes

  5. 配置動作:

    • 添加郵件通知:選擇之前配置的郵件服務器

    • 添加短信通知:選擇Twilio SMS Alert腳本

  6. 點擊"Save"

4. 創建接口丟包告警

  1. 導航至"Alert Central"

  2. 點擊"Create New Alert"

  3. 選擇"Interface Packet Loss"

  4. 配置條件:

    • Trigger when: Packet Loss > 1%

    • For at least: 3 minutes

  5. 配置動作:

    • 添加郵件和短信通知

  6. 點擊"Save"

5. 創建設備宕機告警

  1. 導航至"Alert Central"

  2. 點擊"Create New Alert"

  3. 選擇"Node Down"

  4. 配置條件:

    • Trigger when: Node is down

    • For at least: 1 minute

  5. 配置動作:

    • 添加郵件和短信通知

  6. 點擊"Save"

第四部分:系統測試

1. 設備監控測試

powershell
 
# 測試思科設備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. 告警觸發測試

powershell
 
# 模擬高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文件:

python
 
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):
                f.write(chunk)
        
        # 安裝
        if install_args:
            subprocess.run([download_path] + install_args, check=True)
        else:
            subprocess.run([download_path], check=True)
    except Exception as e:
        print(f"安裝 {file_name} 失敗: {e}")

def configure_solarwinds():
    print("配置SolarWinds Orion...")
    # 這裏可以添加自動配置SolarWinds的代碼
    # 實際生產環境中可能需要使用SolarWinds API或CLI工具
    print("請手動完成SolarWinds的初始配置:")
    print("1. 訪問 http://localhost:8787")
    print("2. 使用admin賬户登錄")
    print("3. 完成初始嚮導")

def main():
    print("=== SolarWinds監控系統一鍵部署腳本 ===")
    
    # 1. 安裝系統更新和必要組件
    install_prerequisites()
    
    # 2. 配置SNMP服務
    configure_snmp()
    
    # 3. 下載並安裝SQL Server 2019
    sql_url = "https://go.microsoft.com/fwlink/?linkid=866662"
    download_and_install(sql_url, "SQLServer2019-SSEI-Dev.exe")
    
    # 4. 下載並安裝SolarWinds Orion
    # 注意:需要替換為實際的SolarWinds下載URL
    sw_url = "https://downloads.solarwinds.com/solarwinds/Release/Orion/2020.2.1/OrionInstaller.exe"
    download_and_install(sw_url, "OrionInstaller.exe")
    
    # 5. 配置SolarWinds
    configure_solarwinds()
    
    print("部署完成!")

if __name__ == "__main__":
    main()

使用説明

  1. 將上述Python腳本保存為deploy_solarwinds.py

  2. 以管理員身份運行PowerShell

  3. 執行以下命令運行腳本:

    powershell
     
    python deploy_solarwinds.py
  4. 腳本將自動完成大部分安裝配置,部分步驟需要手動完成

注意事項

  1. 生產環境中應使用更安全的SNMP團體字符串替代"public"

  2. 郵件和短信通知配置需要根據實際使用的服務提供商進行調整

  3. SolarWinds Orion的完整功能可能需要額外的許可證

  4. 定期備份SolarWinds配置和數據庫

  5. 確保防火牆允許SolarWinds使用的端口(如8787、17778等)

 
user avatar u_16105315 Avatar
Favorites 1 users favorite the story!
Favorites

Add a new Comments

Some HTML is okay.