歡迎您光臨本站 註冊首頁

Ganglia匯總監控搭建和配置詳解

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

linuxidc.com和linuxso.com與其他複製粘貼的編輯,我作為一個開源世界的愛好者和貢獻者,本著開源的精神,並不反對你們轉載我的文章,既然寫出來就是想與大家分享和交流知識.但是,希望你們也能本著開源的精神,在轉載的時候寫明原作者和出處,請不要將版權寫上來源是Linux公社,即使是Linux的GPL協議也是有版權保護的.我相信你們不會把Linux kernel源代碼寫上來源是Linux公社,那為何對於其他內容就執行雙重標準呢?
#---------------------------------
Ganglia是加州伯克利大學千禧計劃的其中一個開源項目,以BSD協議分發.是一個集群匯總監控用的的軟體,和很多人熟知的Cacti不同,cacti是詳細監控集群中每台伺服器的運行狀態,而Ganglia是將集群中的伺服器數據進行匯總然後監控.有時通過cacti或者zabbix看不出來的集群總體負載問題,卻能夠在Ganglia中體現,其集群的熵圖我個人認為是個挺亮點的東西,一眼就明確集群的負載狀況.中文翻譯叫神經中樞,一目了然,言簡意賅.
以下內容分為3個部分,ganglia的編譯和初始配置,web展現的部署,分組監控的配置方法.
一、Ganglia的編譯和配置
1.Ganglia基本概念ganglia分為伺服器端和客戶端,編譯後文件名是gmetad和gmond,其中gmetad是伺服器端,gmond是客戶端,伺服器端只有一個,而被監控伺服器均安裝客戶端.很有意思的是,Ganglia採用Internet IPv4 類D地址中的的組播進行數據請求.我猜可能主要是為了實現一對多節省帶寬的需要.其實現原理應該是gmetad發送一個請求到一個組播地址,由於是組播地址,gmetad只需發送一次請求包即可完成對所有gmond的輪詢.(如果是單播,則Ganglia需要向每台伺服器均發送一次輪詢請求,這樣的話,集群數量多了,主伺服器光發送就會佔用不小的帶寬.而Ganglia本身是為大規模集群所做的HPC而生的,如果佔用很高的帶寬和佔用很大量的CPU資源去處理網路數據就不符合其設計理念了.)然後gmond通過這個請求將採集到的數據返回給gmetad,gmetad將數據保存在rrd資料庫中,然後通過web界面繪圖展示.


2.Ganglia編譯編譯其實有點複雜,依賴的東西比較多,主要有rrdtool,這個用過cacti應該不陌生;expat;confuse;python;apr開發包;PCRE.
ganglia編譯分為兩種情況,伺服器端和客戶端.
我也不說那麼複雜了,直接給腳本,複製粘貼就行了.前提是你已經編譯安裝了rrdtool到/opt/rrdtool文件夾,如果是別的,自行修改腳本路徑就好了.
server端腳本
#!/bin/sh
yum install -y expat expat-devel pcre pcre-devel
wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
tar zxf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure;make;make install
cd ..
wget http://download.savannah.gnu.org/releases/confuse/confuse-2.7.tar.gz
tar zxf confuse-2.7.tar.gz
cd confuse-2.7
./configure CFLAGS=-fPIC --disable-nls ;make;make install
cd ..
wget http://downloads.sourceforge.net/project/ganglia/ganglia monitoring core/3.3.1/ganglia-3.3.1.tar.gz
tar zxf ganglia-3.3.1.tar.gz
cd ganglia-3.3.1
#server
./configure --prefix=/opt/modules/ganglia --with-static-modules --enable-gexec --enable-status --with-gmetad --with-python=/usr --with-librrd=/opt/rrdtool-1.4.5 --with-libexpat=/usr --with-libconfuse=/usr/local --with-libpcre=/usr/local
#client
#./configure --prefix=/opt/modules/ganglia --enable-gexec --enable-status --with-python=/usr --with-libapr=/usr/local/apr/bin/apr-1-config --with-libconfuse=/usr/local --with-libexpat=/usr --with-libpcre=/usr
make; make install
cd gmetad
cp gmetad.conf /opt/modules/ganglia/etc/
cp gmetad.init /etc/init.d/gmetad
sed -i "s/^GMOND=\/usr\/sbin\/gmetad/GMOND=\/opt\/modules\/ganglia\/sbin\/gmetad/g" /etc/init.d/gmetad
chkconfig --add gmetad
ip route add 239.2.11.71 dev eth1
service gmetad start
由於我安裝在/opt/modules/ganglia下面,用sed替換掉啟動文件gmetad中的啟動項.路由需要加上,也就是ip route,我指向到了內網的網卡上.gmond同樣這樣做路由.


