在 CentOS 8 上安装 Cacti 服务器

在 CentOS 8 上安装 PHP

Cacti 是用 PHP 编程语言开发的,因此它需要一个支持 PHP 的 Web 服务器才能运行。

[root@centos8.onitroad.com ~]# dnf install -y php-fpm php-common php-mysqlnd php-xml php-ldap php-json php-cli php-gd php-gmp php-mbstring php-process

启用并启动 PHP-FPM 服务。

[root@centos8.onitroad.com ~]# systemctl enable --now php-fpm.service
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service -> /usr/lib/systemd/system/php-fpm.service.

在 CentOS 8 上安装 Cacti

我们正在从他们的官方网站下载最新的 Cacti 稳定版本。

[root@centos8.onitroad.com ~]# cd /tmp
[root@centos8.onitroad.com tmp]# wget https://www.cacti.net/downloads/cacti-1.2.12.tar.gz

将下载的 tar包 解压缩到默认的 DOCUMENT_ROOT 中。

[root@centos8.onitroad.com tmp]# tar -C /var/www/html -xzf cacti-1.2.12.tar.gz
[root@centos8.onitroad.com tmp]# cd

将 Cacti 目录重命名为一个简单的名称,以便于访问。

[root@centos8.onitroad.com ~]# mv /var/www/html/cacti-1.2.12 /var/www/html/cacti

在 CentOS 8 上安装 MariaDB 服务器

Cacti 需要一个 MySQL 数据库作为其元数据存储库。
这里我们使用 MariaDB 数据库服务器。

[root@centos8.onitroad.com ~]# dnf install -y mariadb-server

启用并启动 MariaDB 数据库服务。

[root@centos8.onitroad.com ~]# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service -> /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service -> /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service -> /usr/lib/systemd/system/mariadb.service.

配置 MariaDB Server 并设置 root 用户的密码。

[root@centos8.onitroad.com ~]# 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
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
 ... 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
 - 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!

在 CentOS 8 上为 Cacti 配置 SELinux

使用 dnf 命令安装所需的 SELinux 命令,例如:semanage。

[root@centos8.onitroad.com ~]# dnf install -y policycoreutils-python-utils-2.9-9.el8.noarch

配置 SELinux 以允许对以下目录进行读/写。

