Linux安裝Cacti

一、環境準備

             1、安裝epel擴展源


[root@cacti ~]# yum install -y epel-release

             2、搭建lamp環境

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@cacti ~]# yum install -y  httpd php php-mysql mysql mysql-server mysql-devel php-gd  libjpeg libjpeg-devel libpng-devel
[root@cacti ~]# /etc/init.d/httpd start
正在啓動 httpd:                                           [確定]
[root@cacti ~]# /etc/init.d/mysqld start
初始化 MySQL 數據庫: Installing MySQL system tables...
OK
Filling help tables...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
 
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h cacti password 'new-password'
 
Alternatively you can run:
/usr/bin/mysql_secure_installation
 
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
 
See the manual for more instructions.
 
You can start the MySQL daemon with:
cd /usr /usr/bin/mysqld_safe &
 
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the /usr/bin/mysqlbug script!
 
                                                           [確定]
正在啓動 mysqld:                                          [確定]


3、安裝cacti監控主機

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@cacti ~]# yum install -y cacti  net-snmp  net-snmp-utils  rrdtool net-snmp-devel net-snmp-libs lm-sensors php-xml zlib libpng freetype cairo-devel pango-devel gd
 
[root@cacti ~]# /etc/init.d/snmpd start
正在啓動 snmpd:                                           [確定]
[root@cacti ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution
 
Copyright (c) 2000, 2013, 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> create database cacti;
 
mysql> grant all on cacti.* to 'cactiuser'@'localhost' identified by 'cactiuser';
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
[root@cacti ~]# mysql -u root cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql
[root@cacti ~]# vim /usr/share/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;
 
[root@cacti ~]# vim /etc/httpd/conf.d/cacti.conf
Deny from all 修改爲 Allow from all
[root@cacti ~]# /etc/init.d/httpd restart
停止 httpd:                                               [確定]
正在啓動 httpd:                                           [確定]

     

4、通過瀏覽器訪問

               如果訪問不了,請檢查主機的iptables和selinux

wKiom1V8MzeiPSGSAAPeoggd1E4262.jpg

                                         圖:一

wKioL1V8NVGhFx3aAAHTyQpC2Tk897.jpg

圖:二

wKioL1V8NYugxMJzAATOjCCu5jE500.jpg

圖:三

              到了登陸,默認的賬號爲admin,密碼爲admin

wKioL1V8NjHi1b0yAAFLckhZxvo091.jpg

圖:四

              登陸之後,系統會強制用戶更改密碼

wKiom1V8NN3gaoNVAAGA7v5oHr0897.jpg

圖:五

wKioL1V8Nt_SRyb9AALBUZ5FwYI217.jpg

圖:六

             點擊graphs-Default Tree-Host Localhost,進入系統監控界面

wKioL1V8N5mzFt3uAAMwQcF4P44338.jpg

圖:七

              我們看到監控界面,沒有出圖,設置一下出圖

1
2
3
4
5
6
7
8
9
10
[root@cacti ~]# /usr/bin/php /usr/share/cacti/poller.php 
OK u:0.00 s:0.00 r:0.00
OK u:0.00 s:0.00 r:0.01
OK u:0.00 s:0.00 r:0.03
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.08
06/13/2015 09:59:49 PM - SYSTEM STATS: Time:0.1974 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
[root@cacti ~]# crontab -e
# 讓命令每5分鐘執行一次
*/5 * * * * /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

              我們在刷新一下,圖就出來了

wKioL1V8OjTQRs83AAWnKWuHCdM963.jpg

圖:八

             數據需要等待一會兒,才能出來

wKiom1V8OpPRL2inAASVMdQMKto471.jpg




            接下來我們添加被監控的主機

1
2
3
4
5
6
7
8
9
10
11
12
13
# 在被監控的主機上安裝
[root@rsa ~]# yum install -y net-snmp lm_sensors
[root@rsa ~]# vim /etc/snmp/snmpd.conf
 
#syslocation Unknown (edit /etc/snmp/snmpd.conf)
syslocation 192.168.1.118
 
#       group          context sec.model sec.level prefix read   write  notif
access  notConfigGroup ""      any       noauth    exact  all none none
 
view all    included  .1                               80    去掉註釋符“#”
[root@rsa ~]# /etc/init.d/snmpd start
正在啓動 snmpd:                                           [確定]

           依次點擊console -> Devices -> add,添加主機

wKioL1V8PnzgxYrwAAPqpjMlnrk408.jpg


               開始添加被監控主機的信息,填寫完畢,點擊Create

wKioL1V8ZCvQcUXcAAdoOgWakeg875.jpg

              

              創建完畢,看是否通信正常,創建完主機,創建要監控的項目點擊 Create Graphs for this Host,

wKioL1V8ZM-gh-q9AAgmwloP-0E215.jpg



              根據需要,去選擇要監控的項目

wKiom1V8Y5DjCHuqAAYpa7QzyvE198.jpg


              監控項目添加完畢,將主機添加到監控主幹線上,點擊左側Graph Trees

wKiom1V8Y-zSqBcEAAXZg1tgOhs039.jpg


               點擊Add,添加被監控的主機

wKioL1V8Zo7h-UX9AANenuKwZ4E322.jpg



              類型選擇Host,再選擇要添加的主機

wKiom1V8ZQ7QZAziAAP2FZOJDnE426.jpg


             添加完畢,點擊Save

wKioL1V8ZwbQjS8DAANMx1asnV0862.jpg


              到主界面查看,是否添加成功,最好在監控服務器上刷新一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@cacti ~]# /usr/bin/php /usr/share/cacti/poller.php --force
