一.安装前准备

1.查看SElinux状态

getenforce
# Enforcing为不执行,Permissive为不执行但产生警告,Disabled为关闭
# 临时关闭命令
setenforce 0
# 永久关闭命令(需要重启服务器)
sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config

2.更换国内软件源(可选)

bash <(curl -L -s https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)

3.安装 EPEL 存储库

如果更换国内源,会提示你是否安装EPEL存储库,就无需此步骤

yum install epel-release -y

4.设置上海时区

timedatectl set-timezone Asia/Shanghai

二.安装环境

1.安装 Apache 和 PHP 7.2

(1)安装 Apache

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum install yum-utils -y
yum-config-manager --enable remi-php72
yum install -y httpd

(2)安装 PHP 7.2

yum install -y php php-common php-bcmath php-cli \
php-mysqlnd php-gd php-gmp php-intl \
php-json php-ldap php-mbstring \
php-pdo php-pear php-snmp php-process \
php-xml php-zip

2.安装 Mariadb 10.6

cat > /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.6/centos7-amd64
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck = 1
EOF

yum install mariadb-server mariadb-client -y

3.安装 SNMP 和 RRDtool

yum install net-snmp net-snmp-utils rrdtool -y

4.启动服务

(1)Apache 服务

systemctl enable httpd
systemctl start httpd
systemctl status httpd

(2)MariaDB 服务

systemctl enable mariadb
systemctl start mariadb
systemctl status mariadb

5.修改 PHP 和 MariaDB 配置

(1)PHP 配置

vi /etc/php.ini
# 修改为下方指定参数,值也可以更大
max_execution_time = 60
memory_limit = 512M
date.timezone = Asia/Shanghai

(2)MariaDB 配置

① 安全配置 MariaDB
/usr/bin/mariadb-secure-installation
# 原密码默认为空
Enter current password for root (enter for none): 
Set root password? [Y/n] y
# 下面输入你的密码
New password: your_password
Re-enter new password: your_password
# 下面设置看你自己
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
② 修改数据库配置
vim /etc/my.cnf.d/server.cnf
# 修改为以下参数,值可以更大
[mariadb-10.6]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
max_heap_table_size = 64M
tmp_table_size = 64M
innodb_buffer_pool_size = 1024M
innodb_doublewrite = OFF
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

(3)重启服务

systemctl restart httpd
systemctl restart mariadb

(4)设置 Cacti 数据库

mysql -u root -p
# 接下来输入你的密码
create database if not exists cacti;
# cactiuser和password为修改项,建议仅修改password
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';
GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost';
FLUSH PRIVILEGES;

三.安装和配置 Cacti

1.下载和安装

wget https://files.cacti.net/cacti/linux/cacti-1.2.25.tar.gz
tar -zxvf cacti-1.2.25.tar.gz
mv cacti-1.2.25 /var/www/html/cacti
chown -R apache:apache /var/www/html/cacti

2.导入 Cacti 数据表

cd /var/www/html/cacti
mysql cacti < cacti.sql -u root -p
cp include/config.php.dist include/config.php
nano include/config.php
#修改一下参数为上面设置的用户名密码
$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'cactiuser';
$database_port     = '3306';
$database_retries  = 5;
$database_ssl      = false;
$database_ssl_key  = '';
$database_ssl_cert = '';
$database_ssl_ca   = '';
$database_persist  = false;

3.启动 poller

touch /etc/sysconfig/cactid
cp -p /var/www/html/cacti/service/cactid.service /etc/systemd/system
systemctl enable cactid
systemctl start cactid
systemctl status cactid

4.访问 Cacti 进行最后安装

你搭建的Cacti网址为:http://IP/cacti

四.一些问题解决

1.图形中文乱码

yum -y install fontconfig ttmkfdir
mkdir /usr/share/fonts/chinese
curl -o /usr/share/fonts/chinese/msyhl.ttc https://down.whsir.com/downloads/msyhl.ttc

此解决方法转载自:吴昊博客-Cacti图形显示方块乱码解决)

2.修改 Cacti 网站访问端口

vi /etc/httpd/conf/httpd.conf
# 将42行的Listen 80修改为你的自定义端口
Listen 8000
# 例如改为8000端口

3.更新 Cacti

下载最新版的压缩包,解压覆盖到 /var/www/html/cacti 目录,刷新网站,更新即可

最后修改:2024 年 05 月 29 日
如果觉得我的文章对你有用,请随意赞赏