客戶端
#!/bin/sh
yum install -y expat expat-devel pcre pcre-devel
wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
tar zxf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure;make;make install
cd ..
wget http://download.savannah.gnu.org/releases/confuse/confuse-2.7.tar.gz
tar zxf confuse-2.7.tar.gz
cd confuse-2.7
./configure CFLAGS=-fPIC --disable-nls ;make;make install
cd ..
wget http://downloads.sourceforge.net/project/ganglia/ganglia monitoring core/3.3.1/ganglia-3.3.1.tar.gz
tar zxf ganglia-3.3.1.tar.gz
cd ganglia-3.3.1
#server
#./configure --prefix=/opt/modules/ganglia --with-static-modules --enable-gexec --enable-status --with-gmetad --with-python=/usr --with-librrd=/opt/rrdtool-1.4.5 --with-libexpat=/usr --with-libconfuse=/usr/local --with-libpcre=/usr/local
#client
./configure --prefix=/opt/modules/ganglia --enable-gexec --enable-status --with-python=/usr --with-libapr=/usr/local/apr/bin/apr-1-config --with-libconfuse=/usr/local --with-libexpat=/usr --with-libpcre=/usr
make; make install
cd gmond
./gmond -t > /opt/modules/ganglia/etc/gmond.conf
cp gmond.init /etc/init.d/gmond
sed -i "s/^GMOND=\/usr\/sbin\/gmond/GMOND=\/opt\/modules\/ganglia\/sbin\/gmond/g" /etc/init.d/gmond
chkconfig --add gmond
ip route add 239.2.11.71 dev eth1
service gmond start
客戶端是不需要rrdtool的,且客戶端的配置文件是需要用一個命令生成的.
伺服器只裝一個,客戶端用腳本分發下去各自安裝就好了.
二、web展現部分的部署就是基本的nginx,php環境,所有的php文件在ganglia源文件路徑下的web文件夾下.進去SRC目錄,把web文件夾整個複製出來,再把nginx指向到那個文件夾就可以了.
第一次訪問web界面可能會報錯,需要修改幾個文件到正確指向上,一個是可以看一下我的diff
[root@portal-lc-209 html]# diff conf_default.php conf_default.php.in


29c29
< $conf['gmetad_root'] = "/opt/modules/ganglia/html";
---
> $conf['gmetad_root'] = "@varstatedir@/ganglia";
46c46
< $conf['rrdtool'] = "/opt/rrdtool-1.4.5/bin/rrdtool";
---
> $conf['rrdtool'] = "/usr/bin/rrdtool";
好像還有幾個文件需要修改,但是時間太久記不清了,可能是eval_conf.php和header.php,按照報錯提示修改就好了.沒有太難的東西.
三、集群的分組部署.
網上Ganglia講安裝配置的文章很多,但是講分組配置的很少.其實這個很重要,默認配置下,Ganglia會把所有東西放在一個Grid裡面,也就是一個網格.大的集群,不分組.但是真實的伺服器集群有各種功能,每個群分管不同的事務,全放一起就太亂了.也不好識別,需要分組使用.
其實Ganglia的分組很簡單,就是分埠,不同的組配置不同的監聽埠就完事了.我的gmetad.conf是這樣配置的.gmetaddata_source "Namenode" 192.168.1.28:8653
data_source "Datanode" 192.168.1.27:8649
data_source "
Portal" 192.168.1.43:8650
data_source "Collector" 192.168.1.35:8651
data_source "DB" 192.168.1.51:8652

