CentOS7下安装搭建Cacti

Posted mxbox

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7下安装搭建Cacti相关的知识,希望对你有一定的参考价值。

1.搭建lamp环境

配置apache

[[email protected] ~]# yum -y install httpd

[[email protected] ~]# systemctl start httpd

[[email protected] ~]# systemctl enable httpd

[[email protected] ~]# firewall-cmd --permanent --add-service=http

success

[[email protected] ~]# firewall-cmd --reload

success

配置mariadb

[[email protected] ~]# yum -y install mariadb-server mysql-devel

[[email protected] ~]# systemctl start mariadb

[[email protected] ~]# mysql_secure_installation

Set root password? [Y/n]

Remove anonymous users? [Y/n] y

Disallow root login remotely? [Y/n] y

Remove test database and access to it? [Y/n] y

Reload privilege tables now? [Y/n] y

[[email protected] ~]# mysql -u root -p

MariaDB [(none)]> grant all privileges on *.* to [email protected] identified by ‘RedHat‘; 创建用于测试php和mariadb连通性的用户

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

[[email protected] ~]# systemctl restart mariadb

[[email protected] ~]# systemctl enable mariadb

[[email protected] ~]# firewall-cmd --permanent --add-port=3306/tcp

success

[[email protected] ~]# firewall-cmd --reload

success

配置php

[[email protected] ~]# yum -y install php php-mysql php-gd php-pear

[[email protected] ~]# vim /etc/php.ini 

date.timezone =PRC      修改时区

[[email protected] ~]# vim /var/www/html/index.php    编辑测试页面

<?php

    $conn=mysql_connect(‘localhost‘,‘test‘,‘redhat‘);

    if ($conn)

      echo "database connect ok";

    else

      echo "database connect failure";

?>

<?php

    phpinfo()

?>

[[email protected] ~]# systemctl restart httpd

测试

技术分享

2.安装配置cacti

下载软件

[[email protected] ~]# cd /usr/local/src/

[[email protected] src]# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz

[[email protected] src]# tar zxvf cacti-0.8.8f.tar.gz

[[email protected] src]# mv cacti-0.8.8f /var/www/html/cacti

创建cacti数据库和cacti用户,赋予权限

[[email protected] ~]# mysql -u root -p

MariaDB [(none)]> create database cacti default character set utf8;

MariaDB [(none)]> grant all privileges on cacti.* to [email protected] identified by ‘redhat‘;

MariaDB [(none)]> flush privileges;

把cacti.sql导入数据库

[[email protected] cacti]# mysql -ucacti -predhat cacti < /var/www/html/cacti/cacti.sql

编辑config.php和global.php

[[email protected] cacti]# vim /var/www/html/cacti/include/config.php|global.php

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cacti";

$database_password = "redhat";

$database_port = "3306";

$database_ssl = false;

安装rrdtool以生成图像

[[email protected] src]# yum -y install rrdtool rrdtool-devel rrdtool-php rrdtool-perl

[[email protected] src]# yum -y install gd gd-devel php-gd    ---rrdtool绘制图像需要的图形库

安装snmp服务

[[email protected] cacti]# yum -y install net-snmp net-snmp-utils php-snmp net-snmp-libs

编辑配置文件

[[email protected] ~]# 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

[[email protected] ~]# systemctl restart snmpd.service

[[email protected] ~]# systemctl enable snmpd.service

授权目录权限

[[email protected] ~]# useradd -r -M cacti

[[email protected] ~]# chown -R cacti /var/www/html/cacti/rra/

[[email protected] ~]# chown -R cacti /var/www/html/cacti/log/

配置一个抓图的计划任务

[[email protected] ~]# crontab -e

*/5 * * * * /usr/bin/php  /var/www/html/cacti/poller.php >> /tmp/cacti_rrdtool.log

浏览器访问cacti管理页面进行安装

 

报错

MySQL TimeZone Support ERROR: Your Cacti database login account does not have access to the MySQL TimeZone database. Please provide the Cacti database account "select" access to the "time_zone_name" table in the "mysql" database, and populate MySQL‘s TimeZone information before proceeding

 

**bash环境下执行 mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

mysql环境下

mysql> use mysql;

mysql> GRANT SELECT ON mysql.time_zone_name TO [email protected];

mysql> flush privileges;**

 

以上是关于CentOS7下安装搭建Cacti的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7.X基于LAMP环境搭建cacti

centos7下搭建cacti

Centos7.4下构建cacti监测体系

cacti搭建

Cacti搭建以及部分常用插件安装

生产环境下搭建 nagios+nconf+cacti+npc的整合