仙人掌工具对IT业务的一个开源的基于Web的网络监控和系统监控图形解决方案。 仙人掌使得用户能够轮询定期服务来创建使用RRDtool的所得数据的曲线图。 通常,它被用来绘制指标,如网络带宽利用率 ,CPU负载 , 运行的进程 , 磁盘空间等的时间序列数据
在RHEL / CentOS / Fedora中安装Cacti
在这种操作方法,我们将告诉你如何安装和设置完整的网络监控应用在RHEL 7.x版/ 6.x中/ 5.x中使用的Net-SNMP工具,称为仙人掌 ,CentOS 7.x版/ 6.x中/ 5.x和24-12的Fedora系统中使用YUM和DNF (Fedora的23起)包管理工具。
Cacti所需软件包
以下要求要在你的Linux操作系统,如RHEL / CentOS的 / Fedora的安装包的仙人掌。
- Apache :一个Web服务器,以显示PHP和的RRDTool创建的网络图。
- MySQL的 :一个数据库服务器存储仙人掌信息。
- PHP:脚本模块创建使用RRDToo升图表。
- PHP-SNMP:PHP扩展的SNMP访问数据。
- NET-SNMP:A SNMP( 简单网络管理协议 )用于管理网络。
- RRDTool的 :数据库的工具来管理和检索像CPU负载 , 网络带宽等的时间序列数据
在RHEL / CentOS / Fedora上安装Cacti所需软件包
首先,我们需要安装以下依赖包一个接一个使用YUM包管理工具。
安装Apache
# yum install httpd httpd-devel --------- On Fedora 22+ releases --------- # dnf install httpd httpd-devel
Apache Web服务器安装
安装MySQL
# yum install mysql mysql-server [On RHEL/CentOS 6/5 and Fedora 12-18]
MySQL安装
MariaDB的是MySQL数据库项目的社区开发叉,并提供了针对MySQL的替代品。 此前官方下RHEL / CentOS的6.x中/ 5.x和Fedora的支持数据库MySQL的。
近日, 红帽使得从MySQL到MariaDB的一个新的事务,因为MariaDB的是MySQL在RHEL / CentOS 7.x的默认实现和Fedora 19起..
# yum install mariadb-server -y [On RHEL/CentOS 7.x and Fedora 19 onwards] # dnf install mariadb-server -y [On Fedora 22+ onwards]
安装MariaDB数据库
安装PHP
# yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli --------- On Fedora 22+ releases --------- # dnf install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli
PHP安装模块
安装PHP-SNMP
# yum install php-snmp # dnf install php-snmp [On Fedora 22+ onwards]
SNMP安装
安装NET-SNMP
# yum install net-snmp-utils net-snmp-libs # dnf install net-snmp-utils net-snmp-libs [On Fedora 22+ onwards]
安装SNMP Utils
安装RRDTool
# yum install rrdtool # dnf install rrdtool [On Fedora 22+ onwards]
安装Rrdtool
盯着Apache,MySQL和SNMP服务
一旦你安装了所有必需的软件对仙人掌的安装,让他们开始一个接一个使用下面的命令。
在RHEL / CentOS 6.x / 5.x和Fedora 18-12
[root@youcl ~]# service httpd start [root@youcl ~]# service mysqld start [root@youcl ~]# service snmpd start
使用init启动服务
在RHEL / CentOS 7.x和Fedora 19以上
[root@youcl ~]# systemctl start httpd.service [root@youcl ~]# systemctl start mariadb.service [root@youcl ~]# systemctl start snmpd.service
使用systemctl启动服务
配置系统启动链接
配置Apache,MySQL和SNMP服务在引导时启动。
在RHEL / CentOS 6.x / 5.x和Fedora 18-12
[root@youcl ~]# /sbin/chkconfig --levels 345 httpd on [root@youcl ~]# /sbin/chkconfig --levels 345 mysqld on [root@youcl ~]# /sbin/chkconfig --levels 345 snmpd on
在引导时启用服务使用chkconfig
在RHEL / CentOS 7.x和Fedora 19以上
[root@youcl ~]# systemctl enable httpd.service [root@youcl ~]# systemctl enable mariadb.service [root@youcl ~]# systemctl enable snmpd.service
在启动时使用systemctl启用服务
在RHEL / CentOS / Fedora上安装Cacti
在这里,你需要安装并启用EPEL软件库 。 启用存储库后,键入以下命令以安装Cacti应用程序。
# yum install cacti # dnf install cacti [On Fedora 22+ onwards]
样品输出:
Loaded plugins: fastestmirror, langpacks epel/x86_64/metalink | 4.7 kB 00:00:00 epel | 4.4 kB 00:00:00 (1/2): epel/x86_64/group_gz | 250 kB 00:00:03 (2/2): epel/x86_64/primary_db | 4.0 MB 00:02:20 (1/2): epel/x86_64/updateinfo | 315 kB 00:00:09 (2/2): epel/x86_64/pkgtags | 1.4 MB 00:00:59 Loading mirror speeds from cached hostfile * base: centos.excellmedia.net * epel: ftp.cuhk.edu.hk * extras: centos.excellmedia.net * updates: centos.excellmedia.net Resolving Dependencies --> Running transaction check ---> Package cacti.noarch 0:0.8.8b-7.el7 will be installed --> Processing Dependency: rrdtool for package: cacti-0.8.8b-7.el7.noarch --> Processing Dependency: net-snmp-utils for package: cacti-0.8.8b-7.el7.noarch --> Running transaction check ---> Package net-snmp-utils.x86_64 1:5.7.2-18.el7 will be installed ---> Package rrdtool.x86_64 0:1.4.8-8.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================= Installing: cacti noarch 0.8.8b-7.el7 epel 2.1 M Installing for dependencies: net-snmp-utils x86_64 1:5.7.2-18.el7 base 195 k rrdtool x86_64 1.4.8-8.el7 base 368 k Transaction Summary ============================================================================================================================================================================================= Install 1 Package (+2 Dependent packages) Total download size: 2.7 M Installed size: 7.2 M Is this ok [y/d/N]: y Downloading packages: (1/3): net-snmp-utils-5.7.2-18.el7.x86_64.rpm | 195 kB 00:00:04 warning: /var/cache/yum/x86_64/7/epel/packages/cacti-0.8.8b-7.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY==============- ] 56 kB/s | 2.4 MB 00:00:05 ETA Public key for cacti-0.8.8b-7.el7.noarch.rpm is not installed (2/3): cacti-0.8.8b-7.el7.noarch.rpm | 2.1 MB 00:00:53 (3/3): rrdtool-1.4.8-8.el7.x86_64.rpm | 368 kB 00:02:47 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 16 kB/s | 2.7 MB 00:02:47 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Importing GPG key 0x352C64E5: Userid : "Fedora EPEL (7) " Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5 Package : epel-release-7-5.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : rrdtool-1.4.8-8.el7.x86_64 1/3 Installing : 1:net-snmp-utils-5.7.2-18.el7.x86_64 2/3 Installing : cacti-0.8.8b-7.el7.noarch 3/3 /var/tmp/rpm-tmp.mR0t1v: line 1: fg: no job control warning: %post(cacti-0.8.8b-7.el7.noarch) scriptlet failed, exit status 1 Non-fatal POSTIN scriptlet failure in rpm package cacti-0.8.8b-7.el7.noarch Verifying : 1:net-snmp-utils-5.7.2-18.el7.x86_64 1/3 Verifying : rrdtool-1.4.8-8.el7.x86_64 2/3 Verifying : cacti-0.8.8b-7.el7.noarch 3/3 Installed: cacti.noarch 0:0.8.8b-7.el7 Dependency Installed: net-snmp-utils.x86_64 1:5.7.2-18.el7 rrdtool.x86_64 0:1.4.8-8.el7 Complete!
为Cacti安装配置MySQL服务器
我们需要配置MySQL的仙人掌 ,要做到这一点,我们需要为我们新安装的MySQL服务器设定的密码,然后我们将创建一个用户仙人掌 仙人掌数据库。 如果你的MySQL已经有密码保护,则不需要再次设定。
设置MySQL密码
要为MySQL服务器设置新密码,请使用以下命令。 ( 注 :这是唯一的新的MySQL安装 )。
[root@youcl ~]# mysqladmin -u root password YOUR-PASSWORD-HERE
创建MySQL Cacti数据库
登录到MySQL服务器与新创建的密码,并创建用户仙人掌 仙人掌数据库,并为它设置密码。
在RHEL / CentOS 6.x / 5.x和Fedora 18-12
[root@youcl ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database cacti; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'youcl'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit; Bye
在RHEL / CentOS 7.x和Fedora 19以上
[root@youcl ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.41-MariaDB MariaDB Server Copyright (c) 2000, 2014, 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.00 sec) MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'youcl'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit; Bye
将Cacti表安装到MySQL
找出使用RPM命令的数据库文件的路径,安装仙人掌表到新创建的数据库仙人掌 ,请使用以下命令。
# rpm -ql cacti | grep cacti.sql
样品输出:
/usr/share/doc/cacti-0.8.8b/cacti.sql OR /usr/share/doc/cacti/cacti.sql
我们现在已经Cacti.sql文件的位置,键入以下命令来安装表,在这里你需要键入仙人掌用户密码 。
[root@youcl ~]# mysql -u cacti -p cactiConfigure MySQL settings for Cacti
Open the file called /etc/cacti/db.php with any editor.
# vi /etc/cacti/db.phpMake the following changes and save the file. Make sure you set password correctly.
/* make sure these values reflect your actual database/host/user/password */ $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "your-password-here"; $database_port = "3306"; $database_ssl = false;Configuring Firewall for Cacti
On RHEL/CentOS 6.x/5.x and Fedora 18-12
[root@youcl ~]# iptables -A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT [root@youcl ~]# iptables -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT [root@youcl ~]# service iptables saveOn RHEL/CentOS 7.x and Fedora 19 Onwards
[root@youcl ~]# firewall-cmd --permanent --zone=public --add-service=http [root@youcl ~]# firewall-cmd --reloadConfiguring Apache Server for Cacti Installation
Open file called /etc/httpd/conf.d/cacti.conf with your choice of editor.
# vi /etc/httpd/conf.d/cacti.confYou need to enabled access to Cacti application for your local network or per IP level. For example we've enabled access to our local LAN network 172.16.16.0/20. In your case, it would be different.
Alias /cacti /usr/share/cacti <Directory /usr/share/cacti/> Order Deny,Allow Deny from all Allow from 172.16.16.0/20 </Directory>In latest version of Apache (ex: Apache 2.4), you may need to change according to the following settings.
Alias /cacti /usr/share/cacti <Directory /usr/share/cacti/> <IfModule mod_authz_core.c> # httpd 2.4 Require all granted </IfModule> <IfModule !mod_authz_core.c> # httpd 2.2 Order deny,allow Deny from all Allow from all </IfModule> </Directory>Finally, restart the Apache service.
[root@youcl ~]# service httpd restart [On RHEL/CentOS 6.x/5.x and Fedora 18-12] [root@youcl ~]# systemctl restart httpd.service [On RHEL/CentOS 7.x and Fedora 19 onwards]Setting Cron for Cacti
Open file /etc/cron.d/cacti.
# vi /etc/cron.d/cactiUncomment the following line. The poller.php script runs every 5mins and collects data of known host which is used by Cacti application to display graphs.
#*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1Running Cacti Installer Setup
Finally, Cacti is ready, just go to http://YOUR-IP-HERE/cacti/ & follow the installer instruction through the following screens. Click Next button.
Cacti Setup Screen
Please choose installation Type as "New Install".
Select Cacti New Install
Make sure all the following values are correct before continuing. Click Finish button.
Cacti Installation Directories
Cacti Login Screen, enter username as admin and password as admin.
Cacti Login Screen
Once you've entered username and password, it will ask you to enter a new password for cacti.
Cacti Force Password Screen
Cacti Console Screen.
Cacti Console Screen
How to Create New Graphs
To create graphs, Click on New Graphs --> Select Host --> Select SNMP - Interface Statistics and Select a graph type In/Out Bits. Click on Create button. Please refer screen below.
How to Create Graphs in Cacti
Cacti Monitoring Graphs
For more information and usage please visit the Cacti Page.
为Cacti配置MySQL设置
打开名为/etc/cacti/db.php使用任何编辑的文件。
# vi /etc/cacti/db.php
进行以下更改并保存文件。 确保正确设置密码。
/* make sure these values reflect your actual database/host/user/password */ $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "your-password-here"; $database_port = "3306"; $database_ssl = false;
为Cacti配置防火墙
在RHEL / CentOS 6.x / 5.x和Fedora 18-12
[root@youcl ~]# iptables -A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT [root@youcl ~]# iptables -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT [root@youcl ~]# service iptables save
在RHEL / CentOS 7.x和Fedora 19以上
[root@youcl ~]# firewall-cmd --permanent --zone=public --add-service=http [root@youcl ~]# firewall-cmd --reload
配置Apache Server以进行Cacti安装
打开文件名为/etc/httpd/conf.d/cacti.conf与您选择的编辑器。
# vi /etc/httpd/conf.d/cacti.conf
您需要启用访问应用程序仙人掌为你的本地网络或每个IP的水平。 例如,我们启用了接入本地局域网172.16.16.0/20。 在你的情况下,它会不同。
Alias /cacti /usr/share/cacti <Directory /usr/share/cacti/> Order Deny,Allow Deny from all Allow from 172.16.16.0/20 </Directory>
在Apache中(例如: Apache2.4)的最新版本,您可能需要按照下面的设置更改。
Alias /cacti /usr/share/cacti <Directory /usr/share/cacti/> <IfModule mod_authz_core.c> # httpd 2.4 Require all granted </IfModule> <IfModule !mod_authz_core.c> # httpd 2.2 Order deny,allow Deny from all Allow from all </IfModule> </Directory>
最后,重新启动Apache服务。
[root@youcl ~]# service httpd restart [On RHEL/CentOS 6.x/5.x and Fedora 18-12] [root@youcl ~]# systemctl restart httpd.service [On RHEL/CentOS 7.x and Fedora 19 onwards]
为Cacti设置Cron
打开文件/etc/cron.d/cacti。
# vi /etc/cron.d/cacti
取消注释以下行。 该poller.php脚本运行,每5分钟 ,并收集所使用的仙人掌应用程序来显示图形的已知主机的数据。
#*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
运行Cacti安装程序设置
最后,仙人掌俱备,只访问http://你的-IP-HERE /仙人掌/&按照安装指令通过下面的屏幕。 单击Next按钮。
仙人掌设置屏幕
请选择安装类型“ 新安装 ”。
选择Cacti新安装
在继续之前,请确保所有以下值是正确的。 单击Finish按钮。
Cacti安装目录
Cacti登录屏幕,输入用户名为admin,密码为admin。
仙人掌登录屏幕
输入用户名和密码后,将要求您输入cacti的新密码。
Cacti Force密码屏幕
仙人掌控制台屏幕。
仙人掌控制台屏幕
如何创建新图表
要创建图表,请点击新图表 - > 选择主机 - > 选择SNMP - 接口统计信息 ,并选择一个图表类型输入/输出位 。 点击创建按钮。 请参考下面的屏幕。
如何在Cacti中创建图形
仙人掌监测图
欲了解更多信息和用法,请访问仙人掌页 。