Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ซอฟต์แวร์ >> เครื่องเสมือน

วิธีเปิดใช้งานและตั้งค่า SNMP บน VMware ESXi Host

หากต้องการ Monitor สถานะ VMware ESXi Servers ในระบบ Monitoring ต้องตั้งค่า SNMP Agent บน Hosts บทความนี้จะแสดงวิธี Enable และ Configure SNMP ใน VMware ESXi 6.7 (Guide นี้ใช้ได้กับ ESXi 5.5 ขึ้นไป)

ใน ESXi มี Built-in SNMP Agent ที่ส่งและรับ SNMP Requests และ Traps ได้ สามารถ Enable และ Configure SNMP Agent บน ESXi Hosts ได้หลายวิธี: ใช้ vCLI, PowerCLI (แต่ไม่ได้ผ่าน vSphere Client GUI)

SNMP Server ใน VMware ESXi

จาก vSphere Web Interface สามารถแค่ตรวจสอบว่า Service "SNMP server" รันอยู่ เปลี่ยน Startup Settings หรือ Stop/Start Service ไปที่ ESXi Host → Configure → Services → SNMP Server Service หยุดอยู่โดยค่าเริ่มต้น ให้ Start 它

วิธีเปิดใช้งานและตั้งค่า SNMP บน VMware ESXi Host

เปิด SSH Access บน ESXi Host และเชื่อมต่อด้วย SSH Client (ผมใช้ Windows 10 Built-in SSH Client)

ตรวจสอบ SNMP Settings ปัจจุบัน:

esxcli system snmp get

วิธีเปิดใช้งานและตั้งค่า SNMP บน VMware ESXi Host

SNMP ยังไม่ Config: Parameters ทั้งหมดว่าง และ Agent Disabled

Authentication:
Communities:
Enable: false
Engineid:
Hwsrc:
indications
Largestorage: true
Loglevel: info
Notraps:
Port: 161
Privacy:
Remoteusers:
Syscontact:
Syslocation:
Targets:
Users:
V3targets:

การตั้งค่า Parameter SNMP Agent ใน ESXi

ระบุ IP Address ของ Monitoring Server (SNMP Target), Port (Default 161 UDP) และ SNMP Community Name (ปกติ public):

esxcli system snmp set --targets=192.168.99.99@161/public

หรือตั้ง Community Name แยก:

esxcli system snmp set --communities YOUR_COMMUNITY_STRING

เพิ่มเติม สามารถระบุ Location:

esxcli system snmp set --syslocation "Allee 16, Mun, DE"

Contact Information:

esxcli system snmp set --syscontact admin@woshub.com
จากนั้น Enable SNMP Service บน ESXi Host:

esxcli system snmp set --enable true

ทดสอบ SNMP Configuration:

esxcli system snmp test

วิธีเปิดใช้งานและตั้งค่า SNMP บน VMware ESXi Host

เพื่อ Apply Settings ให้ Restart SNMP Agent:

/etc/init.d/snmpd restart

วิธีเปิดใช้งานและตั้งค่า SNMP บน VMware ESXi Host

Reset Settings ปัจจุบัน:

esxcli system snmp set –r

Disable SNMP:

esxcli system snmp set --disable true

การตั้งค่า ESXi Firewall สำหรับ SNMP Traffic

อนุญาต SNMP Traffic ใน ESXi Host Firewall ได้ 2 วิธี เพื่ออนุญาต SNMP Requests จาก Device ใดๆ ใน Network:

esxcli network firewall ruleset set --ruleset-id snmp --allowed-all true
esxcli network firewall ruleset set --ruleset-id snmp --enabled true

หรืออนุญาต Inbound Traffic จาก IP Address ของ Monitoring Server หรือ IP Subnet ที่ SNMP Servers อยู่:

esxcli network firewall ruleset set --ruleset-id snmp --allowed-all false
esxcli network firewall ruleset allowedip add --ruleset-id snmp --ip-address 192.168.100.0/24
esxcli network firewall ruleset set --ruleset-id snmp --enabled true

ตอนนี้สามารถ Monitor VMware ESXi Hosts ผ่าน SNMP ได้แล้ว

เปลี่ยน SNMP Settings บน ESXi Host ด้วย PowerCLI

หากต้องการ Config SNMP Parameters บน ESXi Hosts หลายตัวรวดเร็ว ใช้ PowerCLI Script นี้:

$ESXi = 'mun-esxi01'
$Community = 'Public'
$Target = '192.168.99.99'
$Port = '161'

# Connection to an ESXi host
Connect-VIServer -Server $sESXiHost
# Clear current SNMP settings
Get-VMHostSnmp | Set-VMHostSnmp -ReadonlyCommunity @()
# Configure SNMP parameters
Get-VMHostSnmp | Set-VMHostSnmp -Enabled:$true -AddTarget -TargetCommunity $Community -TargetHost $Target -TargetPort $Port -ReadOnlyCommunity $Community
# Display current SNMP parameters
$Cmd= Get-EsxCli -VMHost $ESXiHost
$Cmd.System.Snmp.Get()

หากมี License VMware Enterprise Plus ขั้นสูง สามารถตั้งค่า SNMP Parameters บน ESXi Hosts ผ่าน Host Profiles (Management → Host Profiles → Your Profile → SNMP Agent Configuration)

การตั้งค่า VMware ESXi SNMPv3

เราได้อภิปรายการ Enable และ Configure SNMP Agent v1 และ v2 บน ESXi Hosts แล้ว ตั้งแต่ ESXi 5.1 ใช้ Protocol Version ที่ทันสมัยกว่า: SNMP v3 ใช้คำสั่งต่อไปนี้ตั้งค่า SNMPv3 ที่ปลอดภัยกว่า

ตั้งค่า Authentication และ Encryption Protocols:

esxcli system snmp set -a MD5 -x AES128

Generate Hashes สำหรับ Authentication และ Encryption Passwords (แทนที่ authpass และ privhash ด้วย Password ของคุณ):

esxcli system snmp hash --auth-hash authpass --priv-hash privhash --raw-secret

ใช้ Hashes (authhash และ privhash) เพิ่ม User:

esxcli system snmp set -e yes -C snmp@woshub.com -u snmpuser/authhash/privhash/priv

จากนั้นระบุ SNMP Target Address:

esxcli system snmp set –v3targets 192.168.99.99@161/user/priv/trap

ตรวจสอบ SNMP Configuration แบบ Remote ด้วย Linux snmpwalk Tool:

snmpwalk -v3 -u snmpuser -l AuthPriv -a SHA -A P@ssw0rd1 -x AES-X P@ssword2 192.168.1.120