導讀 | 從系統管理員接手服務器和主機管理以來,像應用監控這樣的工具就成了他們的好幫手。其中比較有名的有Nagios、 Zabbix、 Icinga 和 Centreon。以上這些是重量級的監控工具,讓一個新手管理員來設置,並使用其中的高級特性是有些困難的。 |
本文將向你介紹 Ganglia,它是一個易於擴展的監控系統。使用它能夠實時查看 Linux 服務器和集羣(圖形化展現)中的各項性能指標。php
Ganglia 可以讓你以集羣(按服務器組)和網格(按地理位置)的方式更好地組織服務器。這樣,咱們能夠建立一個包含全部遠程主機的網格,而後將那些機器按照其它標準分組成小的集合。此外, Ganglia 的 web 頁面對移動設備進行過優化,也容許你導出 csv和 .json 格式的數據。html
咱們的測試環境包括一個安裝 Ganglia 的主節點服務器 CentOS 7 (IP 地址 192.168.0.29),和一個做爲被監控端的 Ubuntu 14.04 主機(192.168.0.32)。咱們將經過 Ganglia 的 Web 頁面來監控這臺 Ubuntu 主機。前端
下面的例子能夠給你們提供參考,CentOS7 做爲主節點,Ubuntu 做爲被監控對象。linux
安裝和配置 Gangliaios
請遵循如下步驟,在主節點服務器安裝監控工具。git
1.啓用EPEL 倉庫 ,而後安裝 Ganglia 和相關工具:github
# yum update && yum install epel-release # yum install ganglia rrdtool ganglia-gmetad ganglia-gmond ganglia-web
在上面這步隨 Ganglia 將安裝一些應用,它們的功能以下:web
2.使用 Apache 提供的基本認證功能,爲 Ganglia Web 界面(/usr/share/ganglia)配置身份認證。正則表達式
若是你想了解更多高級安全機制,請參閱 Apache 文檔的 受權與認證部分。數據庫
爲完成這個目標,咱們須要建立一個用戶名並設定一個密碼,以訪問被 Apache 保護的資源。在本例中,咱們先來建立一個叫adminganglia 的用戶名,而後給它分配一個密碼,它將被儲存在 /etc/httpd/auth.basic(能夠隨意選擇另外一個目錄 和/或 文件名, 只要 Apache 對此有讀取權限就能夠。)
# htpasswd -c /etc/httpd/auth.basic adminganglia
給 adminganglia 輸入兩次密碼完成密碼設置。
3.修改配置文件/etc/httpd/conf.d/ganglia.conf:
Alias /ganglia /usr/share/ganglia AuthType basic AuthName "Ganglia web UI" AuthBasicProvider file AuthUserFile "/etc/httpd/auth.basic" Require user adminganglia
4.編輯 /etc/ganglia/gmetad.conf:
首先,使用 gridname 指令來爲網格設置一個描述性名稱。
gridname "Home office"
而後,使用 data_source 指令,後面跟集羣名(服務器組)、輪詢時間間隔(秒)、主節點主機和被監控節點的 IP 地址:
data_source "Labs" 60 192.168.0.29:8649 # 主節點 data_source "Labs" 60 192.168.0.32 # 被監控節點
5.編輯/etc/ganglia/gmond.conf。
a) 確保集羣的配置相似下面。
cluster { name = "Labs" # gmetad.conf 中的 data_source 指令的名字 owner = "unspecified" latlong = "unspecified" url = "unspecified" }
b) 在 udp_send_chanel 中,註釋掉 mcast_join:
udp_send_channel { # mcast_join = 239.2.11.71 host = localhost port = 8649 ttl = 1 }
c) 在 udp_recv_channel 中,註釋掉 mcast_join 和 bind 部分:
udp_recv_channel { # mcast_join = 239.2.11.71 ## comment out port = 8649 # bind = 239.2.11.71 ## comment out }
保存並退出。
6.打開 8649/udp 端口,使用 SELinux 確保 php 腳本(經過 Apache 運行)可以鏈接到網絡:
# firewall-cmd --add-port=8649/udp # firewall-cmd --add-port=8649/udp --permanent # setsebool -P httpd_can_network_connect 1
7.重啓 Apache、gmetad、gmond,並確保它們啓用了「開機啓動」。
# systemctl restart httpd gmetad gmond # systemctl enable httpd gmetad httpd
至此,咱們如今可以打開 Ganglia 的 Web 頁面 http://192.168.0.29/ganglia 並用步驟 2 中設置的憑證登陸。
8.在 Ubuntu 主機上,只需安裝 Ganglia-monitor,等同於 CentOS 上的 ganglia-gmond:
$ sudo aptitude update && aptitude install ganglia-monitor
9.編輯被監控主機的 /etc/ganglia/gmond.conf 文件。與主節點主機上是相同的文件,除了被註釋掉的cluster, udp_send_channeludp_recv_channel 這裏不該被註釋:
cluster { name = "Labs" # The name in the data_source directive in gmetad.conf owner = "unspecified" latlong = "unspecified" url = "unspecified" } udp_send_channel { mcast_join = 239.2.11.71 host = localhost port = 8649 ttl = 1 } udp_recv_channel { mcast_join = 239.2.11.71 ## comment out port = 8649 bind = 239.2.11.71 ## comment out }
以後重啓服務。
$ sudo service ganglia-monitor restart
10. 刷新頁面,你將在 Home office grid / Labs cluster 中看到兩臺主機的各類統計及圖形化的展現(用下拉菜單選擇集羣,本例中爲 Labs):
使用菜單按鈕(如上指出的),你能夠獲取到每臺服務器和集羣的信息。還可使用 對比主機Compare Hosts選項卡來比較集羣中全部服務器的狀態。
可使用正則表達式選擇一組服務器,馬上就能夠看到它們性能的對比:
我最喜歡的一個特色是對移動端有友好的總結界面,能夠經過 Mobile 選項來訪問。選擇你感興趣的集羣,而後選中一個主機。
總結
本篇文章向你們介紹了 Ganglia,它是一個功能強大、擴展性很好的監控工具,主要用來監控集羣和網格。它能夠隨意安裝,便捷的組合各類功能(你甚至能夠嘗試一下官方網站提供的 Demo)。
此時,你可能會發現許多知名的 IT 或非 IT 的企業在使用 Ganglia。除了咱們在文章中說起的以外,還有不少理由這樣作,其中易用性,統計的圖形化(在名字旁附上臉部照片更清晰,不是嗎)多是最重要的緣由。
可是請不要拘泥於本篇文章,嘗試一下本身去作。若是你有任何問題,歡迎給我留言。
via: http://www.tecmint.com/install-configure-ganglia-monitoring-centos-linux/
做者:Gabriel Cánepa 譯者:ivo-wang 校對:jasminepeng