Nov 23, 2007
ONIX-VMHA 0.9 Beta is now availability
What is VMHA?
It is a High Availability package for VMware ESX 2.x,
It supports when one ESX host is dies, another ESX member will Take-over and Power-on all VM in 3 minute.
VMHA discussion In VMware Communities
How it works?
It detect the heartbeat between 2 ESX member and use ESX functions to control vm status.
View Demo
Benefits:
For the most mission critical applications high availability, we use middle-ware
such as Microsoft and Veritas clustering software to bind two redundant servers into a hot-standby pair.
VMware supports 3 types for Clustering:
- Cluster in a Box
- Cluster Across Boxes
- Physical to Virtual Clustering
There are using same clustering software as physical to physical machine clustering.
Thus it reduced Hardware cost allows implementation of HA,
but it still must at least double licenses for OS and Application.
The VMHA is a Physical ESX level cluster, it bind two redundant ESX servers into a hot-standby pair.
When ESX Server 1 is down, the ESX Server 2 will take-over all VMs on ESX Server1.
You only spend the VMs Power-on time.
Download:
Free for Trial, download ONIX-VMHA 0.9 beta version from here.
Document:
ONIX-VMHA Installation Guide (HTML | PDF)
Feedback:
If you have any questions about this program or have it up and running, we would like to hear from you:
please send e-mail to cmliu86@gmail.com
以MRTG建立集中化的主機系統負載監控
2005/07/05 by ONIX
Multi Router Traffic Grapher (MRTG)為一個使用甚廣的網路流量統計軟體,它能即時的繪出網路流量的統計圖。
目前網路上普遍使用 此一軟體做為該單位之流量統計工具,因為 MRTG 是透過 SNMP 協定來監控流量的。
所以,所有的 MRTG 所偵測的裝置都必須符合SNMP 的協定。
MRTG 就是藉由 SNMP 這個協定來取得相關的資訊以製作圖表的, 但目前以MRTG + SNMP只能偵測到網路流量,
而我們的主題重點放在主機系統負載之應用, 我們的系統跨各種平台, 必須撰寫不同的script來偵測主機負載,
且必須在各台主機裝MRTG, 所以我們用另一種方式來達成偵測主機負載, 不須在各台主機裝MRTG, 集中在一個web 畫面上即可瞭解個台主機的使用狀況。
一. 安裝MRTG Server
在一台LinuxServer上安裝MRTG及Apache, 做為以後集中管理的Server。 MRTG安裝及設定在此不贅述, 網路上很多相關資料, 請自行參考。
二. MRTG偵測主機負載的原理
原本MRTG是運行在SNMP之上, 所有的 MRTG 所偵測的裝置都必須符合 SNMP 的協定,但SNMP協定複雜, 一般人難以理解, 所以我自己寫了一些Agent (目前以開發for Linux, AIX, Solaris), 用另一種方式來達成:
我們只要掌握一個重點,在 mrtg 這個程式中,其實他總共需要要求四個數據(前兩個用來作圖,後兩個提供相關資訊,基本上,繪圖只會用到前兩個數據),
因此,你可以隨意製作 MRTG 的圖表,只要你能提供兩個數字給 mrtg 即可製圖。我們來看一下簡單的agent範例(以AIX為例) :
Linux 偵測 CPU 負載量時,需要使用到額外的外掛程式 sysstat
下載並安裝 sysstat-4.0.2-1.i386.rpm
rpm -ivh sysstat-4.0.2-1.i386.rpm
#測試 sar 指令 , 每秒鐘一次, 偵測5次
# sar 1 5
AIX DB2_SVR 2 5 0037946E4C00 07/06/05
System Configuration: lcpu=2
15:40:28 %usr %sys %wio %idle
15:40:29 0 0 0 100
15:40:30 2 0 0 98
15:40:31 0 0 0 100
15:40:32 0 1 0 99
15:40:33 0 0 0 100
Average 0 0 0 99
#
#撰寫偵測CPU使用率script
---Begin of file -----------------------------------------
#!/bin/sh
cpu_usr=`/usr/bin/sar -u 1 3 | grep Average | awk '{print $2}'`
cpu_sys=`/usr/bin/sar -u 1 3 | grep Average | awk '{print $3}'`
cpu_wio=`/usr/bin/sar -u 1 3 | grep Average | awk '{print $4}'`
cpu_usage=`echo "$cpu_usr+$cpu_sys"|bc`
uptime=`/usr/bin/uptime | awk '{print $3 "" $4 "" $5}'`
# ## 列出四個數據(前兩個一定要為數字)###
echo $cpu_usage #第一個值對應於MRTG的IN
echo $cpu_wio #第一個值對應於MRTG的OUT
echo $uptime #主機開機時間
echo "DB2_SVR" #Hostname
---End of file-----------------------------------------
存成mrtg.cpu.linux
# 設定執行權限, 測試輸出是否正確
# chmod 755 mrtg.cpu.aix
#./mrtg.cpu.aix
21.0
5.0
35days,2:26
DB2_SVR
#
編輯MRTG參數檔
# vi /mrtg/cfg/ondemand.cpu.cfg
---------- Begin Of File ----------
### Global Config Options
WorkDir: /var/www/html/mrtg/DB2_SVR# MRTG圖型的輸出目錄
Options[_]: growright #以右而左繪圖
EnableIPv6: no
#################################################################
Target[cpu]: `/mrtg/output/mrtg.cpu.aix` # 我們剛剛寫的程式
MaxBytes[cpu]: 100
Options[cpu]: gauge,growright,nopercent
YLegend[cpu]: CPU loading (%) # Y軸顯示的說明
ShortLegend[cpu]: % # 顯示的計量單位
LegendI[cpu]: sys+usr%: # 第一個接收的值
LegendO[cpu]: wait I/O%: # 第二個接收的值
Title[cpu]: CPU Utilization
PageTop[cpu]: <H1>CPU Utilization - DB2_Srv</H1>
<TABLE>
<TR><TD>System:</TD><TD>DB2_Srv</TD></TR>
</TABLE>
---------- End Of File ----------
Target[裝置名稱]:
Target[ondemand.cpu]:`/mrtg/output/mrtg.cpu.aix`
後面接的是一個自訂的加掛的可執行檔案,這個檔案執行之後,會顯示四個數據,這樣就可以繪圖了。
MaxBytes[vbird.adsldns.org_2]: 1250000
後面的數字代表資料監測時,最大的傳送速率,使用 bytes,所以 10Mbps 則為 1.25MBytes,大約是 1250000 Bytes。用到這個數字的時候是在你的圖表下方,每一個說明後面的(xx%)計算時用到的。
MaxBytes[vbird.adsldns.org_3]: 100
如果你的資料並不是 Bytes 時,例如監測 CPU 負載率時,那這個數值就需要改變
Options[裝置名稱]:
Options[vbird.adsldns.org_2]: growright, bits (常用在網路流量中)
Options[vbird.adsldns.org_3]: growright, nopercent, gauge (常用在CPU負載中)
growright:將資料隨時間變化的順序以右而左繪圖;
bits:資料單位為 bits;
nopercent:在圖下方的說明文字中,不顯示百分比;
gauge:圖表的上限固定!
開始繪圖 :
# 第一次要執行三次以上,前幾次會有錯誤訊息,不須理會
# /usr/local/mrtg-2/bin/mrtg /mrtg/cfg/ondemand.cpu.cfg
#看cfg file中指定的WorkDir是否有輸出, 有的話表設定正確, 將上述指令加入crontab
*/5 * * * */usr/local/mrtg-2/bin/mrtg /mrtg/cfg/ondemand.cpu.cfg> /dev/null 2>&1
寫到這邊大家不知有沒發覺, MRTG Config File只能在本機,
意即每台要監控的Server都要自己是MRTG Server,
所以我寫了個小程式, 能夠透過 TCP/IP 傳送 資料到Server, 達成集中管理的目地…
下載
# mkdir /mrtg
# cd /mrtg
# tar xvf onix-cleint.tar
# cd scripts
# ls
------ agent 下為先寫好之script, AIX, Solaris, Linux Platform可套用------
mrtg.cpu.aix
mrtg.cpu.solaris
mrtg.io.linux
mrtg.mem.aix
mrtg.mem.solaris
mrtg.net.linux
mrtg.cpu.linux
mrtg.io.aix
mrtg.io.solaris
mrtg.mem.linux
mrtg.net.aix
mrtg.net.solaris
------ 其中client目錄下 mrtgclt.class 為將資料送至 Server端之程式 ------
# java mrtgclt
ONIX socket agent for MRTG, version 1.0
Usage: mrtgclt server cfg_location LegendO LegendI Uptime Clientname
------需輸入5個值, 分別為:
------mrtgclt <Server端IP> <output_file路徑檔名> <In-Value> <Out-Value> <Uptime> <Client-Name>
# 以上內容以包含在各script中, 如果script 不需修改, 可直接套用
# 所以我們直接加入crontab
0,10,15,20,25,30,35,40,45,50,55 * * * * /mrtg/mrtg.cpu.aix 10.20.9.250 /mrtg/output/ondemand.cpu ondemand
# 這指令表示會收集cpu資訊後, 送至10.20.9.250 主機上存成/mrtg/output/ondemand.cpu ,
# client-name為ondemand
以後每台要監控的伺服器均如此設定, 請選擇正確平台的agent, script可能要依各個環境不同做一點小修改
請自行從scripts中copy出來修改
2.下載及安裝 Server 端套件 (必需有Java Runtime)
安裝在選定的那台MRTG Server 下載
[root@localhost]]# mkdir /mrtg
[root@localhost]]# cd /mrtg
[root@localhost mrtg]# tar xvf onix-server
[root@localhost mrtg]]# ls -l
agent_sample
bin cfg
client
output
3. 在MRTG Server上先啟動 Socket 的Listener, 等待接收client送來的資料
[root@localhost mrtg]]# cd bin
[root@localhost bin]]# java mrtgsvr&
ONIX socket Server for MRTG version 1.1
Listening for port 1388……
[root@localhost bin]]#
可以在 /etc/rc.local 中加入
cd /mrtg/bin
java mrtgsvr&
cd /
以後開機就會自動啟動了
4. 編輯Server上的MRTG參數檔
對應到每個client端的agent
# vi /mrtg/cfg/ondemand.cpu.cfg
---------- Begin Of File ----------
### Global Config Options
WorkDir: /var/www/html/mrtg/ondemand # MRTG圖型的輸出目錄, 需事先create
Options[_]: growright # 以右而左繪圖
EnableIPv6: no
#################################################################
Target[cpu]: `/mrtg/output/ondemand.cpu` # 由client傳送過來的檔案
MaxBytes[cpu]: 100
Options[cpu]: gauge,growright,nopercent
YLegend[cpu]: CPU loading (%) # Y軸顯示的說明
ShortLegend[cpu]: % # 顯示的計量單位
LegendI[cpu]: sys+usr%: # 第一個接收的值
LegendO[cpu]: wait I/O%: # 第二個接收的值
Title[cpu]: CPU Utilization
PageTop[cpu]: <H1>CPU Utilizationd</H1>
<TABLE>
<TR><TD>System:</TD><TD>CPU</TD></TR>
</TABLE>
---------- End Of File ----------
5. 開始繪圖
# 將上述指令加入crontab, 每5分鐘繪圖一次
*/5 * * * */usr/local/mrtg-2/bin/mrtg /mrtg/cfg/ondemand.cpu.cfg> /dev/null 2>&1
# 製作 Index 檔: 因我們同一部主機可能收及包含CPU, Memory, I/O…等資訊, MRTG提供一個工具可將數個
# config 做成一個index.html
# cd /mrtg/cfg
# indexmaker –output=/var/www/html/mrtg/ondemand/index.htmlondemand.cpu.cfg ondemand.mem.cfg …
6. 查看結果
開啟Browser, 輸入 MRTG Server的IP
這就是剛建立的Index Page, 每個項目還可以再點進去
參考資料:
Linux 網路實作經典之高手究極篇 - 高健智、賴阿福 - 知城出版社
