此篇文章全部通过yum方式,在全新的Centos 6.7上安装Cacti监控,本文中所有内容都经过博主测试。
当前系统环境介绍:
服务器是通过VMware12安装的Centos6.7版本,IP地址为192.168.0.70,yum默认安装mysql版本5.1、php5.3、Apache2.2。
1、安装环境包
首先要确认当前服务器是否关闭iptables和selinux(不会关闭的自行网上搜索,这里不再阐述)
先安装epel-release软件包(不装这个包是无法yum直接安装cacti的)
[root@localtest ~]#yum install epel-release
|---|------------------------------------------------| | 1 | [root@localtest ~]#yum install epel-release |
清理下缓存
[root@localtest ~]#yum clean all
|---|-------------------------------------| | 1 | [root@localtest ~]#yum clean all |
显示可用的yum仓库
[root@localtest ~]#yum repolist
|---|------------------------------------| | 1 | [root@localtest ~]#yum repolist |
注意:如果报错的话查下/etc/yum.repos.d下的epel文件中#baseur是否被注释掉了,如果被注释掉的话是无法直接用yum安装cacti的,并注释掉#mirrorlist行
yum安装apache、mysql、php、snmp、rrdtool、cacti
[root@localtest ~]#yum install -y httpd mysql mysql-server mysql-devel php php-mysql php-snmp php-gd net-snmp* rrdtool cacti
|---|----------------------------------------------------------------------------------------------------------------------------------| | 1 | [root@localtest ~]#yum install -y httpd mysql mysql-server mysql-devel php php-mysql php-snmp php-gd net-snmp* rrdtool cacti |
2、启动服务
[root@localtest ~]#service httpd start [root@localtest ~]#service mysqld start [root@localtest ~]#service snmpd start
|-------|--------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | [root@localtest ~]#service httpd start [root@localtest ~]#service mysqld start [root@localtest ~]#service snmpd start |
3、添加开机自启
[root@localtest ~]#chkconfig httpd on [root@localtest ~]#chkconfig mysqld on [root@localtest ~]#chkconfig snmpd on
|-------|-----------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | [root@localtest ~]#chkconfig httpd on [root@localtest ~]#chkconfig mysqld on [root@localtest ~]#chkconfig snmpd on |
4、更改mysql密码(我这里密码就改成whsir了)
[root@localtest ~]#mysqladmin -uroot password 'whsir'
|---|----------------------------------------------------------| | 1 | [root@localtest ~]#mysqladmin -uroot password 'whsir' |
5、登录mysql,创建cacti库并赋予权限
(注意:此处创建库一定指定编码,这是大坑啊,不指定编码的话会报ERROR 1071 (42000) at line 1916: Specified key was too long; max key length is 1000 bytes)
[root@localtest ~]#mysql -uroot -pwhsir
|---|--------------------------------------------| | 1 | [root@localtest ~]#mysql -uroot -pwhsir |
mysql>CREATE DATABASE cacti DEFAULT CHARACTER SET utf8; mysql>GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cactimima'; mysql>flush privileges; mysql>exit
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | mysql>CREATE DATABASE cacti DEFAULT CHARACTER SET utf8; mysql>GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cactimima'; mysql>flush privileges; mysql>exit |
6、修改cacti config.php文件
[root@localtest ~]#vim /usr/share/cacti/include/config.php
|---|---------------------------------------------------------------| | 1 | [root@localtest ~]#vim /usr/share/cacti/include/config.php |
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "cactimima"; $database_port = "3306"; $database_ssl = false;
|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 | $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "cactimima"; $database_port = "3306"; $database_ssl = false; |
7、将cacti.sql导入数据库
[root@localtest ~]#mysql -uroot -pwhsir cacti < /usr/share/doc/cacti-0.8.8h/cacti.sql
|---|-------------------------------------------------------------------------------------------| | 1 | [root@localtest ~]#mysql -uroot -pwhsir cacti < /usr/share/doc/cacti-0.8.8h/cacti.sql |
8、设置允许外部连接
更改httpd配置文件,将Deny from all改成Allow from all(如果不允许外部连接的话,只能在linux本机访问,如下图)
[root@localtest ~]#vim /etc/httpd/conf.d/cacti.conf
|---|--------------------------------------------------------| | 1 | [root@localtest ~]#vim /etc/httpd/conf.d/cacti.conf |
修改成功后重启Apache
[root@localtest ~]#service httpd restart
|---|---------------------------------------------| | 1 | [root@localtest ~]#service httpd restart |
此时可直接访问http://192.168.0.70/cacti/install/
如果访问不了,注意是否是防火墙问题。
直接Next
此处有个问题,cacti的日志路径,如果不填写的话默认路径是/log/cacti.log
默认账户密码都是admin,登录后会提示你修改一次密码,我这里就直接改成123456了