由于cacti 1.1.x系列发布后,变化比较大,集成了很多插件,自带自动发现功能,所以记录下来,比较适合复制粘贴。
环境:CentOS 7.4
安装前提
a、安装系统补丁
yum update -y
b、开启ntp,保证时间正确
yum install chrony -y systemctl enable chronyd systemctl start chronyd
c、禁用selinux,重启生效
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config reboot
1、安装mariadb 10.1
cacti 1.1.0 需要mysql >= 5.6 ,所以这里选择mariadb 10.1
yum install centos-release-openstack-ocata -y yum install mariadb-server -y
2、mariadb参数调整(参考配置)
[mysqld] ...... character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci max_heap_table_size = 128M max_allowed_packet = 32M tmp_table_size = 64M join_buffer_size = 64M innodb_buffer_pool_size = 1024M innodb_doublewrite = off innodb_flush_log_at_timeout = 3
重启mariadb让配置生效
systemctl enable mariadb systemctl start mariadb
导入时区信息
mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root mysql
3、安装lamp
yum install httpd php php-mysqlnd php-mbstring php-ldap php-process php-gd php-snmp php-pecl-zendopcache php-xml wget net-snmp-utils rrdtool -y echo "ServerTokens Prod" >> /etc/httpd/conf/httpd.conf echo "ServerSignature Off" >> /etc/httpd/conf/httpd.conf sed -i 's/;date.timezone.*/date.timezone = PRC/g' /etc/php.ini mkdir -p /var/lib/php/session chown -R apache:apache /var/lib/php/session systemctl enable httpd systemctl start httpd
4、下载cacti
cd /var/wwww/html wget http://www.cacti.net/downloads/cacti-1.1.0.tar.gz tar zxvf cacti-1.1.0.tar.gz mv cacti-1.1.0 cacti cd cacti chown -R apache:apache resource scripts log cache
5、给cacti建库
mysql -u root -e "drop database if exists cacti" mysql -u root -e "delete from mysql.user where Host = 'localhost' and User = 'cactiuser'" mysql -u root -e "create database `cacti` default character set utf8mb4 collate utf8mb4_unicode_ci" mysql -u root -e "grant all on cacti.* to 'cactiuser'@'localhost' identified by 'cactiuser'" mysql -u root -e "grant select on mysql.time_zone_name to 'cactiuser'@'localhost'" mysql -u root -e "flush privileges" mysql -u root cacti < /var/www/html/cacti/cacti.sql
6、安装向导
访问http://ip/cacti 进入安装向导
7、修改密码
默认用户密码admin/admin,首次登陆要求改密码,密码长度和复杂度都比较严格,点赞。
8、定时任务
设置定时任务,在/etc/crontab 文件中添加一行
*/5 * * * * root /usr/bin/php -q /var/www/html/cacti/poller.php >/dev/null
9、配置自动发现(可选)
功能有点类似zabbix
a、定义snmp选项,比如snmp v2,community 为abc b、定义扫描网段,比如192.168.0.0/24,定时扫描,发现snmp端口存活的机器自动添加到cacti, c、定义规则,将扫描到的机器,按照操作系统分类,放入不同的tree,划不同的图
10、安装spine(可选)
spine是一个c写的程序,性能比默认的poller.php要高很多。
yum install gcc libtool make autoconf mysql-devel net-snmp-devel help2man wget -y wget tar zxvf cacti-spine-1.1.0.tar.gz cd cacti-spine-1.1.0 ./bootstrap ./configure --with-mysql make cp spine /usr/local/bin/ cp spine.conf.dist /etc/spine.conf
/etc/spine.conf文件里记得根据需要修改。
重装
如果需要重装,简单的删除数据库,重新初始化即可(第5-7步)
汉化
cacti 1.1.x 支持中文,但是汉化不彻底,手痒的同学可以按照下面的办法汉化:
1、安装
yum install gettext -y
2、反编译mo文件为po文件
cd /var/www/html/cacti/locales/LC_MESSAGES /usr/bin/msgunfmt chinese_china_simplified.mo -o chinese_china_simplified.po
3、用文本编辑器修改文件
4、编译po文件为mo文件
/usr/bin/msgfmt chinese_china_simplified.po -o chinese_china_simplified.mo