#修改配置
[iyunv@localhost ~]# vi /etc/snmp/snmpd.conf
# First, map the community name "public" into a "security name"
# sec.name source community
#com2sec notConfigUser default public
#或者关闭防火墙
[iyunv@localhost nrpe-2.15]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
#SELINUX=permissive
SELINUX=disabled #设置为disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
"/etc/selinux/config" 11L, 467C written
#启动snmp服务
[iyunv@localhost ~]# service snmpd start
[iyunv@localhost ~]# chkconfig snmpd on
#重启snmpd服务
[iyunv@localhost ~]# service snmpd restart
Stopping snmpd: [ OK ]
Starting snmpd: [ OK ]
#测试snmp 192.168.3.131
[iyunv@localhost ~]# snmpwalk -v 1 192.168.3.131 -c cacti123 system
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1166731) 3:14:27.31
SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain
SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for managing TCP implementations
SNMPv2-MIB::sysORDescr.3 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.5 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORDescr.6 = STRING: The SNMP Management Architecture MIB.
SNMPv2-MIB::sysORDescr.7 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.8 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (4) 0:00:00.04
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (4) 0:00:00.04
#测试snmpd 192.168.3.153,没有成功。经查原因是192.168.3.153上防火墙的问题
[iyunv@localhost ~]# snmpwalk -v 1 192.168.3.153 -c cacti123 system
Timeout: No Response from 192.168.3.153
#虚拟机192.168.3.153上查看防火墙状态
[iyunv@localhost ~]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
Chain RH-Firewall-1-INPUT (2 references)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255
3 ACCEPT esp -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT ah -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT udp -- 0.0.0.0/0 224.0.0.251 udp dpt:5353
6 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:631
7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:631
8 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
9 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
10 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:1158
11 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:1158
12 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:1521
13 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:1521
14 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5501
15 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:5501
16 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
#虚拟机上192.168.3.153停用防火墙
[iyunv@localhost ~]# service iptables stop
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
[iyunv@localhost ~]# /etc/init.d/iptables status
Firewall is stopped.
#回到192.168.3.133上,测试snmp 192.168.3.153
[iyunv@localhost ~]# snmpwalk -v 1 192.168.3.153 -c cacti123 system
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (79336) 0:13:13.36
SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain
SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (3) 0:00:00.03
SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for managing TCP implementations
SNMPv2-MIB::sysORDescr.3 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.5 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORDescr.6 = STRING: The SNMP Management Architecture MIB.
SNMPv2-MIB::sysORDescr.7 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.8 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (3) 0:00:00.03
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (3) 0:00:00.03
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (3) 0:00:00.03
#安装rrdtool
配安装源
[iyunv@localhost ~]# cd /etc/yum.repos.d/
[iyunv@localhost yum.repos.d]# vi CentOS-Base.repo
在文件的末尾,添加
--------------------------------
#20130128 insert
[dag]
name=Dag RPM Repostory for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
--------------------------------
这样就可以用yum来安装了。这样就能一下安装相关的依赖包等内容了。
[iyunv@localhost mysql]# cd /var/www/html/cacti
[iyunv@localhost cacti]# cd cacti-0.8.8f/
[iyunv@localhost cacti-0.8.8f]# /usr/bin/mysql -u root -p cacti <cacti.sql
Enter password:
#登录mysql
[iyunv@localhost cacti-0.8.8f]# /usr/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.95 Source distribution
Copyright (c) 2000, 2011, 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> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cacti123';
Query OK, 0 rows affected (0.00 sec)
[iyunv@localhost include]# /usr/bin/php /var/www/html/cacti/poller.php --force
OK u:0.01 s:0.02 r:0.60
OK u:0.01 s:0.02 r:0.61
OK u:0.01 s:0.02 r:0.70
OK u:0.01 s:0.02 r:0.70
OK u:0.01 s:0.02 r:0.73
OK u:0.01 s:0.02 r:0.73
OK u:0.01 s:0.02 r:0.80
OK u:0.01 s:0.03 r:0.80
OK u:0.01 s:0.03 r:1.00
OK u:0.01 s:0.03 r:1.00
OK u:0.01 s:0.03 r:1.78
OK u:0.01 s:0.03 r:1.78
OK u:0.01 s:0.03 r:1.93
OK u:0.01 s:0.03 r:1.93
OK u:0.01 s:0.03 r:2.03
OK u:0.01 s:0.03 r:2.03
OK u:0.01 s:0.03 r:2.26
OK u:0.01 s:0.03 r:2.26
OK u:0.01 s:0.03 r:2.38
OK u:0.01 s:0.03 r:2.38
OK u:0.01 s:0.03 r:2.56
OK u:0.01 s:0.03 r:2.56
OK u:0.01 s:0.03 r:2.63
OK u:0.01 s:0.03 r:2.63
OK u:0.01 s:0.03 r:2.74
OK u:0.01 s:0.03 r:2.74
OK u:0.01 s:0.03 r:2.80
OK u:0.01 s:0.03 r:2.80
OK u:0.01 s:0.03 r:2.91
OK u:0.01 s:0.03 r:3.01
OK u:0.01 s:0.03 r:3.08
OK u:0.01 s:0.03 r:3.13
OK u:0.01 s:0.03 r:3.29
OK u:0.01 s:0.04 r:3.50
OK u:0.01 s:0.04 r:3.97
OK u:0.01 s:0.04 r:3.97
OK u:0.01 s:0.04 r:4.04
OK u:0.01 s:0.04 r:4.04
OK u:0.01 s:0.04 r:4.30
OK u:0.01 s:0.04 r:4.30
OK u:0.01 s:0.04 r:4.61
OK u:0.01 s:0.04 r:4.61
OK u:0.02 s:0.04 r:4.71
OK u:0.02 s:0.04 r:4.71
OK u:0.02 s:0.04 r:4.82
OK u:0.02 s:0.04 r:4.82
OK u:0.02 s:0.05 r:4.94
OK u:0.02 s:0.05 r:4.94
OK u:0.02 s:0.05 r:5.10
OK u:0.02 s:0.05 r:5.10
OK u:0.02 s:0.05 r:5.21
OK u:0.02 s:0.05 r:5.23
OK u:0.02 s:0.05 r:5.32
OK u:0.02 s:0.05 r:5.39
OK u:0.02 s:0.05 r:5.51
OK u:0.02 s:0.05 r:5.65
OK u:0.02 s:0.05 r:5.71
OK u:0.02 s:0.05 r:5.78
10/28/2015 11:52:23 AM - SYSTEM STATS: Time:5.9279 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:35 RRDsProcessed:29
#登录mysql检查一下
[iyunv@localhost log]# /usr/bin/mysql -u cactiuser -p
Enter password: cacti123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.0.95 Source distribution
Copyright (c) 2000, 2011, 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> select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> status;
--------------
/usr/bin/mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (i386) using readline 5.1
Connection id: 31
Current database:
Current user: cactiuser@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.0.95 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 hour 46 min 9 sec
Threads: 7 Questions: 22588 Slow queries: 0 Opens: 77 Flush tables: 1 Open tables: 64 Queries per second avg: 3.547
--------------
mysql> show tables;
ERROR 1046 (3D000): No database selected
#查一下数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cacti |
| test |
+--------------------+
3 rows in set (0.01 sec)
#切换数据库至cacti
mysql> use cacti
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
#查看数据库记录poller的执行时间是空的
mysql> select * from poller_time;
Empty set (0.00 sec)
#执行[iyunv@localhost include]# /usr/bin/php /var/www/html/cacti/poller.php --force 后
#再次查看数据库
[iyunv@localhost include]# /usr/bin/mysql -u cactiuser -p
Enter password: cacti123
mysql> use cacti
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
#查看数据库记录poller的执行时间
mysql> select * from poller_time;
+----+-------+-----------+---------------------+---------------------+
| id | pid | poller_id | start_time | end_time |
+----+-------+-----------+---------------------+---------------------+
| 1 | 19470 | 0 | 2015-10-27 21:25:01 | 2015-10-27 21:25:05 |
+----+-------+-----------+---------------------+---------------------+
1 row in set (0.00 sec)
#过一会再查,增加了5分钟
mysql> select * from poller_time;
+----+-------+-----------+---------------------+---------------------+
| id | pid | poller_id | start_time | end_time |
+----+-------+-----------+---------------------+---------------------+
| 1 | 19627 | 0 | 2015-10-27 21:30:02 | 2015-10-27 21:30:05 |
+----+-------+-----------+---------------------+---------------------+
1 row in set (0.00 sec)
[iyunv@localhost log]# cat cacti.log
10/28/2015 11:52:23 AM - SYSTEM STATS: Time:5.9279 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:35 RRDsProcessed:29
10/28/2015 12:25:01 PM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval! The Poller Interval is '300' seconds, with a maximum of a '300' second Cron, but 1964 seconds have passed since the last poll!
10/28/2015 12:25:05 PM - SYSTEM STATS: Time:3.6730 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:35 RRDsProcessed:29
10/28/2015 12:30:05 PM - SYSTEM STATS: Time:3.8174 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:35 RRDsProcessed:29
10/28/2015 12:35:06 PM - SYSTEM STATS: Time:4.2797 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:35 RRDsProcessed:29
10/28/2015 12:40:06 PM - SYSTEM STATS: Time:4.1686 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:35 RRDsProcessed:29
10/28/2015 12:45:05 PM - SYSTEM STATS: Time:4.2167 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:35 RRDsProcessed:29
You have new mail in /var/spool/mail/root