歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

lnmp環境下cacti搭建

LNMP架構安裝配置方法 /content/24599374.html
實驗過程中關閉防火牆和selinux
service iptables stop  
setenforce 0
官網下載cacti相關軟件
root@localhost file]# wgethttp://www.cacti.net/downloads/cacti-0.8.8a.tar.gz http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.5.tar.gz
安裝rrdtool采集工具
安裝rrdtool之前需要安裝相應的lib庫,如下安裝:
yum install cairo-devel libxml2-devel pango pango-devel perl-devel -y
tar xzf rrdtool-1.4.5.tar.gz;cd rrdtool-1.4.5;
./configure --prefix=/data/local/rrdtool/;make  &&make install
ln -s /data/local/rrdtool/bin/* /usr/local/bin/
安裝SNMP服務
yum install net-snmp  net-snmp-utils  -y
安裝cacti主程序
tar xzf cacti-0.8.8a.tar.gz && mv  cacti-0.8.8a    /usr/local/nginx/html/
創建cacti數據庫
service mysqld restart
mysql 進入創建數據庫:
mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.60 Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
創建數據庫
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
創建用戶並授權
mysql> grant all on cacti.* to cacti@'localhost' identified by "123456";
Query OK, 0 rows affected (0.00 sec)
刷新權限
flush privileges;
把數據導入到數據庫:
mysql -u cacti -p cacti < cacti
/cacti
.sql

配置php的數據庫連接部分,改用戶名和密碼
[root@localhost ~]# vim /usr/local/nginx/html/cacti-0.8.8a/include/config.php
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2004-2012 The Cacti Group                                 |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | as published by the Free Software Foundation; either version 2          |
 | of the License, or (at your option) any later version.                  |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDTool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 |http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/

/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;

/*
   Edit this to point to the default URL of your Cacti install
   ex: if your cacti install as athttp://serverip/cacti/ this
   would be set to /cacti/
*/
//$url_path = "/cacti/";

/* Default session name - Session name must contain alpha characters */
//$cacti_session_name = "Cacti";

?>
[root@localhost ~]# chmod -R 777 /usr/local/nginx/html/cacti/rra/ 
[root@localhost ~]# chmod -R 777 /usr/local/nginx/html/cacti/log/
重啟網站服務 service nginxd restart
添加Rrdtool抓圖任務計劃
crontab -e
*/1  * * * * /usr/bin/php /usr/local/nginx/html/cacti/poller.php >>/tmp/cacti_rrdtool.log 2 >&1
啟動smmp
[root@localhost ~]# /etc/init.d/snmpd restart
停止 snmpd:                                               [失敗]
正在啟動 snmpd:                                           [確定]
[root@localhost ~]# /etc/init.d/snmptrapd restart
停止 snmptrapd:                                           [失敗]
正在啟動 snmptrapd:                                       [確定]

浏覽器裡面查看安裝
http://192.168.72.250/cacti/install/
有界面提示進行全新安裝 安裝後添加devices graph trees,再查看devices裡面的status狀態是否為up,up才算成功,
如果一直是unkown,那麼可以
測試snmp返回數據的是否正確:
snmpwalk -v2c -c public localhost
手動抓圖後再觀察status是否為up:
/usr/bin/php /usr/local/nginx/html/cacti/poller.php
添加一個遠程主機
在遠程主機上安裝snmpd服務
yum install net-snmp net-snmp-utils -y
修改配置文件vi /etc/snmp/snmpd.conf
vi /etc/snmp/snmpd.conf,我們只需要更改:62行把他改為:
access notConfigGroup "" any noauth exact all none none
第二:我們需要更改42行為:
com2sec notConfigUser 192.168.1.16 public #注意:如果是服務器端這裡的IP要改成你要監控的遠程客戶端的IP
(其中192.168.1.16 ip 表示你允許那台服務器可以監控你。public 表示團體名)
第三:我們還要更改:86行:把#號去掉:變成如下即可
view all included .1 80
最後重啟snmpd服務ok :
service snmpd restart
如果發現監控的主機不出圖,狀態始終為unkown.那就同步下時間。
yum install -y ntpdate
ntpdate us.pool.ntp.org
然後清空掉 /usr/local/nginx/html/cacti/rra下抓取的數據
手動抓取下 /usr/bin/php /usr/local/nginx/html/cacti/poller.php
再看下 /usr/local/nginx/html/cacti/rra下 是否有遠程主機的IP開頭的文件
比如 192_168_1_17_hdd_free_100.rrd
localhost_traffic_in_35.rrd
此時應該有圖了
排錯:有圖無數據
vi /usr/local/php/php.ini
將php.ini中設置date.timezone的值為PRC,設置好以後的為:date.timezone=PRC,同時取消這一行代碼的注釋,即去掉前面的分號就可以了。
tail -f /var/log/cron
tail -f /var/spool/mail/root 即可查看最近的crontab執行情況 這裡的值有數據 Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:26 RRDsProcessed:
代表抓取成功了
注意RRA目錄下面的文件都是每隔1分鐘產的數據才算成功。


Copyright © Linux教程網 All Rights Reserved