这篇微博是记录我根据Linux公社的lidaxia搭建的,用来记录我搭建成功的过程,原文是这个链接https://www.linuxidc.com/Linux/2017-03/141995.htm
搭建过程主要如下:
cacti是基于lamp或者lnmp,这里使用的是lamp架构,首先配置Apache
[root@cacti-server ~]# yum -y install httpd
[root@cacti-server ~]# systemctl start httpd
[root@cacti-server ~]# systemctl enable httpd
[root@cacti-server ~]# firewall-cmd --permanent --add-service=http
success
[root@cacti-server ~]# firewall-cmd --reload
配置mariadb,mariadb是mysql的一个分支,登录时还是要用mysql -u user -p命令
[root@cacti-server ~]# yum -y install mariadb-server mysql-devel
[root@cacti-server ~]# systemctl start mariadb
[root@cacti-server ~]# 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
[root@cacti-server ~]# mysql -u root -p
MariaDB [(none)]> grant all privileges on *.* to test@localhost identified by 'RedHat'; 创建用于测试php和mariadb连通性的用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
[root@cacti-server ~]# systemctl restart mariadb
[root@cacti-server ~]# systemctl enable mariadb
[root@cacti-server ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@cacti-server ~]# firewall-cmd --reload
success
配置php
[root@cacti-server ~]# yum -y install php php-mysql php-gd php-pear
[root@cacti-server ~]# vim /etc/php.ini
date.timezone =PRC 修改时区(这里要添加这条消息,不设置时区安装会报错)
[root@cacti-server ~]# 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()
?>
[root@cacti-server ~]# systemctl restart httpd
2.安装配置cacti
下载软件
[root@cacti-server ~]# cd /usr/local/src/
[root@cacti-server src]# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
[root@cacti-server src]# tar zxvf cacti-0.8.8f.tar.gz
[root@cacti-server src]# mv cacti-0.8.8f /var/www/html/cacti
也可以直接在官网上下载,shell上传就行,官网的版本已经是1.1.38了
创建cacti数据库和cacti用户,赋予权限
[root@cacti-server ~]# mysql -u root -p
MariaDB [(none)]> create database cacti default character set utf8;
MariaDB [(none)]> grant all privileges on cacti.* to cacti@localhost identified by 'redhat';
MariaDB [(none)]> flush privileges;
把cacti.sql导入数据库
[root@cacti-server cacti]# mysql -ucacti -predhat cacti < /var/www/html/cacti/cacti.sql
编辑config.php和global.php
[root@cacti-server 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以生成图像
[root@cacti-server src]# yum -y install rrdtool rrdtool-devel rrdtool-php rrdtool-perl
[root@cacti-server src]# yum -y install gd gd-devel php-gd ---rrdtool绘制图像需要的图形库
安装snmp服务
[root@cacti-server cacti]# yum -y install net-snmp net-snmp-utils php-snmp net-snmp-libs
编辑配置文件
[root@cacti-server ~]# 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
[root@cacti-server ~]# systemctl restart snmpd.service
[root@cacti-server ~]# systemctl enable snmpd.service
授权目录权限
[root@cacti-server ~]# useradd -r -M cacti
[root@cacti-server ~]# chown -R cacti /var/www/html/cacti/rra/
[root@cacti-server ~]# chown -R cacti /var/www/html/cacti/log/
这里必须给目录权限,不然安装时会报错。
做完以上步骤就可以登录http://IP_address/cacti来进行安装了,安装过程中必须的php模块一定要安装完,我用的是阿里云的yum源,却什么扩展就php-扩展名,就能安装下来了,还有一点就是mysql会报一个时区的错误,这个错误的解决办法如下:
登录到数据库,输入如下命令
grant select on mysql.time_zone_name to cacti@localhost identified by 'redhat';
flush privileges;
exit
/usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p
解决完这些后错误和安装PHP扩展模块就可以next了,一直next就行,基本的cacti就安装完成了,最后登录的初始化账户密码都是admin