如何在CentOS 7上安装Cacti 1.1
Anne655
・10 分钟阅读
Cacti是一个免费的开放源码网络监控和绘图工具,用PHP编写,用RRDtool (Round-Robin数据库工具)可以提供各种有用的特性,包括远程和本地数据收集器,图形模板,网络发现,设备管理自动化等等。
前提条件
- 新的CentOS 7x64服务器实例,假设它的IP地址是203.0.113.1 ,
- 一个sudo用户。
- 服务器实例已被使用EPEL YUM更新到最新的稳定状态 ,
步骤1 : 设置最新的LAMP栈
必须先设置LAMP栈或相似的web操作环境,然后才能正确安装和运行Cacti 。
下面为Cacti建立一个最新的LAMP栈,它由Centos7 Apache2.4、Mariadb10.2和PHP 7.1组成,
# Install Apache 2.4
sudo yum install httpd -y
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
sudo sed -i"s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
# Install MariaDB 10.2
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo yum install MariaDB-server MariaDB-client -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
# Secure MariaDB 10.2
sudo /usr/bin/mysql_secure_installation
# When prompted, answer questions as below:
# - Enter current password for root (enter for none): Just press the Enter button
# - Set root password? [Y/n]: Y
# - New password: your-MariaDB-root-password
# - Re-enter new password: your-MariaDB-root-password
# - Remove anonymous users? [Y/n]: Y
# - Disallow root login remotely? [Y/n]: Y
# - Remove test database and access to it? [Y/n]: Y
# - Reload privilege tables now? [Y/n]: Y
# Create a MariaDB database for Cacti
mysql -u root -p
# For security purposes, be sure to replace"cacti","cactiuser", and"yourpassword" with your own ones.
CREATE DATABASE cacti;
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
# Install required PHP 7.1 components for Cacti
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y mod_php71w php71w-process php71w-common php71w-pdo php71w-xml php71w-ldap php71w-mbstring php71w-gd php71w-snmp php71w-mysqlnd php71w-cli php71w-mcrypt php71w-opcache php71w-imap php71w-intl
sudo cp /etc/php.ini /etc/php.ini.bak
sudo sed -i 's#;date.timezone =#date.timezone = America/Los_Angeles#' /etc/php.ini
# Modify firewall rules
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
步骤2:安装其他必需的依赖项
除了设置实用的LAMP堆栈之外,还需要为Cacti安装几个依赖项,如下所示。
sudo yum install -y net-snmp net-snmp-utils rrdtool
sudo systemctl start snmpd.service
sudo systemctl enable snmpd.service
步骤3: 准备Cacti文件和数据库
下载并解压缩Cacti 1.1归档文件。
cd
wget http://www.cacti.net/downloads/cacti-1.1.20.tar.gz
tar -zxvf cacti-1.1.20.tar.gz
将Cacti文件移到适当位置,创建Cacti log
文件,然后向它们授予适当的权限。
sudo mv ~/cacti-1.1.20 /opt
sudo ln -s /opt/cacti-1.1.20 /var/www/html/cacti
sudo touch /opt/cacti-1.1.20/log/cacti.log
sudo chown -R apache:apache /opt/cacti-1.1.20
将timezone信息和Cacti数据导入我们之前设置的MariaDB数据库。
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql -u root -p cacti < /var/www/html/cacti/cacti.sql
mysql -u root -p
# In the MySQL shell:
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;
EXIT;
设置Cacti参数,
使用vi
编辑器打开Cacti配置文件:
sudo vi /var/www/html/cacti/include/config.php
确保下面的参数使用正确的值。
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'yourpassword';
$database_port = '3306';
$database_ssl = false;
$url_path = '/cacti/';
保存并退出。
:wq
!
为Cacti设置一个作业。
sudo crontab -u apache -e
用以下方法填充文件:
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
保存并退出。
:wq
!
步骤4:为Cacti设置Apache虚拟主机
为了使Apache服务于Cacti,你需要为Cacti设置一个Apache虚拟主机,如下所示。
注意:请记住修改机器上ServerAdmin
,ServerName
和ServerAlias
的值。
cat <<EOF | sudo tee -a /etc/httpd/conf.d/cacti.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/
ServerName cacti.example.com
ServerAlias www.cacti.example.com
<Directory /var/www/html/cacti/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/cacti.example.com-error_log
CustomLog /var/log/httpd/cacti.example.com-access_log common
</VirtualHost>
EOF
重启Apache以使你的所有更改生效。
sudo systemctl restart httpd.service
步骤5:更新MariaDB设置
为了在使用Cacti时提供更好的性能,你需要使用建议的值,去更新几个MariaDB设置。
备份/etc/my.cnf
文件,然后使用vi
编辑器打开它:
sudo cp /etc/my.cnf /etc/my.cnf.bak
sudo vi /etc/my.cnf
查找行[client-server]
,并按如下所示追加内容。
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
max_heap_table_size=64M
tmp_table_size=80M
join_buffer_size=80M
innodb_buffer_pool_size=256M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
保存并退出。
:wq
!
重新启动MariaDB,以便将所有修改生效。
sudo systemctl restart mariadb.service
步骤6:使用Web浏览器中的CACTI安装向导继续安装CACTI
将你喜爱的网页浏览器指向http://203.0.113.1/cacti
,你就会进入Cacti Installation Wizard
界面。
在License Agreement
页面上,检查,Accept GPL License Agreement
选项,然后单击Next
按钮。
在Pre-installation Checks
页面上,所有要求都应该满足,只需单击Next
按钮即可移动。
在Installation Type
页面上,选择New Primary Server
选项,然后单击Next
按钮。
在 Critical Binary Locations and Versions
页,忽略 Spine Binary File Location
因为我们没有安装Spine,只需单击Next
按钮即可移动。
在Directory Permission Checks
页面上,确保所有指定的目录都可写,然后单击Next
按钮。
在Template Setup
页面上,选中Local Linux Machine
选项,然后单击Finish
按钮完成安装,并且切换到界面中的日志。
在User Login
接口上,使用默认的用户名admin
和默认的密码admin
登录。
登录后,你将被要求立即更改密码,确保提供一个满足所有提示要求的安全密码。
Cacti的安装和配置已经完成,之后应该相应设置RRDtool,以便Cacti能够获得必要的图形数据。