Linux下的監控器之一Ganglia詳解與部署
Ganglia基礎詳解
Ganglia介紹
Ganglia是一個跨平臺可擴展的,高性能計算系統下的分布式監控系統,如集群和網格。它是基於分層設計,它使用廣泛的技術,如XML數據代表,便攜數據傳輸,RRDtool用於數據存儲和可視化。它利用精心設計的數據結構和算法實現每節點間並發非常低的。它已移植到廣泛的操作系統和處理器架構上,目前在世界各地成千上萬的集群正在使用。
Ganglia特點
具有良好的擴展性,分層架構使用與大規模服務器集群的架構
負載開銷低,支持高並發
廣泛支持各種操作系統
Ganglia組成
Ganglia框架有gmond,gmated和webfronted進程組成:
gmond:是運行在被監控節點的守護進程,負責采集本節點的上數據,同時也接受替他節點上發送過來的數據,默認監聽在8649。
gmated:運行在監控節點上的守護進程,負責定期檢查每個gmond進程並從哪裏獲取數據,然後將數據存儲在本地的RRD存儲引擎中。
webfronted:使用PHP寫成的web圖形化界面,功能從gmetad獲取數據並且讀出數據庫,通過rrdtool工具生成圖表,通過http協議顯示在終端上。
Ganglia的工作模型
node:監控單個服務器
一臺主機運行gmond進程,另一臺主機運行gmetad進程進行數據采集。
cluster:監控一個集群
主機A,B,C,D,E模型一: 主機A,B,C,D作為被監控端,運行gmont進程。 主機E作為監控端運行gmetad進程。 模型二: 主機A,B,C:被監控端 主機D:運行gmont進程,負責采集A,B,C傳送的數據,最終將數據傳送給監控節點。 主機E:監控節點 模型三: 如見下圖:
grid:監控一個網格,由多個集群服務組成
Ganglia之間的通信
gmond<–>gmond:采用UDP通信協議,並以文件格式為XDL的格式進行發送。
gmond<–>gmetad:采用TCP通信協議,並以文件格式為XML的形式進行傳送。
gmetad<–>gmetad:采用TCP通信協議,並以文件格式為XML的形式進行傳送。
通常采用單播和多播進行通信
gmond與gmond之間以多播的方式行通信(默認)。gmond向外發送數據,相鄰的gmond主機也會收到數據。
Ganglia的部署
部署結構
主機 IP 作用 Clone1 192.168.80.129 監控 Clone2 192.168.80.130 被監控
監控端部署
gmetad安裝:
提前安裝confuse,rrdtool yum源安裝: [[email protected] ~]# yum install ganglia-gmetad ganglia-web 編譯安裝gmetad: [[email protected] ~]# wget https://jaist.dl.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.7.2/ganglia-3.7.2.tar.gz [[email protected] ~]# tar -xzf ganglia-3.7.2.tar.gz [[email protected] ~]# cd ganglia-3.7.2 [[email protected] ganglia-3.7.2]# ./configure --prefix=/usr/local/ganglia --with-static-modules --enable-gexec --enable-status --with-gmetad --with-libexpat --with-libconfuse=/usr/local/confuse --with-libpcre --with-librrd=/usr/local/rrtdool --htmldir=/var/www/html/gangia [[email protected] ganglia-3.7.2]# make && make install
gmetad配置:
1. 在安裝包文件中找到gmetad.init文件 2. 將此文件復制到/etc/rc.d/init.d/gmetad [[email protected] gmetad]# cp gmetad.init /etc/rc.d/init.d/gmetad 3. 編輯/etc/rc.d/init.d/gmetad,設置GMSTA=/usr/local/ganglia/sbin/gmetad 4. 添加多播地址 [[email protected] sbin]# ip route add 239.2.11.71 dev eth0 5. 編輯配置文件 data_source "Ganglia" 192.168.80.130 //定義集群的名稱,以及集群的節點 gridname "MyGrid" //定義一個網格名稱,網格中的服務器集群由data_source定義 xml_port 8651 //定義一個接受數據的端口,默認偽8651 interactive_port 8652 //此參數定義web端獲取數據的端口, rrd_rootdir "/var/lib/ganglia/rrds" //rrd數據庫的存放路徑,默認偽/var/lib/ganglia/rrds
ganglia-web配置:
1. yum源安裝: [[email protected] ~]# yum install ganglia-web [[email protected] ~]# cp /usr/share/ganglia/* /var/www/html/ 2. 編譯安裝: [[email protected] ~]# git clone https://github.com/ganglia/ganglia-web.git [[email protected] ~]# cd ganglia-web/ [[email protected] ganglia-web]# cp -rv * /var/www/html/ganglia/ [[email protected] ganglia]# mv conf_default.php.in conf_default.php 3. 編輯conf_default.php $conf[‘gmetad_root‘] = "/var/lib/ganglia"; //ganglia-gmetad安裝目錄 $conf[‘gweb_root‘] . "/version.php"; //genglia的web根目錄 $conf[‘rrds‘] = "${conf[‘gmetad_root‘]}/rrds"; //web讀物rrd數據庫的路徑 $conf[‘dwoo_compiled_dir‘] = "${conf[‘gweb_confdir‘]}/dwoo/compiled"; //需要777權限 $conf[‘dwoo_cache_dir‘] = "${conf[‘gweb_confdir‘]}/dwoo/cache"; //需要777權限 $conf[‘rrdtool‘] = "/usr/local/rrtdool/bin/rrdtool"; //指定rrdtool的路徑 $conf[‘graphdir‘]= $conf[‘gweb_root‘] . ‘/graph.d‘; //生成圖成模板目錄 $conf[‘ganglia_ip‘] = "127.0.0.1"; //gmetad服務器的地址 $conf[‘ganglia_port‘] = 8652; //提供監控數據端口 4. 改變rrd庫的權限為777 5. 創建/var/www/html/ganglia/dwoo/下comiled目錄和cache目錄,並賦予可寫權限
被監控端部署
gmond安裝:
前提安裝confuse 1. yum安裝: [[email protected] ~]# yum install ganglia-gmond 2. 編譯安裝: [[email protected] ~]# wget https://jaist.dl.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.7.2/ganglia-3.7.2.tar.gz [[email protected] ~]# tar -xzf ganglia-3.7.2.tar.gz [[email protected] ~]# cd ganglia-3.7.2 [[email protected] confuse-2.5]# ./configure --prefix=/usr/local/ganglia --enable-gexec --enable-status --with-libconfuse=/usr/local/confuse --with-expat=/usr --with-libpcre=/usr [[email protected] confuse-2.5]# make && make install
gmond配置:
1. cp啟動文件 [[email protected] gmond]# cp gmond.init /etc/rc.d/init.d/gmond 2. 編譯啟動文件/etc/rc.d/init.d/gmond: GMSTA=/usr/local/ganglia/sbin/gmond 3. 配置多播地址: [[email protected] ganglia-3.7.2]# ip route add 239.2.11.71 dev eth0 4. 生成配置文件: [[email protected] gmond]# ./gmond -t > /etc/ganglia/gmond.conf [[email protected] gmond]# ./gmond -t > /usr/local/ganglia/etc/gmond.conf
gmond配置文件:
gmond的配置文件分為Gloabl,cluster,host,協議配置四部分組成 第一部分: globals { daemonize = yes //是否後臺運行 setuid = yes //是否設置用戶運行 user = nobody //運行程序的用戶 debug_level = 0 //調試級別 max_udp_msg_len = 1472 //最大UDP隊列長度 mute = no //是否將采集到的數據廣播到其他節點 deaf = no //是否接受其他節點發送過來的數據 allow_extra_data = yes //允許額外數據 host_dmax = 86400 //是否刪除一個節點,0表示永不刪除,非0表示不響應時間,超過這個時間系統會刷新集群節點,從而刪除此節點 host_tmax = 20 // cleanup_threshold = 300 //清理過期數據的時間 gexec = no //是否使用gexec來告知主機是否可用 send_metadata_interval = 0 //在單播通信中,新添加的節點多長時間表示一下自己的存在,0表示啟動時通知。} 第二部分:定義主機在集群中的信息cluster { name = "my cluster" //集群名稱,要與監控端data_source其中一項匹配 owner = "unspecified" //節點擁有者 latlong = "unspecified" //節點的坐標,一般不用指定 url = "unspecified" //節點的URL,一般不用指定} 第三部分:定義主機 host { location = "unspecified" //節點的物理位置,一般不用指定} 第四部分:協議配置 udp_send_channel { //udp發送通道 mcast_join = 239.2.11.71 //指定發送的多播地址,單播模式下,為host_ip,可以定義多個udp_send_channel port = 8649 //監聽的端口 ttl = 1} udp_recv_channel { //udp接受通道 mcast_join = 239.2.11.71 //指定接受的多播地址 port = 8649 //監聽的端口 bind = 239.2.11.71 //綁定地址 retry_bind = true } tcp_accept_channel { port = 8649 gzip_output = no }
結果
Linux下的監控器之一Ganglia詳解與部署