gridname "Hadoop"
rrd_rootdir "/opt/modules/ganglia/html/rrds"
#配置rrd數據保存文件的路徑,給web界面用的,這個是固定的,最好放在web文件夾下,並賦予正確的許可權
case_sensitive_hostnames 0
數據來源有5個,這5個分別是每個組的組長,相當於一道杠.但是組長是不需要配置gmetad的,除非你要做多級組播收集數據.每個組長只需要分配不同的埠號就可以了.你可能會問,IP不一樣,埠一樣不行嗎?不行,這個IP是單播IP,相當於一個路由指向,而Ganglia實際的數據傳輸是在多播IP上進行的,而多播IP只有一個.在客戶端配置,如果你需要多級gmetad,可以配多個多播IP.


客戶端配置就比較複雜一些了.我只貼上需要修改的部分,其他都是默認就可以了gmondcluster {
name = "
Portal"
#對應gmetad中的Portal,名稱一定要寫對.
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
/* Feel free to specify as many udp_send_channels as you like. Gmond
used to only support having a single channel */
udp_send_channel {
#bind_hostname = yes # Highly recommended, soon to be default.
# This option tells gmond to use a source address
# that resolves to the machine's hostname. Without
# this, the metrics may appear to come from any
# interface and the DNS names associated with
# those IPs will be used to create the RRDs.
mcast_join = 239.2.11.71
port =
8650
#gmetad中的Portal所分配的埠號.
ttl = 1
}

/* You can specify as many udp_recv_channels as you like as well. */
udp_recv_channel {
mcast_join = 239.2.11.71
port = 8650
bind = 239.2.11.71
}

/* You can specify as many tcp_accept_channels as you like to share
an xml description of the state of the cluster */
tcp_accept_channel {
port = 8650
}
紅色部分就是Portal小組的埠,從gmetad.conf中可以看到,Portal小組屬於8650埠,那麼相應的在gmond中,也要將udp和tcp埠寫為8650.


如果是另外一個組的,就寫上在gmetad中配置的那個埠.當然,你可以把這個埠號想像為小組的代號.可能更好理解一些.
再加上另外一個組的成員gmond就更容易理解了cluster {
name = "
DB"
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}

/* The host section describes attributes of the host, like the location */
host {
location = "unspecified"
}

/* Feel free to specify as many udp_send_channels as you like. Gmond
used to only support having a single channel */
udp_send_channel {
#bind_hostname = yes # Highly recommended, soon to be default.
# This option tells gmond to use a source address
# that resolves to the machine's hostname. Without
# this, the metrics may appear to come from any
# interface and the DNS names associated with
# those IPs will be used to create the RRDs.
mcast_join = 239.2.11.71
port = 8652
ttl = 1
}

/* You can specify as many udp_recv_channels as you like as well. */
udp_recv_channel {
mcast_join = 239.2.11.71
port = 8652
bind = 239.2.11.71
}

/* You can specify as many tcp_accept_channels as you like to share
an xml description of the state of the cluster */
tcp_accept_channel {
port = 8652
}
紅色對紅色,藍色對藍色.一目了然.
附監控效果圖:
40台伺服器,228顆CPU,共計900G內存,網路流量峰值總計300M位元組左右.



Heatmap熵圖,某集群總體負載情況.
匯總監控Ganglia就是這樣了.


[火星人 ] Ganglia匯總監控搭建和配置詳解已經有734次圍觀

http://coctec.com/docs/linux/show-post-47706.html