OK u:0.00 s:0.00 r:0.00
OK u:0.00 s:0.00 r:0.01
OK u:0.00 s:0.00 r:0.03
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.08
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.09
OK u:0.00 s:0.00 r:0.10
06/13/2015 05:16:53 PM - SYSTEM STATS: Time:0.2109 Method:cmd.php Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:20 RRDsProcessed:17


wKiom1V8ZdnS8_09AAXT9mV_92I511.jpg




cacti監控主機執行/usr/bin/php /usr/share/cacti/poller.php --force報錯解決

wKioL1Zz0G6g4iXTAABIvZPtDzo585.png


解決方法:

wKiom1Zz0NqRm6P2AAAnpC0hU1k251.png

現在再次執行就不會報錯了

wKiom1Zz0TKDv2zGAAAqgUDUp8s280.png


如果報這個錯

wKioL1Zz0dfjbaHXAACeuIbpXr8161.png

解決方法:wKioL1Zz0huxfgKqAAAvb0kmT_w385.png


cacti檢測找不到網卡解決方法:wKiom1Zz0oHCTr1bAABSFyZ5uSM472.png

功夫不負有心人,終於各種測試,找到了昨晚試驗沒出現的網卡;
方法如下:

前面的所有步驟和銘哥論壇帖子一樣。web裏面的配置也一樣。後面找到的配置不需要修改;(按照配置修改後會提示snmp error錯誤)
只需要在客戶機(你要監控的機器)修改配置文件:
[root@localhost ~]# vi /etc/snmp/snmpd.conf 


view    systemview    included   .1.3.6.1.2.1.1
修改爲:
view    systemview    included   .1.3.6.1.2.1

然後重啓snmpd服務;
[root@localhost ~]# /etc/init.d/snmpd restart

在web監控裏面添加
113315lz2z2ezplwf2805m.jpg 


類型選擇Graph Types: SNMP - Interface Statistics 就看到你客戶機的網卡了。點擊create。保存。
113415c55ce9l7x1xx79nl.jpg 



Graphs中就可以看到添加的網卡流量信息了;
113539mrbbj5vkyzggnbvh.jpg 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章