Cacti的服务器监控

             服务器监控Cacti

一、企业需求

通过cacti实现和windows和mysql的监控

 

二、实现思路

cacti 通过调用net-snmp工具采集数据,结合rrdtool记录数据并绘制图片,以web页面形式展示给管理员用户

 

三、运维环境

两台最小化虚拟机,一台windows2008 R2 虚拟机

Cacti   192.168.10.1/24 LAMP net-snmp-tuils rrd-tool cacti

Client  192.168.10.2/24 mysql net-snmp-tuils

 

详细步骤

 

 

安装需要的依赖包

[root@cacti ~]# yum -y install httpd mysql mysql-server mysql-devel php php-mysql php-gd zlib freetype libxml2 gd libjpeg make gcc gcc-c++

 

 

修改httpd 配置文件

[root@cacti ~]# vim /etc/httpd/conf/httpd.conf

276 ServerName www.example.com:80

402 DirectoryIndex index.php index.html index.html.var

 

 

启动服务

[root@cacti ~]# /etc/init.d/httpd start

Starting httpd:                                            [  OK  ]

 

 

mysql初始化

[root@cacti ~]# /etc/init.d/mysqld start

Please report any problems with the /usr/bin/mysqlbug script!

 

                                                           [  OK  ]

Starting mysqld:                                           [  OK  ]

 

 

写好主页

[root@cacti ~]# vim /var/www/html/test.php

 

<?php

phpinfo();

?>

 

 

192.168.10.1

 

 

192.168.10.1/test.php

 

 

 

 

安装Net-snmp-utils 软件包 提供 snmpget snmpwalk snmp 等数据采集命令

[root@cacti ~]# yum -y install net-snmp net-snmp-utils

 

[root@cacti ~]# /etc/init.d/snmpd start

Starting snmpd:                                            [  OK  ]

 

开机启动

[root@cacti ~]# chkconfig mysqld on

[root@cacti ~]# chkconfig httpd on

[root@cacti ~]# chkconfig snmpd on

 

安装rrdtool软件包

依赖包

[root@cacti ~]# yum -y install cairo-devel zlib libxml2 libxml2-devel glib2 glib2-devel libpng libpng-devel freetype freetype-devel libart_lgpl pango pango-devel perl-CPAN

 

源码包

[root@cacti ~]# tar xf rrdtool-1.4.8.tar.gz -C /usr/src/

[root@cacti ~]# cd /usr/src/rrdtool-1.4.8/

[root@cacti rrdtool-1.4.8]# ./configure --prefix=/usr/local/ && make && make install

 

 

安装Cacti  配置连接数据库

[root@cacti ~]# tar xf cacti-0.8.8b.tar.gz 

[root@cacti ~]# mv cacti-0.8.8b /var/www/html/cacti

[root@cacti ~]# useradd -M -s /sbin/nologin cacti

[root@cacti ~]# chown -R cacti.cacti /var/www/html/cacti/

创建用于cacti监测平台 使用cacti下的cacti.sql

[root@cacti ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.1.71 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 cactidb default character set utf8;

Query OK, 1 row affected (0.00 sec)

授权

mysql> grant all on cactidb.* to 'cacti'@localhost identified by 'cacti';

Query OK, 0 rows affected (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

导入数据表

 

[root@cacti cacti]# mysql -uroot -p123123 cactidb < cacti.sql

 

调整cacti配置文件 修改include/config.php 设置数据库连接参数

 

[root@cacti cacti]# pwd

/var/www/html/cacti

[root@cacti cacti]# vim include/config.php

 

26 $database_type = "mysql";

27 $database_default = "cactidb";   //Mysql库名

28 $database_hostname = "localhost";

29 $database_username = "cacti";   //用户名

30 $database_password = "cacti";   //密码

31 $database_port = "3306";       //端口

32 $database_ssl = false;

 

39 $url_path = "/";      //开启注释,指定cacti目录相对于网站根目录的位置

 

[root@cacti cacti]# vim /etc/httpd/conf/httpd.conf

292 DocumentRoot "/var/www/html/cacti"   默认发布路径

317 <Directory "/var/www/html/cacti">      

重启服务

[root@cacti cacti]# /etc/init.d/httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

 

客户机配置

安装所需要的依赖包

[root@client ~]# yum -y install net-snmp lm_sensors

 

修改配置文件

[root@client ~]# cp -p /etc/snmp/snmpd.conf{,.bak}

[root@client ~]# vim /etc/snmp/snmpd.conf

 

41 com2sec notConfigUser  192.168.10.1       public

62 access  notConfigGroup ""      any       noauth    exact  all none none

85 view all    included  .1                               80

 

[root@client ~]# /etc/init.d/snmpd start

Starting snmpd:                                            [  OK  ]

 

[root@client ~]# netstat -aunpt |grep 161

udp        0      0 0.0.0.0:161                 0.0.0.0:*                               1171/snmpd

 

iptables -I INPUT -s 内网 -p udp --dport 161 -j ACCEPT

iptables -I OUTPUT -s 内网 -p udp --sport 161 -j ACCEPT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

[root@cacti cacti]# /usr/bin/php /var/www/html/cacti/poller.php --force

OK u:0.00 s:0.00 r:0.00

OK u:0.00 s:0.00 r:0.00

OK u:0.00 s:0.00 r:0.00

OK u:0.00 s:0.00 r:0.02

OK u:0.00 s:0.00 r:0.04

OK u:0.00 s:0.00 r:0.24

OK u:0.00 s:0.00 r:0.29

OK u:0.00 s:0.00 r:0.33

OK u:0.00 s:0.00 r:0.38

OK u:0.00 s:0.00 r:0.42

OK u:0.00 s:0.00 r:0.47

OK u:0.00 s:0.00 r:0.51

OK u:0.00 s:0.00 r:0.55

OK u:0.00 s:0.00 r:0.60

OK u:0.00 s:0.00 r:0.62

OK u:0.00 s:0.00 r:0.74

OK u:0.00 s:0.00 r:0.85

OK u:0.00 s:0.00 r:0.96

OK u:0.00 s:0.00 r:1.08

OK u:0.00 s:0.00 r:1.18

OK u:0.00 s:0.00 r:1.30

OK u:0.00 s:0.00 r:1.42

OK u:0.00 s:0.00 r:1.53

OK u:0.00 s:0.00 r:1.65

OK u:0.00 s:0.00 r:1.77

OK u:0.01 s:0.00 r:1.88

05/24/2017 02:34:53 AM - SYSTEM STATS: Time:2.0112 Method:cmd.php Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:37 RRDsProcessed:26

 

 

 

可能出现的报错

[root@cacti cacti]# vim /etc/php.ini  --force

[root@cacti cacti]# /etc/init.d/httpd restart

停止 httpd:                                               [确定]

正在启动 httpd:                                           [确定]

 

上面是数据出不来 可以重启服务强制刷新

 

[root@client ~]# yum -y install mysql mysql-server mysql-devel

[root@client ~]# /etc/init.d/mysqld restart

 

设置计划任务

[root@cacti cacti]# crontab -ucacti -e

 

*/5     *       *       *       *      /usr/bin/php /var/www/html/cacti/poller.php

 

[root@cacti cacti]# crontab -l -ucacti

*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php

 

 

[root@cacti cacti]# chkconfig crond on

[root@cacti cacti]# /etc/init.d/crond status

crond (pid  1880) 正在运行...

 

localhost

 

 

 

 

 

 

 

linux-server

 

 

 

 

 

 

安装源码包

[root@cacti ~]# tar xf percona-monitoring-plugins-1.1.4.tar.gz -C /usr/src/

[root@cacti ~]# cd /usr/src/percona-monitoring-plugins-1.1.4/cacti/scripts/

[root@cacti scripts]# cp ss_get_mysql_stats.php /var/www/html/cacti/scripts/

 

 

 

 

客户端,被监控端 授权

[root@client ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.1.71 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> grant process,super on *.* to 'cacti'@'192.168.10.1' identified by 'cacti';

Query OK, 0 rows affected (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

 

 

选择,mysql模板

 

 

 

 

 

import   >  选择文件 import

 

全都绿了

 

 

HOST TEMPLATES

Percona mysql server HT

 

 

导入模板成功 save

 

 

save

 

 

 

Devices  

新建一个新的设备

 

 

保存

 

 

mysql  192.168.10.2   Percona mysql version 2   create

 

 

 

mysql添加进tree中

 

 

[root@cacti scripts]# /etc/init.d/httpd restart

停止 httpd:                                               [确定]

正在启动 httpd:                                           [确定]

[root@cacti scripts]# /usr/bin/php /var/www/html/cacti/poller.php --force

 

 

[root@cacti scripts]# vim /etc/ntp.conf

 

时间同步

 

 

[root@client ~]# ntpdate 192.168.10.1

23 May 19:50:12 ntpdate[52147]: adjust time server 192.168.10.1 offset -0.001339 sec

[root@client ~]# ntpdate 192.168.10.1

23 May 19:50:14 ntpdate[52148]: adjust time server 192.168.10.1 offset -0.000813 sec

 

 

 

 

client成功

 

windows 2008 R2

 

 

配置  >  服务   >  属性  

 

 

 

 

 

 

 

 

重启服务

新建一个新的设备

 

 

 

windows成功

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值