系统:CentOS 7.8
一、安装前准备
1.关闭Selinux
#vi /etc/selinux/config
找到
SELINUX=enforcing
改成
SELINUX=disabled
2.关闭防火墙或者开放80端口
关闭防火墙
#systemctl stop firewalld
#systemctl disable firewalld
开放80端口
#开启端口
#firewall-cmd --zone=public --add-port=80/tcp --permanent
#重启防火墙
#firewall-cmd --reload
#查看开放的端口
#firewall-cmd --list-port
3.更新yum源
#备份repo文件
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#进入yum源配置目录
#cd /etc/yum.repos.d/
#根据CentOS版本下载对应的新源
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#yum makecache 生成缓存,把新下载CentOS-Base.repo源生效
#yum makecache
#执行yum源更新命令
#yum clean all
#yum makecache
#yum -y update
4.安装Cacti所依赖的环境
注意:CentOS7默认的数据库是Mariadb而非MySQL,所以我们需要单独在官网下载安装MySQL。
#1.安装MySQL
#wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
#rpm -ivh mysql-community-release-el7-5.noarch.rpm
#yum -y install mysql mysql-server mysql-devel
#2.安装其他依赖
#yum -y install httpd php php-mysql zlib freetype libjpeg fontconfig libxml2 gd php-gd php-ldap php-mbstring php-posix php-snmp rrdtool net-snmp net-snmp-utils
#启动服务
#systemctl start httpd snmpd mysqld
#开机自启
#systemctl enable httpd snmpd mysqld
二、Cacti+Spine搭建
1.安装Cacti
1.登录Cacti官网
#下载1.2.2版本
#cd /var/www/html
#wget https://www.cacti.net/downloads/cacti-1.2.2.tar.gz
#tar -zxvf cacti-1.2.2.tar.gz -C /var/www/html #解压到http服务目录
#mv cacti-1.2.2 cacti #重命名路径
#chown -R root:root /var/www/html/cacti/
#chmod -R 777 /var/www/html/cacti/
#useradd cacti
#chown -R cacti:cacti /var/www/html/cacti/log/
#chown -R cacti:cacti /var/www/html/cacti/rra/
2.编辑Web页面数据配置文件
#vim /var/www/html/cacti/include/config.php
#修改database的用户名和密码
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti';
$database_password = 'cacti';
$database_port = '3306';
$database_ssl = false;
3.创建MySQL数据库相关存储信息
#登录数据库
#mysql -uroot -p
mysql> create database cacti default character set utf8; #创建数据库设置字符集
mysql> grant all on cacti.* to 'cacti'@'localhost' identified by 'cacti'; #赋权
mysql> flush privileges; #刷新
mysql> exit;
4.修改php配置和导入sql文件
#vim /etc/php.ini
#找到date.timezone取消注释并修改成如下
date.timezone = "Asia/Shanghai"
#systemctl restart httpd #修改完重启下httpd服务
#mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql
#yum install -y ntp #安装ntpdate
#ntpdate asia.pool.ntp.org #同步时间
2.安装Spine
#wget https://www.cacti.net/downloads/spine/cacti-spine-1.2.2.tar.gz
#tar zxvf cacti-spine-1.2.2.tar.gz
#mv cacti-spine-1.2.2 /usr/local/spine
#cd /usr/local/spine
#yum install -y net-snmp-devel mysql-devel openssl-devel dos2unix autoconf automake binutils libtool gcc cpp glibc-headers kernel-headers glibc-devel help2man
#sh bootstrap
#./configure --with-reentrant
#make
#make install
#chown root:root /usr/local/spine/bin/spine
#chmod +s /usr/local/spine/bin/spine
#编辑spine.conf:
#cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
#vim /etc/spine.conf #修改如下部分
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
#/usr/local/spine/bin/spine //执行此命令,成功后显示如下
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 1.2.2 starting
SPINE: Time: 0.0225 s, Threads: 1, Devices: 0
使用crontab命令添加任务
#crontab -e
#添加以下任务,我这里配置成每五分钟运行一次
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
添加好crontab计划任务后,验证下crond服务是否已经启动,并设置开机自启
#systemctl status crond
#systemctl enable crond
三、设置Cacti
打开浏览器输入:ip地址/cacti 进入到安装界面
如果有错误提示:System log file is not available for writing,please enable write access Log:/var/www/html/cacti/log/cacti.log
解决方法如下:
#touch /var/www/html/cacti/log/cacti.log
#chmod -R 777 /var/www/html/cacti/log
#chmod -R 777 /var/www/html/cacti/log/cacti.log
刷新浏览器进入到用户登录界面,默认账号密码都是:admin
第一次登录还会提示修改密码,按照要求修改即可。
选择主题和语言后点开始:
接下来发现有几个报错:
先解决MySQL时区错误的问题。
#登录MySQL执行以下内容
#mysql -uroot -p
mysql> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost IDENTIFIED BY 'cacti';
mysql> flush privileges;
mysql> exit;
#/usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -uroot -p mysql
刷新浏览器,时区报错就没有了。
接下来再解决检测未通过的选项:
修改 /etc/my.cnf 在[mysqld]后添加如下内容:
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
max_allowed_packet = 16777216
max_heap_table_size = 128M
tmp_table_size = 128M
join_buffer_size = 256M
innodb_buffer_pool_size = 1901M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
innodb_buffer_pool_instances =16
再重启MySQL并刷新Cacti页面就可以点击下一页了
这一步根据提示对应修改下:
#vim /etc/my.cnf #在[mysqld]下添加这两句
#character-set-server=utf8mb4
#collation-server=utf8mb4_unicode_ci
#mysql -uroot -p #再进入数据库运行这句
mysql> ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
重启MySQL再刷新页面点击下一页
安装完成后需要在设置里修改下Poller轮询器,修改为Spine;不然在Cacti图形监控页,全部会显示The Cacti Poller has not run yet.
选择系统配置→设置→Poller→采集类型选择spine→保存
整个安装过程到这里就完成了,之后在被监控端配置snmp然后添加上去Cacti里就可以监控了。