Cacti1.2.x新版教程之安装部署
本篇教程基于Cacti1.2.2版本验证,其他版本自测!
Cacti坑确实很多,官方也是偶尔突然更新下,老牌的监控软件也就这么没落了,另外Cacti真的很不安全,强烈建议部署在内网里!
文中所用的包组,来自于wlnmp一键包,强烈建议按照文中配置进行安装,别上来就改来改去,最后各种报错。
如果要进行版本升级,一定要做好数据备份,Cacti升级失败的风险还是比较大的~
原来本文是以php7.2为例,后续再使用中发现cacti偶尔会在php7.2下报错,因为有些函数兼容性问题,所以不建议使用php7.2或php7.3版本来运行cacti。
本文在Centos7.x系统上运行,当前php使用7.1版本,mysql使用5.7版本,注意内存要大于2G!!!
请使用Centos7.x系统环境,本教程目前不适用于Centos8.x
请自行关闭防火墙,关闭selinux,或自行配置放行规则
1、添加epel源
yum install epel-release
2、添加wlnmp一键包源
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
3、安装nginx、php、mysql
yum install wnginx wphp71 wmysql57
4、安装php扩展及其他所需依赖
yum install wphp71-ldap wphp71-snmp wrrdtool wnet-snmp wspine-1.2.2 sendmail
5、设置两个软链接
ln -sv /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20
ln -sv /usr/local/mysql/lib/libmysqlclient.so /usr/lib64/libmysqlclient.so
6、取消被禁用的php函数
vi /usr/local/php/etc/php.ini
找到disable_functions行,删除shell_exec,exec,popen,保存退出,重启php服务
注:按ESC,再按:wq即可保存退出
/etc/init.d/php-fpm71 restart
7、启动相关服务
/etc/init.d/nginx restart
/etc/init.d/mysql restart
/etc/init.d/snmpd restart
8、修改MySQL密码(默认为空)
修改默认MySQL密码,创建cacti数据库,并添加相应权限
mysql -uroot -p
mysql> set password = password('whsir');
mysql> CREATE DATABASE cacti DEFAULT CHARACTER SET utf8;
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'blog.whsir.com';
mysql> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost IDENTIFIED BY 'blog.whsir.com';
mysql> ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql> flush privileges;
mysql> quit
9、加载时区到mysql数据库
/usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -uroot -pwhsir mysql
加载时区后看到以下内容
mysql: [Warning] Using a password on the command line interface can be insecure.
Warning: Unable to load '/usr/share/zoneinfo//iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo//leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo//tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo//zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo//zone1970.tab' as time zone. Skipping it.
10、下载cacti
网络不佳的情况下,强烈建议先下载到本地,再上传到服务器
mkdir /data/www
cd /data/www
wget https://www.cacti.net/downloads/cacti-1.2.2.tar.gz
tar xf cacti-1.2.2.tar.gz
mv cacti-1.2.2 cacti
11、修改cacti数据库配置文件
cd /data/www/cacti/include
vi config.php
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti';
$database_password = 'blog.whsir.com';
$database_port = '3306';
$database_ssl = false;
12、导入cacti.sql
mysql -uroot -pwhsir cacti < /data/www/cacti/cacti.sql
touch日志文件,后续安装时用的到
touch /data/www/cacti/log/cacti.log
touch /data/www/cacti/log/cacti_stderr.log
13、做一些软链,后续安装用的到
ln -sv /usr/local/rrdtool/bin/rrdtool /usr/local/bin/rrdtool
ln -sv /usr/local/php/bin/php /usr/bin/php
ln -sv /usr/local/snmp/bin/snmpwalk /usr/local/bin/snmpwalk
ln -sv /usr/local/snmp/bin/snmpget /usr/local/bin/snmpget
ln -sv /usr/local/snmp/bin/snmpbulkwalk /usr/local/bin/snmpbulkwalk
ln -sv /usr/local/snmp/bin/snmpgetnext /usr/local/bin/snmpgetnext
ln -sv /usr/local/snmp/bin/snmptrap /usr/local/bin/snmptrap
14、修改cacti目录权限
chown -R www:www /data/www/cacti/
15、修改nginx配置
vi /usr/local/nginx/conf/vhost/demo.conf
修改root路径为root /data/www;,取消php注释include enable-php71.conf;,修改下server_name为本机IP,或者自己填个域名,自行hosts,不做过多说明!
16、重启nginx服务
nginx -t
/etc/init.d/nginx restart
17、spine配置
spine是一个基于C语言的,非常快速的轮询引擎,它是默认的cmd.php的可选替代,如果要使用spine需要单独的设置
cd /usr/local/spine/etc
cp spine.conf.dist spine.conf
vi spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass blog.whsir.com
DB_Port 3306
验证一下
/usr/local/spine/bin/spine
返回以下内容表示成功
SPINE: Using spine config file [spine.conf]
SPINE: Version 1.2.2 starting
SPINE: Time: 1.0244 s, Threads: 1, Devices: 1
18、进入web安装
注意:如果访问有问题,修改后建议清空下浏览器缓存,或直接开浏览器隐身模式,以防有缓存
http://IP/cacti
默认账号密码admin,第一次登陆后会提示更改密码
安装向导检查,根据检查结果,自行更改php.ini和my.cnf文件,更改后记得重启,如相关参数在配置中不存在,手动添加即可
vi /etc/my.cnf
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
/etc/init.d/mysql restart
配置crontab,不然不出图
crontab -e
#添加下面一行,一分钟运行一次
*/1 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
systemctl status crond
systemctl enable crond
yum install perl-devel perl-CPAN perl-YAML
perl -MCPAN -e shell#
install LWP::UserAgent