测试
[root@cacti-server ~]# /usr/bin/php /var/www/html/cacti/poller.php
OK u:0.00 s:0.01 r:0.80
OK u:0.00 s:0.02 r:1.21
OK u:0.00 s:0.02 r:1.39
OK u:0.00 s:0.02 r:1.50
OK u:0.00 s:0.02 r:1.87
10/21/2016 04:02:32 PM - SYSTEM STATS: Time:1.4211 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
3.安装Spine
注:由于cacti默认使用cmd.php来轮询数据,速度会很慢,特别是在监控节点比较多的情况下,cmd.php就更显不足了,因此我们采用Spine来轮询数据。cacti-spine是一个由C语言开发的,用于替代cmd.php的快速获取数据的引擎。
[root@cacti-server ~]# cd /usr/local/src/
[root@cacti-server src]#wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8f.tar.gz
[root@cacti-server src]# tar zxvf cacti-spine-0.8.8f.tar.gz
[root@cacti-server cacti-spine-0.8.8f]# ./configure
[root@cacti-server cacti-spine-0.8.8f]# make
[root@cacti-server cacti-spine-0.8.8f]# make install
拷贝snmp的配置文件
[root@cacti-server ~]# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
注:spine默认配置文件需要放在/etc才会生效,否则测试时会报如下错误:
SPINE: Poller[0] FATAL: Unable to read configuration file! (Spine init)
编辑配置文件
[root@cacti-server ~]# vim /etc/spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass RedHat
DB_Port 3306
测试
[root@cacti-server ~]# /usr/local/spine/bin/spine
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8f starting
SPINE: Time: 0.1278 s, Threads: 5, Hosts: 2
修改web的设置
进入Cacti页面设置spine路径
Console -> Configuration -> Settings -> Paths -> Alternate Poller Path -> Spine Poller File Path->/usr/local/spine/bin/spine
修改Cacti使用的Poller Type
Console -> Configuration -> Settings ->Poller->Poller Type->spine
查看日志
[root@cacti-server ~]# cat /var/www/html/cacti/log/cacti.log
10/22/2016 12:45:50 AM - SYSTEM STATS: Time:0.1146 Method:spine Processes:1 Threads:1 Hosts:2 HostsPerProcess:2 DataSources:0 RRDsProcessed:0
4.添加被监控主机
安装snmp服务
[root@cacti-client ~]# yum -y install net-snmp net-snmp-devel net-snmp-utils
编辑配置文件
[root@cacti-client ~]# vim /etc/snmp/snmpd.conf
41 com2sec notConfigUser 192.168.23.156 public
62 access notConfigGroup "" any noauth exact all none none
85 view all included .1 80
[root@cacti-client ~]# systemctl restart snmpd
[root@cacti-client ~]# systemctl enabled snmpd
配置防火墙
[root@cacti-client ~]# firewall-cmd --permanent --add-port=161/udp
success
[root@cacti-client ~]# firewall-cmd --reload
success
5.监控apache
客户端的配置
编辑apache的配置文件,加入server-status模块的设置
[root@cacti-client ~]# vim /etc/httpd/conf/httpd.conf
ExtendedStatus On
SetHandler server-status
Order deny,allow
Deny from all
Allow from all
[root@cacti-client ~]# systemctl restart httpd
[root@cacti-client ~]# systemctl enable httpd
查看apache加载的模块
[root@cacti-client ~]# apachectl -t -D DUMP_MODULES|grep status
status_module (shared)
访问http://192.168.23.157/server-status查看模块的详细信息
[root@cacti-client ~]# firewall-cmd --permanent --add-service=http
success
[root@cacti-client ~]# firewall-cmd --reload
success
服务端的配置
安装监控apache的php页面
[root@cacti-server ~]# cd /usr/local/src/
[root@cacti-serversrc]#wget http://forums.cacti.net/download/file.php?id=18576&sid=8d429b69af5be45179d928e1303f2077
[root@cacti-server src]# unzip ApacheStats_0.8.2.zip
[root@cacti-server src]# cd ApacheStats_0.8.2/
[root@cacti-serverApacheStats_0.8.2]#cp ss_apache_stats.php /var/www/html/cacti/scripts/
导入模板
在Cacti Web界面导入cacti_host_template_webserver_-_apache.xml模板:
点击Import/Export->Import Templates,上传模板即可
添加服务器并创建图表
登录Cacti Web界面,添加被监控apache服务器设备,并创建相应图表:
Devices->Add->WebServer–Apache模板->Create New Graphs,添加所需图表即可。等待一段时间就会出图
6.监控mariadb
[root@cacti-client ~]# mysql -uroot -predhat
MariaDB [(none)]> grant process,super,replication client on *.*to 'mysqltest'@'192.168.23.156' identified by 'redhat'; 创建用于监控主机连接mariadb进行监控的用户
MariaDB [(none)]> flush privileges;
[root@cacti-client ~]# systemctl restart mariadb
[root@cacti-client ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@cacti-client ~]# firewall-cmd --reload
success
安装监控mariadb的php页面文件
[root@cacti-server ~]# cd /usr/local/src/
[root@cacti-serversrc]#wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-monitoring-plugins-1.1.6.tar.gz
[root@cacti-server src]# tar zxvf percona-monitoring-plugins-1.1.6
[root@cacti-server src]# cd percona-monitoring-plugins-1.1.6/cacti/scripts/
[root@cacti-serverscripts]#cpss_get_mysql_stats.php /var/www/html/cacti/scripts/
编辑页面文件
[root@cacti-server scripts]# vim /var/www/html/cacti/scripts/ss_get_mysql_stats.php
$mysql_user = 'mysqltest'; 用于监控主机连接mariadb的用户
$mysql_pass = 'redhat'; 用户密码
导入模板
在Cacti Web界面导入cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.1.6.xml模板:
点击Import/Export->Import Templates,上传模板即可
添加服务器并创建图表
登录Cacti Web界面,添加被监控mariabdb服务器设备,并创建相应图表:
Devices->Add->dbServer–Mysql模板->Create New Graphs,添加所需图表即可。等待一段时间就会出图
7.邮件报警
下载插件
[root@cacti-server ~]# cd /usr/local/src/
[root@cacti-server src]# tar zxvf settings-v0.71-1.tgz
[root@cacti-server src]# mv settings /var/www/html/cacti/plugins/
[root@cacti-server src]# tar zxvf thold-v0.5.0.tgz
[root@cacti-server src]# mv thold /var/www/html/cacti/plugins/
访问cacti管理页面安装插件
测试
告警被触发
查看邮件
[root@cacti-server ~]# cat /var/spool/mail/root
..................................
..................................
To: root@192.168.23.156
Subject: ALERT: test - Used Space - / [hdd_used] [hdd_used] went above threshold of 25 with 36.8871
From: Cacti
Date: Mon, 24 Oct 2016 14:00:03 +0800
..................................
An alert has been issued that requires your attention.
..................................
Host: test (192.168.23.157)
URL: http://192.168.23.156/cacti//graph.php?local_graph_id=103&rra_id=1
Message: ALERT: test - Used Space - / [hdd_used] [hdd_used] went above threshold of 25 with 36.8871
..................................
Content-Type: image/jpg
Content-Disposition: inline; filename="103.jpg"
...................................
...................................
Cacti 的详细介绍:请点这里
Cacti 的下载地址:请点这里