Cacti监控
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cacti监控相关的知识,希望对你有一定的参考价值。
搭建Cacti监控服务器 192.168.4.21一、部署LAMP服务
yum安装httpd、mariadb、mariadb-server、php、php-mysql
# vim /var/www/html/test.php
<?php
$x=mysql_connect("localhost","root","123456");
if($x){ echo "ok"; }else{ echo "err"; };
?>
二、安装Cacti(仙人掌)
2.1 创建存储配置信息的库
mysql> create database cactidb;
2.2 授权存储数据时,连接数据库服务器的用户
MariaDB [(none)]> grant all on cactidb.* to
-> [email protected]"localhost"
-> identified by "123456";
2.3 安装Cacti
[[email protected] ~]# tar -zxf cacti-0.8.8h.tar.gz
[[email protected] ~]# mv cacti-0.8.8h /var/www/html/cacti
[[email protected] ~]# ls /var/www/html
cacti index.html test.php
[[email protected] ~]# chown -R apache:apache /var/www/html/cacti
[[email protected] ~]# ls /var/www/html/cacti/index.*
/var/www/html/cacti/index.php
2.4 访问web页面做初始配置
2.4.1 创建存储配置信息的表
[[email protected] ~]# cd /var/www/html/cacti/
[[email protected] cacti]# ls *.sql
cacti.sql
[[email protected] cacti]# mysql -uxc -p123456 cactidb < cacti.sql
[[email protected] cacti]# mysql -uxc -p123456 cactidb //进入库内查看是否成功导入存储信息
2.4.2 修改配置文件,设置存储配置信息使用的库
[[email protected] cacti]# vi include/config.php
27 $database_default = "cactidb";
29 $database_username = "xc";
30 $database_password = "123456";
[[email protected] cacti]# sed -n '26,32p' /var/www/html/cacti/include/config.php
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "xc";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;
2.4.3 安装依赖的软件包
# yum -y install rrdtool
# yum list | grep -i snmp
# yum -y install net-snmp-*
# rpm -qa |grep -i snmp
访问http://192.168.4.21/cacti/install/
初始用户名与密码均为admin,登陆后会强制要求改密码
三、安装数据高速采集器spine
3.1 安装spine
# yum -y install mariadb-devel
# tar -xf cacti-spine-0.8.8h.tar.gz
# cd cacti-spine-0.8.8h/
[[email protected] cacti-spine-0.8.8h]# ./configure --with-mysql
# make
# make install
# ls /usr/local/spine/bin/spine
3.2 修改spine程序
# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
# vim /etc/spine.conf
修改文件,确定数据库,用户,密码
3.3 配置cacti调用spine采集器(登陆管理页面配置)
++++++++++++++++++++++++++++++++++++++++++++++++
四、监控主机配置
4.1 监控远端主机 192.168.4.18
A、配置被监控端
1) 运行snmpd服务:
装包 # yum -y install net-snmp-*
修改配置文件
sed -i '41s/default/192.168.4.21/' /etc/snmp/snmpd.conf
sed -i '62s/systemview/all/' /etc/snmp/snmpd.conf
sed -i '85s/^#//' /etc/snmp/snmpd.conf //去掉注释的#符号
sed -n '85p' /etc/snmp/snmpd.conf
启动服务
systemctl start snmpd
systemctl enable snmpd
netstat -utanlp |grep snmpd
B、配置监控服务器
1)添加监控主机 并选择监控模板
2)设置监控项
3)创建图片
4)图像树 并把监控主机的图片添加到图像树里
5)编写抓取数据的cron任务
vim /etc/php.ini
878date.timezone = Asia/Shanghai
:wq
# ls /var/www/html/cacti/rra
# ls /var/www/html/cacti/poller.php
# php /var/www/html/cacti/poller.php
[[email protected] ~]# crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php
:wq
# systemctl status crond
tail /etc/spine.conf
6)查看监控图片
4.2 监控本机
修改本机配置
sed -i '41s/default/localhost/' /etc/snmp/snmpd.conf
sed -i '62s/systemview/all/' /etc/snmp/snmpd.conf
sed -i '85s/^#//' /etc/snmp/snmpd.conf
监控网页上添加要监控的主机、图片、生成图像树
4.3 监控警报
插件文件安装目录 ( /var/www/html/cacti/plugins)
a 安装插件 并激活插件
#tar -zxvf monitor-v1.3-1.tgz
#mv monitor /var/www/html/cacti/plugins/
#tar -zxvf settings-v0.71-1.tgz
#mv settings /var/www/html/cacti/plugins/
#tar -zxvf thold-v0.5.0.tgz
#mv thold /var/www/html/cacti/plugins/
b 配置插件实现监控报警
要求:监控本机登录的用户数 做监控报警 >1 报警 >2报错 ,达到监控阀
值时给本机的[email protected]邮箱发邮件。
1、在本机准备邮件服务并添加邮箱帐号
#rpm -q postfix || yum -y install postfix
#systemctl status postfix
#useradd cacti
# mail -s "aaa" cacti < /etc/hosts
# su - cacti
2 配置监控报警
a 创建邮箱列表 sendmail
b 配置监控报警
c 指定邮件服务器
d 查看监控报警项是否被触发
e 查看是否收到报警邮件
以上是关于Cacti监控的主要内容,如果未能解决你的问题,请参考以下文章