部署Cacti监控服务 192.168.4.13
一、部署服务器运行环境 (LAMP)
#yum -y install httpd php
#yum -y install mariadb-server mariadb
#yum -y install php-mysql
#systemctl restart httpd ;systemctl enable httpd
#systemctl start mariadb ;systemctl enable mariadb
#mysql
mysql> create database cactidb;
mysql> grant all on cactidb.* to plj@"localhost" identified by
"123456";
mysql>quit;
#mysql -uplj -p123456
mysql> quit;
二 、测试运行环境
vim /var/www/html/linkdb.php
<?php
$a=mysql_connect("localhost","plj","123456");
if($a){echo "ok";}else{echo "err";}
?>
:wq
[root@localhost ~]# elinks --dump http://localhost/linkdb.php
ok
三、安装cacti
#tar -zxvf cacti-0.8.8h.tar.gz -C /var/www/html/
#cd /var/www/html/
# mv cacti-0.8.8h/ cacti
#chmod -R 777 cacti
#mysql -uplj -p123456 cactidb < /var/www/html/cacti/cacti.sql
#mysql -uplj -p123456 cactidb
mysql> show tables;
# vim /var/www/html/cacti/include/config.php
26 $database_type = "mysql";
27 $database_default = "cactidb";
28 $database_hostname = "localhost";
29 $database_username = "plj";
30 $database_password = "123456";
31 $database_port = "3306";
32 $database_ssl = false;
:wq
四、登录web页面做初始化配置
RRDTool 绘图工具
yum -y install rrdtool
snmp 简单网络管理协议
# yum -y install net-snmp*
firefox http://192.168.4.13/cacti
用户名 admim
初始密码 admim
(首次登录强制修改登录密码)
五 、使用Cacti
a 查看已经监控的主机
b 查看已有的监控模版
c 查看对已监控主机创建的监控图片
六、安装高速采集器
6.1 安装
#yum -y install mariadb-devel
#tar -zxvf cacti-spine-0.8.8h.tar.gz
#cd cacti-spine-0.8.8h/
#./configure --with-mysql
#make
#make install
# ls /usr/local/spine/
bin etc
6.2 配置
#cp /usr/local/spine/bin/spine /usr/bin/
#cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
#vim /etc/spine.conf
33 DB_Host localhost
34 DB_Database cactidb
35 DB_User plj
36 DB_Pass 123456
37 DB_Port 3306
:wq
6.3 登录管理页面设置采集数据频率
http://192.168.4.13/cacti
++++++++++++++++++++++++++++++++++++++++++
七 配置
7.1 监控本机
a 运行snmpd服务
#rpm -qa | grep -i snmp
# vim /etc/snmp/snmpd.conf
41 com2sec notConfigUser 127.0.0.1 public
62 access notConfigGroup "" any noauth exact all none
none
85 view all included .1 80
:wq
# systemctl start snmpd ; systemctl enable snmpd
[root@localhost ~]# netstat -untlap | grep snmpd
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN
26507/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:*
26507/snmpd
[root@localhost ~]#
b 登录管理页面添加监控本机
1 添加监控新主机(名称 ip地址 监控模版 监控项目)
2 创建图像
3 创建图像树 localhost-tree
4 把监控本机的图像 添加到图像树
5 编写计划任务
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
[root@localhost ~]# crontab -e
*/1 * * * * php /var/www/html/cacti/poller.php
:wq
# systemctl status crond
6 查看监控信息
7.2 监控远端主机 192.168.4.12
++++++++++++++++++++++++++++
7.2.1 配置远端主机
a 运行snmpd服务
# sed -i '41s/default/192.168.4.13/' /etc/snmp/snmpd.conf
# sed -i '62s/systemview/all/' /etc/snmp/snmpd.conf
# sed -i '85s/^#//' /etc/snmp/snmpd.conf
# systemctl start snmpd ; systemctl enable snmpd
# netstat -utnalp | grep snmpd
7.2.2 配置监控服务器
1 添加监控新主机(名称 ip地址 监控模版 监控项目)
2 创建图像
3 创建图像树 web12-tree
4 把监控本机的图像 添加到图像树
6 查看监控信息
+++++++++++++++++++++++++++++
7.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报错 ,达到监控阀
值时给本机的cacti@localhost邮箱发邮件。
1、在本机准备邮件服务并添加邮箱帐号
#rpm -q postfix || yum -y install postfix
#systemctl status postfix
#useradd cacti
# mail -s "aaa" cacti < /etc/hosts
# su - cacti
#mail
2 配置监控报警
a 创建邮箱列表 sendmail
b 配置监控报警
c 指定邮件服务器
d 查看监控报警项是否被触发
e 查看是否收到报警邮件