cacti安装与配置

一 cacti组键介绍

1 cacti

  • Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。它通过snmpget来获取数据,使用 RRDtool绘画图形,
  • cacti架构
    cacti安装与配置_第1张图片

2 snmp(Simple Network Management Protocal, 简单网络管理协议)

  • 原理:在每个被监控的主机或节点上都运行一个agent,用来收集这个节点的所有相关信息
  • 同时监听snmp的port(161)。
  • 安装:分为监控机和被监控机:监控机安装Nnet-snmp-utils,被监控端安装net-snmp。
  • 工作方式:
    cacti安装与配置_第2张图片
    -安装方式
yum install -y net-snmp net-snmp-utils #安装snmp-service snmp-agent
systemctl restart snmpd #启动snmp
netstat -unlp #看看snmp协议端口
snmpwalk -v 2c -c public localhost host  #查看主机信息

注:MIB:OID和名称对应关系

3 rrdtool

  • 安装rrdtool
yum install -y rrdtool
  • 查看rrdtool工具
 rrdtool -h
  • RRDTool绘图步骤
    cacti安装与配置_第3张图片

二 cacti安装

注:本文基于centos7.2最小化安装 默认防火墙已经关闭。

2.1 基于yum安装lamp环境

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum install --enablerepo=remi,remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
yum install mysql-community-server -y
yum install -y httpd

2.2 设置apache、mysql、php为开机自动启动

systemctl restart httpd
systemctl enable httpd
systemctl restart mysqld
systemctl enable mysqld
systemctl enable php-fpm
systemctl restart php0fpm

2.3 安装snmp

yum install net-snmp net-snmp-utils -y

2.4 安装rrdtool

yum install -y rrdtool rrdtool-devel rrdtool-php

2.5 配置mysql

mysqladmin create cactidb
mysql cactidb < cacti.sql
mysql -e "grant all on cactidb.* to cactiuser@localhost identified by 'cactiuser'"
mysqladmin flush-privileges 

修改/etc/my.cnf

max_heap_table_size =32M
max_allowed_packet =16777216
tmp_table_size =128M
join_buffer_size =128M
innodb_doublewrite =off
innodb_additional_mem_pool_size =100M
innodb_flush_log_at_timeout =5
innodb_read_io_threads=32
innodb_write_io_threads=16
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci

2.6 编辑cacti配置文件

#编辑cacti配置文件XXX/cacti/include/config.php
$database_type = "mysql";
$database_default = "cactidb";    #修改为自己创建的数据库
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;
$url_path = "/";

2.7 创建普通用户并添加执行权限

useradd  cactiuser
chown -R cactiuser.cactiuser log rra
echo '*/5 * * * * /usr/bin/php /web/vhosts/cacti/poller.php &> /dev/null' > /var/spool/cron/cactiuser 

2.8 修改php时区

vim /etc/php.ini 
#date.timezone = Asia/Shanghai

执行php脚本 php /var/www/html/cacti/poller.php

添加php-XXX插件:具体见修改前缺什么模块

修改配置文件:修改前
修改前:
cacti安装与配置_第4张图片

yum -y install php-posix
yum -y install php-ldmp

2.9 安装spine

wget https://www.cacti.net/downloads/spine/cacti-spine-1.1.38.tar.gz

修改后:
安装完成示意图
cacti安装与配置_第5张图片

问题及解决方案

问题一:如何升级mysql数据库
参考:mysql升级:5.4–>5.6
https://blog.csdn.net/u010440155/article/details/54910595

问题二:如何修改mysql的root密码并赋予远程登录权限
mysql修改root密码
https://blog.csdn.net/jie11447416/article/details/53444656/

问题三:如何安装php插件模块
注:我这里安装php5.6版本

yum install -y php56-ldap.x86_64 #这里添加php模块如php56-ldap.x86_64
#参考https://segmentfault.com/a/1190000010270703

问题四:mysql命令失败提示

mysql>  GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxx' WITH GRANT OPTION ;
ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 43, found 42. Created with MySQL 50556, now running 50640. Please use mysql_upgrade to fix this error.

解决方案:mysql_upgrade -u root -p --force

问题五:如何升级php版本为5.6

sudo yum clean all
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm  
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm  
yum remove php-common 
yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring  
yum install yum-plugin-replace
systemctl restart php-fpm
service  restart httpd

参考和阅读文献

安装rrdtool和cacti遇到的问题
https://blog.csdn.net/wusilen/article/details/61622259
参考文献:
RRDTool 详解 https://blog.csdn.net/apple_llb/article/details/50839311
RRDtool简体中文教程 http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=864861&page=1
Cacti整合Zabbix监控 http://www.178linux.com/1215
cacti,zabbix,nagios各自原理及区别 http://blog.51cto.com/12118369/1968090
监控篇之 —- nagios + cacti 介绍及区别http://blog.51cto.com/binbinwudi8688/1408961
Cacti+Nagios监控平台完美整合(2)

你可能感兴趣的:(cacti安装与配置)