cacti是一款用php语言开发的性能与流量监控工具
监控对象:linux、windows、路由器、交换机等
监控范围:基于SNMP(简单网络管理协议)搜集CPU占用和内存使用、运行进程数、磁盘空间、网卡流量等各种数据
官方下载地址:https://www.cacti.net/downloads/
本案例:
基于centos7.4架设监控平台 服务器地址:192.168.80.81
80.81安装好lamp,cacti是在web上部署的,
因为系统安装包内版mariadb本过低,无法与最新版cacti搭配使用,现在yum仓库里增加中科大mariadb源,解决这一问题
需要的各软件版本:
Apache 2.4.6
MariaDB 10.1.30
PHP Version 5.4.16
cacti-1.1.26
cacti-spine-1.1.26
help2man-1.41.1-3.el7
php-mbstring-5.4.16-42.el7
php-snmp-5.4.16-42.el7
案例开始:
1.安装各种软件
yum install -y \
httpd \
MariaDB-client MariaDB-server \
MariaDB-devel \
php \
php-snmp \
php-ldap \
php-pdo \
php-mysql \
php-devel \
php-pear \
php-common \
php-gd \
php-mbstring \
php-xml \
php-process \
net-snmp \
net-snmp-utils \
net-snmp-libs \
net-snmp-agent-libs \
net-snmp-devel \
rrdtool \
rrdtool-php \
rrdtool-perl \
rrdtool-devel \
gcc openssl-devel \
dos2unix \
autoconf \
automake \
binutils libtool \
cpp postfix \
glibc-headers \
kernel-headers \
glibc-devel \
gd gd-devel \
help2man \
ntpdate \
wget patch
2.LAMP调试
vi /etc/httpd/conf/httpd.conf
ServerName www.aa.com //修改主机名
vi /etc/httpd/conf.d/php.conf
LoadModule php5_module modules/libphp5.so //最底行下插入
vi /etc/php.ini
safe_mode=off //在[PHP]下插入
date.timezone = PRC //放开#
systemctl stop firewalld.service
setenforce 0
systemctl start httpd.service
systemctl start mariadb.service
netstat -anpt | grep 80
netstat -anpt | grep 3306
mysql_secure_installation //给数据库初始设置,初始密码去除匿名等
vi /var/www/html/index.php
<?php
phpinfo();
?>
win10访问http://192.168.80.81/ 检测和php连通性,出现php版本页
vi /etc/my.cnf.d/server.cnf //[mysqld]下配置
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci
character_set_client = utf8mb4
max_connections = 100
max_heap_table_size = 256M
max_allowed_packet = 16777216
join_buffer_size = 64M
tmp_table_size = 64M
innodb_file_per_table = ON
innodb_buffer_pool_size = 1024M
innodb_doublewrite = OFF
innodb_lock_wait_timeout = 50
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
mysql -u root -p //登入数据库添加授权用户cacti
CREATE DATABASE cacti character set utf8 collate utf8_bin; //创建cacti数据库 使用utf8编码
GRANT all ON cacti. TO ‘cacti‘@‘%‘ IDENTIFIED BY ‘admin123‘;
GRANT all ON cacti. TO ‘cacti‘@‘localhost‘ IDENTIFIED BY ‘admin123‘;
flush privileges;
vi /var/www/html/index.php
<?php
$link=mysqli_connect(‘192.168.80.81‘,‘cacti‘,‘admin123‘);
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
win10访问http://192.168.80.81/ 检测mysql php是否协同工作
3.安装cacti
tar xf cacti-1.1.26.tar.gz
mv cacti-1.1.26 /var/www/html/cacti
mysql -ucacti -p cacti < /var/www/html/cacti/cacti.sql //数据库导入
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot mysql -p //导入时区文件否则cacti会报错
grant select on mysql.time_zone_name to ‘cacti‘@‘localhost‘ IDENTIFIED BY ‘admin123‘; //在数据库中为时区文件授权给cacti localhost改为%
vi /var/www/html/cacti/include/config.php //编辑cacti连接数据库账号
hostname = 192.168.80.182 本地连接可以不改,远程连接就改 这里localhost ,上面授权就localhost
$database_username = ‘cacti‘;
$database_password = ‘admin123‘;
----------------以下配置SNMP------
rpm -ivh php-snmp-5.4.16-42.el7.x86_64.rpm php-mbstring-5.4.16-42.el7.x86_64.rpm
vi /etc/snmp/snmpd.conf
com2sec notConfigUser 127.0.0.1 public //改成环回口地址监控自己 41
access notConfigGroup "" any noauth exact all none none //把systemview改成all 62
view all included .1 80 // 去掉#号 85
systemctl restart snmpd.service
systemctl enable snmpd.service
useradd -r -M cacti
chown -R cacti /var/www/html/cacti/rra/
chown -R cacti /var/www/html/cacti/log/
chown -R apache.apache /var/www/html/cacti/resource/
chown -R apache.apache /var/www/html/cacti/cache
chown -R apache.apache /var/www/html/cacti/scripts
chown -R apache.apache /var/www/html/cacti/log
------以下可以不做-----
crontab -e
/5 * /usr/bin/php /var/www/html/cacti/poller.php >> /tmp/cacti_rrdtool.log
---------------以下安装cacti-spine优化数据轮询速度-----插件采集数据
需要安装help2man-1.41.1-3.el7.noarch.rpm
ln -s /usr/lib64/libmysqlclient.so.18.0.0 /usr/lib64/libmysqlclient.so
tar xf cacti-spine-1.1.26.tar.gz
cd cacti-spine-1.1.26
./configure && make && make install
cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf 复制模板为配置文件
vi /usr/local/spine/etc/spine.conf //修改相关参数
DB_Host localhost 自己本机
DB_Database cacti
DB_User cacti
DB_Pass admin123
DB_Port 3306
RDB_Host localhost 远程主机
RDB_Database cacti
RDB_User cacti
RDB_Pass admin123
RDB_Port 3306
-----------登录到页面-----------
service httpd restart
192.168.80.181/cacti/
……
安装过程
……
spine路径 /usr/local/spine/bin/spine
日志路径 /var/www/html/cacti/log
默认账号:admin admin 修改密码要使用复杂密码且至少8位且是复杂密码
[email protected]
Console -> 设置(Cacti Settings) -> Paths -> 在 Spine Binary File Location 文本框内填入配置文件路径 /usr/local/spine/bin/spine ,在 Spine Config File Path 文本框内填入配置文件路径 /usr/local/spine/etc/spine.conf,点击保存 (Save)。
//使用spine插件采集数据
Console -> 设置(Cacti Settings) -> Poller -> 在 Poller Type 下拉框中选择 spine ,点击保存 (Save)。
在添加完设备和图形后,需要重建采集器缓存。
Console --> 系统工具 --> Rebuild Poller Cache
----------------增加被控主机--------------
通过“控制面板”-“程序”把SNMP的服务端增加好。
然后在服务管理器中使用SNMP service 在安全中增加相关参数。新增加的服务 要重启才行。
新图形 -snmp版本2
使用pingandsnmpuptime
win10里服务设置名称和安全里面的地址snmp
原文地址:http://blog.51cto.com/13469709/2091989