Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。它通过SNMP来获取数据,使用 RRDtool绘画图形,本文介绍如何在CentOS 7上安装Cacti 1.2
将SELinux设置为permissive模式sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/configreboot
安装EPEL库rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
安装SNMP和RRDToolyum -y install net-snmp net-snmp-utils net-snmp-libs rrdtool
安装PHPCentos 7的初始PHP版本不符合Cacti的最低要求,因此我们安装PHP 7.3版本。
- 安装Remi库yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
- 安装PHP 7.3yum install -y --enablerepo=remi-php73 php php-xml php-session php-sockets php-ldap php-gd php-gmp php-intl php-mbstring php-mysqlnd php-pdo php-process php-snmp
安装MariaDBCentos 7预装的MariaDB 5.4不符合Cacti的最低要求,这里我们安装MariaDB官方最新版本,直接复制下框所有命令设置安装源:
cat <<EOF>> /etc/yum.repos.d/mariadb.repo[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.4/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1EOF
使用如下命令安装:
yum install -y MariaDB-server MariaDB-client
数据库优化编辑MariaDB配置文件:
vi /etc/my.cnf.d/server.cnf
修改[mysqld]参数如下:
collation-server = utf8mb4_unicode_cicharacter-set-server=utf8mb4max_heap_table_size = 64Mtmp_table_size = 64Mjoin_buffer_size = 64Minnodb_file_format = Barracudainnodb_large_prefix = 1innodb_flush_log_at_timeout = 3innodb_buffer_pool_size = 1GBinnodb_buffer_pool_instances = 10# Based on what type for storage you use. The below values are for SSD drives.# Change it if Cacti reports issues during the installationinnodb_read_io_threads = 32innodb_write_io_threads = 16innodb_io_capacity = 5000innodb_io_capacity_max = 10000
启用服务systemctl start httpd snmpd mariadbsystemctl enable httpd snmpd mariadb
创建Cacti数据库- MariaDB初始化mysql_secure_installation
按照提示设定数据库root用户密码及完成其它设置(都可以选择默认)。
安装Cactiyum安装cacti
yum -y install cacti
将默认数据库导入到cacti数据库
mysql cacti < /usr/share/doc/cacti-*/cacti.sql -u root -pEnter password:*******
编辑数据库配置文件
vi /usr/share/cacti/include/config.php
设定名称,主机名,用户和密码信息
/* make sure these values reflect your actual database/host/user/password */$database_type = "mysql";$database_default = "cacti";$database_hostname = "localhost";$database_username = "cactiuser";$database_password = "cactipassword";$database_port = "3306";$database_ssl = false;
编辑crontab文件
vi /etc/cron.d/cacti
取消注释以下条目以实现每五分钟轮询一次(删掉该条目前面的#号)
*/5 * * * * apache /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
编辑/etc/php.ini文件设置时区
vi /etc/php.ini
更新时区
date.timezone = Aisa/Shanghai #需要删除前面的;号memory_limit = 512Mmax_execution_time = 60
编辑Apache配置文件
vi /etc/httpd/conf.d/cacti.conf
把Require host localhost修改为Require all granted,修改前:
<Directory /usr/share/cacti/> <IfModule mod_authz_core.c> # httpd 2.4 Require host localhost </IfModule> <IfModule !mod_authz_core.c> # httpd 2.2 Order deny,allow Deny from all Allow from localhost </IfModule></Directory>
修改后:
<Directory /usr/share/cacti/> <IfModule mod_authz_core.c> # httpd 2.4 Require all granted </IfModule> <IfModule !mod_authz_core.c> # httpd 2.2 Order deny,allow Deny from all Allow from localhost </IfModule></Directory>
安装cacti-spine由于效率的原因,在需要大量采集数据时,如果使用自带的cmd.php轮询器会比较慢,1分钟1次的采集频率可能无法完成轮询所有的被监控的机器,从而可能导致部分监控项目不出图或图形断断续续。为了解决效率问题,Cacti官方也推出spine,采用多线程的方式高效的轮询。
- 安装spineyum -y install cacti-spine
- 设置spinevi /etc/spine.conf
填写主机名,用户和密码信息
DB_Host localhostDB_Database cactiDB_User cactiuserDB_Pass cactipasswordDB_Port 3306
重新启动服务systemctl restart httpd snmpd mariadb
设定防火墙firewall-cmd --permanent --add-service=httpfirewall-cmd --reload
设置cacti打开浏览器输入http://your-ip-address/cacti登陆后按照安装向导完成Cacti安装。默认密码为admin/admin
安装完成后,记得在[系统设置] -> [设置] -> [Poller]选项卡下将采集类型由cmd修改为spine。
其它Cacti 1.2.11有一个小bug,输入用户名和密码无法登陆,打开php配置文件,注释掉如下内容即可(在前面加#号):
vi /usr/share/cacti/include/config.php # $cacti_cookie_domain = 'cacti.net';