CentOS7.6安装Cacti1.1.38
温馨提示:这篇文章已超过741天没有更新,请注意相关的内容是否还可用!
通过部署Cacti能够对公司的交换机、路由器及服务器进行监控。从而实时了解决各类设备的运行状态,如内存当前使用率,磁盘使用情况,网卡流量等,更重要的是可以监控公司核心交换机各接口流量,从而当大的网络环境出现问题时,如:有人大流量发包,有人发送ARP,有人下载大文件,导致整个网络非常卡时,都可以通过Cacti查看各个接口带宽的使用情况,判断问题所在
教程架构分布图
Cacti监测对象
(一) 能够监控服务器的CPU负载、内存使用率、磁盘空间及使用率、进程数、连接数。
(二) 能够监控Web(可用性、网站速率对比)、Mail、FTP、数据库、中间件。
(三) 能够监控路由器、交换机及服务器的接口流量(进与出的带宽)、转发速率、丢包率。
(四) 能够监控网络设备性能、配置文件(对比与备份)、路由数。
(五) 能够监控安全设备性能、连接数、攻击数。
(六) 能够监控设备运行状态:风扇、电源、温度。
(七) 它可以提供邮件和手机短信报警功能,我们可以在cacti中对每个监控项定义阀值,当Cacti监控到超过阀值时,会产生相
应报警日志发送到你指定的邮箱和手机上。
Cacti安装环境配置
配置MariaDB官方yum源,这里安装mariadb10.3.5版本:
# vim /etc/yum.repos.d/MariaDB.repo [mariadb] name=MariaDB baseurl=http://yum.mariadb.org/10.3.5/centos74-amd64/ gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
安装mariadb server和mariadb client
# yum install -y MariaDB-server MariaDB-client MariaDB-devel
安装httpd和php
# yum install -y httpd php
安装php扩展
# yum install -y php-mysql php-snmp php-xml php-ldap php-gd php-mbstring php-posix
安装net-snmp简单网络管理协议
# yum install -y net-snmp net-snmp-libs net-snmp-utils net-snmp-devel net-snmp-perl
安装RRDTool 绘图工具
# yum install -y rrdtool rrdtool-devel rrdtool-php rrdtool-perl perl-devel perl-CPAN perl-YAML
启动httpd服务并设为开机启动
# systemctl start httpd && systemctl enable httpd
配置PHP
# vi /etc/php.ini
date.timezone = Asia/Shanghai
测试php与apache解析是否正常,创建php测试页面
# vi /var/www/html/index.php
<?php phpinfo();?>
关闭防护墙
停止使用: systemctl stop firewalld 停用 。
禁止开机启动 :systemctl disable firewalld
配置MYSQL
启动mysql数据库服务并设为开机启动
# systemctl start mariadb && systemctl enable mariadb
初始化MariaDB数据库,主要创建mysql数据库密码,然后全部Y下一步:
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): //当前数据库密码为空,直接按回车键 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y //输入要为root管理员设置的密码(数据库root非linux root) New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y //删除匿名账号 ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y //禁止root管理员从远程登录 ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y //删除test数据库并取消对它的访问权限 - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y //刷新授权表,让初始化后的设定立即生效 ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
修改mysql配置文件,在[server]下增加如下内容
[server] # this is only for the mysqld standalone daemon character_set_server = utf8mb4 collation-server = utf8mb4_unicode_ci max_heap_table_size = 256M max_allowed_packet = 16777216 tmp_table_size = 64M join_buffer_size = 64M innodb_file_per_table = ON innodb_buffer_pool_size = 1024M innodb_doublewrite = OFF #innodb_additional_mem_pool_size = 96M innodb_flush_log_at_timeout = 3 innodb_read_io_threads = 32 innodb_write_io_threads =16
配置SNMP
//修改default为本机ip,修改public为自己的团体名(可以不改),42行
com2sec notConfigUser default public
//把systemview改成all ,供所有snmp 访问权限 64行
access notConfigGroup "" any noauth exact all none none
//去掉此行注释
view all included .1 80 // 去掉#号 85行
重启snmp服务
# systemctl restart snmpd.service && systemctl enable snmpd.service
本机测试snmp数据(修改monit为配置的团体名),查看是否能够获取数据
# snmpwalk -v 2c -c public localhost system
安装和配置cacti
官网下载:https://www.cacti.net/downloads/cacti-1.1.38.tar.gz
1、下载Cacti 安装包
# wget https://www.cacti.net/downloads/cacti-1.1.38.tar.gz # tar -zxvf cacti-1.1.38.tar.gz # cp -R cacti-1.1.38 /var/www/html/cacti
2.创建 cacti 数据库
创建cacti数据库,创建数据库用户cactiuser,设置用户相关授权
# mysql -u root -p
MariaDB [(none)]> create database cacti; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all on cacti.* to cactiuser@localhost identified by "cactiuser"; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser'; Query OK, 0 rows affected (0.00 sec) MariaDB [cacti]> flush privileges; Query OK, 0 rows affected (0.00 sec)
注意这里的数据库用户名密码全部为cactiuser,可以自定义。
3.导入 Cacti 默认数据库
MariaDB [(none)]> use cacti; Database changed MariaDB [cacti]> source /var/www/html/cacti/cacti.sql; MariaDB [cacti]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [cacti]> quit Bye
4.配置数据库时区:
# mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysql Enter password: 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.
5. 创建cacti配置文件config.php
主要修改数据库用户名密码,和cacti路径,这里全部默认,根据刚才上面的配置进行修改
# vi /var/www/html/cacti/include/config.php
#……………… $database_type = 'mysql'; $database_default = 'cacti'; $database_hostname = 'localhost'; $database_username = 'cactiuser'; $database_password = 'cactiuser'; $database_port = '3306'; $database_ssl = false; #…………… $url_path = '/cacti/';
6.创建站点目录权限
# chown -R apache.apache /var/www/html/cacti/ # chmod -R 777 /var/www/html/cacti/
7. 添加定时任务
将每5分钟执行一次的数据获取脚本加入crontab
# crontab -e */5 * * * * cactiuser php /var/www/html/cacti/poller.php > /dev/null 2>&1
8.重新启动相关服务
# systemctl restart httpd && systemctl restart mariadb # systemctl restart crond && systemctl restart snmpd
安装spine
cacti默认使用cmd.php来轮询数据,速度会很慢,因此我们采用Spine来轮询数据。cacti-spine是一个由C语言开发的,用于替代cmd.php的快速获取速度的引擎。(也可以不装)
安装spine高速数据采集插件
1、安装spine高速数据采集插件
# wget https://www.cacti.net/downloads/spine/cacti-spine-1.1.38.tar.gz
# yum install -y mysql-devel dos2unix autoconf automake binutils libtool gcc cpp glibc-headers glibc-devel help2man
# tar zxvf cacti-spine-1.1.38.tar.gz
# cp -R cacti-spine-1.1.38 /usr/local/spine
# cd /usr/local/spine
# ln -s /usr/lib64/libmysqlclient.so.18.0.0 /usr/lib64/libmysqlclient.so
# sh bootstrap
# ./configure
# 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
修改/etc/spine.conf如下部分:
# vi /etc/spine.conf
DB_Host localhost DB_Database cacti DB_User cactiuser DB_Pass cactiuser DB_Port 3306
进行初始化:
# /usr/local/spine/bin/spine //执行此命令,成功后显示如下
初始化cacti
重启httpd服务,在浏览器访问:http://ip/cacti,进入安装界面。
检查各个模块时,可能有部分错误,自行排查
安装前检查:
php moduel检查
数据库配置检查
根据提示进行对应目录权限的配置,将相应目录给予httpd对应用户相应的读写权限,刷新浏览器后,点Next继续:
选择需要加载的模板,我这里全选
Cacti监控使用
登陆cacti
初次登录默认用户密码为admin/admin
重设密码,admin/你要的密码
成功登陆
登录后,在Console–>Configuration–>Settings–>Paths下配置spine路径:
在Console–>Configuration–>Settings–>Poller下,将Poller Type改为spine,也可以在这里修改数据收集时间间隔: