如何在Ubuntu 18.04上安装和配置cacti
在本教程中,我们将研究如何在Ubuntu 18.04上安装Cacti Server。
什么是 Cacti ?
CACTI是一个完全开源的网络监控和绘图工具,被设计为行业标准数据记录工具RRDTool的前端应用。
CACTI利用RRDTOOL数据存储和图形功能的力量。
Cacti 的一些很好的功能包括:用于多个数据采集方法的MetricsUpport的快速轮询,用于ACL的高级图形模板管理功能
CACTI提供了直观且易于使用的Web界面,可用于具有数千台服务器和网络设备的复杂网络的小LAN安装。
如何在Ubuntu 18.04上安装Cacti Server
Cacti在部署Cacti Server本身之前需要安装和配置许多依赖项。
本教程将逐个覆盖这些依赖项的安装:
第1步:更新系统并升级所有包
我们始终从服务器包升级开始以避免任何依赖性问题:
sudo apt-get update sudo apt-get upgrade
第2步:安装PHP和所需的模块
我们现在需要安装PHP和Cacti要求的一些PHP模块。
运行以下命令以获取所有内容并安装。
$sudo apt-get -y install php php-mysql php-curl php-net-socket \ php-gd php-intl php-pear php-imap php-memcache libapache2-mod-php \ php-pspell php-recode php-tidy php-xmlrpc php-snmp \ php-mbstring php-gettext php-gmp php-json php-xml php-common
最重要的模块是PHP-SNMP和PHP-MYSQL。
确保安装了它们。
我们可以使用命令查看PHP版本:
# php -v PHP 7.2.5-0ubuntu0.18.04.1 (cli) (built: Jan 9 2016 17:21:02) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.2.5-0ubuntu0.18.04.1, Copyright (c) 1999-2016, by Zend Technologies
确保设置正确的时区:
# grep date.timezone /etc/php/7.2/apache2/php.ini ; http://php.net/date.timezone date.timezone = "Africa/Nairobi"
第3步:安装Apache Web服务器
Cacti的默认推荐Web服务器是Apache,使用命令安装它:
sudo apt-get -y install apache2
安装Apache后,仅允许Prod ServerTokens配置基本安全性。
sudo vim /etc/apache2/conf-enabled/security.conf
改变第25行
ServerTokens Prod
此指令配置我们作为服务器HTTP响应所返回的内容。
有效选项已满| os |最小|次要|主要|刺激。
设置servername:
# grep ServerName /etc/apache2/apache2.conf ServerName cacti.theitroad.com
在问题上设置服务器管理员以接收电子邮件。
# grep ServerAdmin /etc/apache2/apache2.conf ServerAdmin Hyman@theitroad
如果我们已启用UFW,请在防火墙上打开HTTP和HTTPS端口。
# ufw allow http Rule added Rule added (v6 # ufw allow https Rule added Rule added (v6)
进行以下更改后,我们需要重新启动Apache Web服务:
sudo systemctl restart apache2
第3步:安装MariaDB服务器
在Ubuntu上安装MariaDB,请使用我的上一稿:
如何在Ubuntu 18.04和Centos 7上安装MariaDB
调整 Cacti 的Mariadb数据库
在文件/e/etc/mysql/mariadb.cnf上的[mysqld]下添加以下设置
max_heap_table_size=128M tmp_table_size=128M join_buffer_size=64M innodb_buffer_pool_size=512M innodb_doublewrite=OFF innodb_flush_log_at_timeout=3 innodb_read_io_threads=32 innodb_write_io_threads=16
重新启动MariaDB服务
sudo systemctl restart mysql
要检查这些设置中的任何一个,请使用MySQL SELECT语句,例如MYSQL SELECT语句。
MariaDB [(none)]> select @@tmp_table_size; +------------------+ | @@tmp_table_size | +------------------+ | 134217728 | +------------------+ 1 row in set (0.00 sec)
或者
MariaDB [(none)]> show variables like 'join_buffer_size';
完成数据库服务器后,我们需要为Cacti创建一个数据库:
$mysql -u root -p Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 56 Server version: 10.3.7-MariaDB-1:10.3.7+maria~bionic-log mariadb.org binary distribution Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database cacti; Query OK, 1 row affected (0.000 sec) MariaDB [(none)]> grant all privileges on cacti.* to Hyman@theitroad'localhost' identified by 'strongpassword'; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> exit Bye
测试数据库连接:
$mysql -u cacti_user -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 178 Server version: 10.1.29-MariaDB-6 Ubuntu 18.04 Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | cacti | | information_schema | +--------------------+ 2 rows in set (0.00 sec) MariaDB [(none)]>
第4步:安装SNMP和CACTI
最后一个包安装步骤适用于CACTI和SNMP包。
Cacti依赖于SNMP和RRDTool工具的功能。
使用命令安装这些包:
sudo apt-get install snmp snmpd snmp-mibs-downloader rrdtool cacti cacti-spine
当被要求选择Web服务器时,选择Apache。
+-------------------------+ Configuring cacti +--------------------------+ | Please select the web server for which Cacti should be automatically | | configured. | | | | Select "None" if you would like to configure the web server manually. | | | | Web server: | | | | apache2 | | lighttpd | | None | | | | | | <Ok> | | | +------------------------------------------------------------------------+
有关数据库配置,请为手动配置选择否,因为我们为Cacti创建了一个数据库
+---------------------------+ Configuring cacti +---------------------------+ | | | The cacti package must have a database installed and configured before | | it can be used. This can be optionally handled with dbconfig-common. | | | | If you are an advanced database administrator and know that you want to | | perform this configuration manually, or if your database has already | | been installed and configured, you should refuse this option. Details | | on what needs to be done should most likely be provided in | | /usr/share/doc/cacti. | | | | Otherwise, you should probably choose this option. | | | | Configure database for cacti with dbconfig-common? | | | | <Yes> <No> | | | +---------------------------------------------------------------------------+
等待安装完成,然后继续配置SNMP。
步骤5:配置SNMP
首先通过在/etc/snmp/snmp.conf上注释出下行来启用MIB的加载
改变
mibs :
到
# mibs :
通过编辑/etc/snmp/snmpd.conf配置SNMP社区名称
# On line 49 - Uncomment and change to the name of community string to any name you like. # This enable full access from localhost rocommunity theitroad localhost
通过评论以下方式缺陷公共访问:
rocommunity public default -V systemonly rocommunity6 public default -V systemonly
到
# rocommunity public default -V systemonly # rocommunity6 public default -V systemonly
重新启动SNMPD服务
sudo systemctl restart snmpd
使用SNMPWALK命令行工具验证SNMP配置:
$sudo snmpwalk -v 2c -c theitroad localhost system SNMPv2-MIB::sysDescr.0 = STRING: Linux cacti 4.15.0-22-generic #24-Ubuntu SMP Wed Jan 16 12:15:17 UTC 2016 x86_64 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (11034) 0:01:50.34 SNMPv2-MIB::sysContact.0 = STRING: Me <Hyman@theitroad> SNMPv2-MIB::sysName.0 = STRING: cacti SNMPv2-MIB::sysLocation.0 = STRING: Sitting on the Dock of the Bay SNMPv2-MIB::sysServices.0 = INTEGER: 72 SNMPv2-MIB::sysORLastChange.0 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDCompliance SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup SNMPv2-MIB::sysORID.6 = OID: TCP-MIB::tcpMIB SNMPv2-MIB::sysORID.7 = OID: IP-MIB::ip SNMPv2-MIB::sysORID.8 = OID: UDP-MIB::udpMIB SNMPv2-MIB::sysORID.9 = OID: SNMP-NOTIFICATION-MIB::snmpNotifyFullCompliance SNMPv2-MIB::sysORID.10 = OID: NOTIFICATION-LOG-MIB::notificationLogMIB SNMPv2-MIB::sysORDescr.1 = STRING: The MIB for Message Processing and Dispatching. SNMPv2-MIB::sysORDescr.2 = STRING: The management information definitions for the SNMP User-based Security Model. SNMPv2-MIB::sysORDescr.3 = STRING: The SNMP Management Architecture MIB. SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities SNMPv2-MIB::sysORDescr.5 = STRING: View-based Access Control Model for SNMP. SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing TCP implementations SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing IP and ICMP implementations SNMPv2-MIB::sysORDescr.8 = STRING: The MIB module for managing UDP implementations SNMPv2-MIB::sysORDescr.9 = STRING: The MIB modules for managing SNMP Notification, plus filtering. SNMPv2-MIB::sysORDescr.10 = STRING: The MIB module for logging SNMP Notifications. SNMPv2-MIB::sysORUpTime.1 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.2 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.3 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.4 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.5 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.6 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.7 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.8 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.9 = Timeticks: (1) 0:00:00.01 SNMPv2-MIB::sysORUpTime.10 = Timeticks: (1) 0:00:00.01
请记住使用社区字符串的名称替换OniTor。
步骤6:配置CACTI Server
从其中我们必须为cacti配置数据库设置并在Web界面上启动安装程序。
更改文件/usr/share/cacti/site/include/config.php上的db设置。
# On line 49 - Change cacti database connection info $database_type = "mysqli"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti_user"; $database_password = "strongpassword"; $database_port = "3306"; $database_ssl = false;
用我们在步骤3中创建的数据库用户替换CACTI_USER,并使用CACTIA数据库用户密码创建的数据库用户。
导入Cacti MySQL数据库模式:
$mysql -u cacti_user -p cacti < /usr/share/doc/cacti/cacti.sql Enter password:
用数据库名称替换与数据库用户和cacti的cacti_user。
设置CACTI数据库用户的MySQL TimeZone
# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql Enter password: Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Grant Cacti MySQL数据库用户访问TimeZone数据库:
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 202 Server version: 10.1.29-MariaDB-6 Ubuntu 18.04 Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO Hyman@theitroad; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye
配置Cacti Apache站点访问控制(可选):
如果我们想限制对Cacti Web界面的访问,请编辑文件/etc/apache2/conf-available/cacti.conf并注释出线路:
Require all granted
然后配置如下:
# Change line 7 #Require all granted Require host localhost Require ip 192.168.1.0/24
用可信子网替换192.168.1.0/24.
我们还可以添加以下单独的IP:
Require ip 192.168.1.20 Require ip 172.16.20.30
我们需要在进行上述修改后重新启动Apache服务,
$sudo systemctl restart apache2
设置目录权限
sudo chown -R www-data:www-data /opt/cacti/
第7步:启动初始CACTI设置
打开我们喜欢的Web浏览器,并从CACTI服务器授权的客户端系统中导航到"http://(cacti服务器的主机名或者IP地址)/cacti /"。
勾选接受GPL许可协议,然后单击"开始"按钮继续。
Cacti 将检查是否满足所有要求。
根据警告级别,我们可能需要进行一些更改。
单击"下一步"按钮进入下一阶段。
我们将被要求选择Server安装类型:新主服务器 - 为主站点选择此项.New Remote Louser - 远程轮询器用于访问未容易地访问主站点的网络。
由于这是我们的第一台服务器,因此选择"新主服务器",然后单击"下一步"
确认所有二进制文件都在找到并单击"下一步"。
请注意安装后需要在安装后具有只读权限的目录,然后单击"下一步"。
我们现在正在最后阶段,通过单击"完成"按钮完成安装以获取登录页面。
默认登录是:
username: admin Password: admin
当提示更改管理员用户的密码时,提供新的密码并确认。
然后我们将访问Cacti接口,如下所示
第8步:监视本地CACTI服务器
添加本地Cacti服务器以进行监视。
登录Cacti作为管理员用户并转到:
控制台>设备> +(添加设备)
填写服务器详细信息并向下滚动,然后单击"保存"按钮。