標籤:解決方案 監控 苦瓜
zabix簡介
zabbix(音同 z?bix)是一個基於WEB介面的提供分布式系統監視以及網路監視功能的企業級的開源解決方案。
- zabbix能監視各種網路參數,保證伺服器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題。
- zabbix由2部分構成,zabbix server與可選組件zabbix agent。
- zabbix server可以通過SNMP,zabbix agent,ping,連接埠監視等方法提供對遠程伺服器/網路狀態的監視,資料收集等功能,它可以運行在Linux,Solaris,HP-UX,,AIX,Free BSD,Open BSD,OS X等平台上。
實驗環境:Centos6.5
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="image" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376280wQTf.png" width="600" height="384" />
一、配置一個lamp平台
安裝php-fpm、mysql-server、httpd、php-mysql
修改php-ini設定檔
date.timezone = Asia/Shanghai
啟動mysql服務,並建立一個zabbix的資料庫,並完成授權
mysql> create database zabbix;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on zabbix.* to ‘zbxuser‘@‘localhost‘ identified by ‘zbxpass‘;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on zabbix.* to ‘zbxuser‘@‘127.0.0.1‘ identified by ‘zbxpass‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
二、安裝並配置zabbix-server
在server上安裝如下zabbix包(這裡安裝的是zabbix2.4的包,包需要在噶un放網站下載,前提配置好yum源)
# yum install zabbix-2.4.0-1.el6.x86_64.rpm zabbix-agent-2.4.0-1.el6.x86_64.rpm zabbix-get-2.4.0-1.el6.x86_64.rpm zabbix-sender-2.4.0-1.el6.x86_64.rpm zabbix-server-2.4.0-1.el6.x86_64.rpm zabbix-server-mysql-2.4.0-1.el6.x86_64.rpm zabbix-web-2.4.0-1.el6.noarch.rpm zabbix-web-mysql-2.4.0-1.el6.noarch.rpm
編譯zabbix的設定檔
1、#vim zabbix_server.conf
修改如下項
DBHost=172.16.1.1 //資料庫伺服器的IP地址
DBName=zabbix //資料庫的名稱
DBUser=zbxuser //串連資料庫伺服器的使用者名稱
DBPassword=zbxpass //串連資料庫伺服器的使用者密碼
2、為zabbix資料庫匯入基礎資訊
650) this.width=650;" title="clipboard[4]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[4]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376280Wwz7.png" width="834" height="80" />
使用命令
#mysql zabbix < schema.sql
3、啟動服務
#service httpd start
#service php-fpm start
#service zabbix-server start
4、在瀏覽器輸入172.16.1.1對zabbix服務的web頁面進行初始化
650) this.width=650;" title="clipboard[18]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[18]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376280eTS8.png" width="651" height="381" />
650) this.width=650;" title="clipboard[19]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[19]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376280xQOF.png" width="640" height="510" />
650) this.width=650;" title="clipboard[20]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[20]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376281J58F.png" width="643" height="411" />
650) this.width=650;" title="clipboard[21]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[21]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376281ZMCz.png" width="646" height="440" />
650) this.width=650;" title="clipboard[22]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[22]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376281XtKN.png" width="657" height="317" />
650) this.width=650;" title="clipboard[23]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[23]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376281Ekmk.png" width="663" height="141" />
5、為server端配置agent使其能監控自己
#vim zabbix_agent.conf
修改如下項:
Server=127.0.0.1,172.16.1.1 //允許來拉取資料的主機的IP地址
ServerActive=127.0.0.1,172.16.1.1 //主動通知來拉取資料的主機的IP地址(只有server與agent在同一主機時才有127.0.0.1)
Hostname=server.zhou.com //需與主機名稱保持一致
**************************************************
主機名稱修改方法:
#vim /etc/hosts
#vim /etc/sysconfig/network
#hostname New-HostName
****************************************************
此時server會自動將原生agent添加進去
三、建立一個獨立的agent端
安裝的包:
# yum install zabbix-2.4.0-1.el6.x86_64.rpm zabbix-agent-2.4.0-1.el6.x86_64.rpm zabbix-sender-2.4.0-1.el6.x86_64.rpm
設定檔修改內容同上
添加主機:
650) this.width=650;" title="clipboard[5]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[5]" src="http://img1.51cto.com/attachment/201410/15/8371039_14133762811WDY.png" width="868" height="335" />
四、配置zabbi-proxy代理server的
安裝的包:zabbix-2.4.0-1.el6.x86_64.rpm zabbix-proxy zabbix-proxy-mysql
編輯設定檔“
#vim /etc/zabbix/zabbix_proxy.conf
Server=172.16.1.1 //*zabbix server的ip地址或主機名稱Hostname=node2.zhou.com //*該主機名稱的配置需被zabbix server知道,並且在zabbix server前端配置時會用到LogFile=/tmp/zabbix_proxy.log //pid檔案的存放位置DBName=zabbix_proxy //*DBUser=zabbix //*DBPassword=123456 //*ConfigFrequency=60 //zabbix proxy 想伺服器檢索配置資料資訊的頻率,在被動模式下該參數將被忽略DataSenderFrequency=60 //zabbix proxy發送收集的資料給zabbix server的頻率
***上述帶‘*‘的是必須修改的***
啟動服務在,在web頁面上添加即可
五、自訂各項參數
由於在生產環境中內建的模版並不能完全滿足我們的需求,所以我們需要自己定義鍵,模版等。
1、如何自訂鍵?
修改設定檔,啟動自訂鍵這一項
UnsafeUserPaameters=1
其餘可以不用修改
在檔案/etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf中添加如下內容
UserParameter=count.line.passwd,wc -l /etc/passwd|awk ‘{print $1}‘
重啟用戶端,在命令列上測試鍵是否可用
650) this.width=650;" title="clipboard[8]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[8]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376282DBBU.png" width="665" height="100" />
**zabbix_get的用法使用zabbix_get -h
2、如何自訂模版?
如果有大量的同一類裝置,需要監控的資訊也大致類似,一個個去修改相關參數比較麻
煩,我們可以通過建立一個 template 來簡化操作。
Configuration->Host Groups->Template->Create Template
登入web介面,點擊Configuration中的Templates的Create template
需要的參數按自己的需要填寫
3、添加triggers
650) this.width=650;" title="clipboard[9]" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="clipboard[9]" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376282k1bK.png" width="635" height="285" />
****添加Name,自己選定item ,定義警示範圍Function 設定值
4、添加使用者,並賦予相應的許可權:
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="image" src="http://img1.51cto.com/attachment/201410/15/8371039_14133762825YiT.png" width="647" height="71" />
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="image" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376282UgAF.png" width="601" height="541" />
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="image" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376282btxh.png" width="603" height="398" />
**這裡的收家人可以是多個,警示層級可以自己選擇(可多選),Type可以自己定義
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="image" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376283uAJO.png" width="584" height="444" />
**這裡需要特別注意的是如果使用者沒有相應的許可權會導致警示時的郵件我要發送達
5、定義media
Media,即警示方式,Zabbix 可以提供四類 Media:Email/SMS/Jabber/Script,通過
Administrator->Media Type 來修改或新增警示方式
Email 方式最常用的,填入相關的 SMTP 資訊,即可通過郵件方式發送警示。
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="image" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376283xO3F.png" width="606" height="74" />
650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px" border="0" alt="image" src="http://img1.51cto.com/attachment/201410/15/8371039_1413376283XzA0.png" width="596" height="256" />
Zabbix-Proxy-agent實現web監控