[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/log(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/snmp_queries(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_server(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_queries(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/scripts(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/boost(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/mibcache(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/realtime(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/spikekill(/.*)?"
[root@centos8.onitroad.com ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/rra(/.*)?"

重新应用 cacti 目录上的文件上下文。

[root@centos8.onitroad.com ~]# restorecon -R /var/www/html/cacti/

配置一个 cron 作业,每 5 分钟运行一次 poller.php 脚本。
此脚本将收集和更新 /rra 目录中的系统指标。

[root@centos8.onitroad.com ~]# echo  "*/5 * * * *    apache   /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1" >> /etc/crontab

使用浏览器打开Cacti界面。
http://centos8.onitroad.com.onitroad.com/cacti。

使用默认用户名/密码登录:admin/admin

由于我们是第一次登录Cacti web界面,所以需要修改admin用户的默认密码。

阅读并接受 Cacti 网络监控软件的许可协议。

我们已经安装完成Cacti, 可以开始在控制面板中添加要监控的服务器。

在 CentOS 8 上配置 Cacti

根据环境编辑 config.php 文件并更新参数。

[root@centos8.onitroad.com ~]# vi /var/www/html/cacti/include/config.php

定位并更新以下参数。

$database_username = 'cacti';
$database_password = 'q1angm1ma';

将 apache 用户设为 Cacti 软件目录的所有者。

[root@centos8.onitroad.com ~]# chown -R apache:apache /var/www/html/cacti/

重新启动 Apache 和 PHP 服务使更改生效。

[root@centos8.onitroad.com ~]# systemctl restart httpd.service php-fpm.service

在 CentOS 8 上安装 SNMP

SNMP(简单网络管理协议)是一种 Internet 标准协议,用于收集和组织有关 IP 网络上受管设备的信息。

安装 net-snmp 和 net-snmp-utils 包以安装 SNMP 和 php-snmp 以启用 PHP 对 SNMP 的支持。

[root@centos8.onitroad.com ~]# dnf install -y net-snmp php-snmp net-snmp-utils

在 CentOS 8 上安装 RRDTool

Cacti 需要 RRDTool(RRD 代表 Round Robin Database)来维护系统指标数据。
因此,我们使用 dnf 命令安装 rrdtool 包。

[root@centos8.onitroad.com ~]# dnf install -y rrdtool

为 Cacti 创建 MariaDB 数据库

以 root 用户身份连接 MariaDB 服务器。

[root@centos8.onitroad.com ~]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

为 Cacti 网络监控服务器创建一个数据库。

MariaDB [(none)]> create database cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.112 sec)

为 Cacti 软件创建一个用户并授予对 cacti 数据库的完整权限。

MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'Str0ngPa55word';
Query OK, 0 rows affected (0.254 sec)

向 cacti 用户授予时区选择权限。

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
Query OK, 0 rows affected (0.042 sec)

重新加载权限表。

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.083 sec)

退出 MySQL shell。

MariaDB [(none)]> QUIT
Bye

Cacti tar包 还包含一个用于创建必要数据库对象的 SQL 脚本。
我们可以使用这个脚本在 cacti 数据库中创建表和其他对象。

[root@centos8.onitroad.com ~]# mysql -D cacti -u cacti -pStr0ngPa55word < /var/www/html/cacti/cacti.sql

在继续之前,我们需要加载 MariaDB 时区表。
否则,Cacti Web 安装程序会在时区上向我们发出警告。

使用以下命令从 CentOS 8 操作系统加载具有可用时区的时区表。

[root@centos8.onitroad.com ~]# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p123 mysql
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.

时区已成功加载到 MariaDB 表中。
不要担心警告,这是因为这些文件不包含有效的时区。

编辑 MariaDB 配置文件。

[root@centos8.onitroad.com ~]# vi /etc/my.cnf.d/mariadb-server.cnf

根据 Cacti 网络监控软件的要求,在 [mysqld] 部分下设置以下全局变量。

join_buffer_size=30M
innodb_file_format=Barracuda
innodb_buffer_pool_size=256M
innodb_buffer_pool_instances=1
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_io_capacity=5000
innodb_io_capacity_max=10000
innodb_large_prefix=1
character_set_client=utf8mb4
character_set_server=utf8mb4
collation_server=utf8mb4_unicode_ci

在 CentOS 8 上安装 Apache HTTP Server:

Cacti 网络监控服务器是一个基于 PHP 的 Web 应用程序,因此,我们需要一个支持 PHP 的 Web 服务器来运行它。

为此,我们这里使用 Apache HTTP 服务器。

安装 Apache HTTP 服务器

[root@centos8.onitroad.com ~]# dnf install -y httpd httpd-devel

启用并启动 Apache 服务。

[root@centos8.onitroad.com ~]# systemctl enable --now httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service -> /usr/lib/systemd/system/httpd.service.

允许 Linux 防火墙中的 Apache 服务,使其可从网络计算机访问。

[root@centos8.onitroad.com ~]# firewall-cmd --permanent --add-service=http
success
[root@centos8.onitroad.com ~]# firewall-cmd --reload
success
www. On IT Road .com

为 Cacti 配置 PHP 设置

要使用 Cacti 网络监控服务器,我们需要相应地自定义 PHP 设置。

编辑 /etc/php.ini 配置文件并将其配置为使用 Cacti 。

[root@centos8.onitroad.com ~]# vi /etc/php.ini

找到并设置以下参数。

safe_mode = Off                 ; Disable safe mode
date.timezone = "Asia/Karachi"  ; Define timezone to avoid warnings on time/date functions
file_uploads = On               ; Allow import of templates
memory_limit = 400M             ; maximum amount of memory a PHP script can consume
max_execution_time = 60         ; maximum execution time (in seconds) of a PHP script
日期:2020-09-17 00:16:43 来源:oir作者:oir