サボテンは英語でサボテンを意味します。サボテンは、PHP、MySQL、SNMP、およびRRDToolに基づいて開発されたネットワークトラフィック監視グラフィカル分析ツールのセットです。
cactiは、php言語で実装されたソフトウェアです。その主な機能は、snmp(簡易ネットワーク管理プロトコル)サービスを使用してデータを取得し、rrdtool(リングデータベース)を使用してデータを保存および更新し、rrdtoolを使用してデータを生成することです。ユーザーはデータを表示する必要があります。チャートがユーザーに表示されます。したがって、snmpとrrdtoolがcactiの鍵となります。Snmpはデータ収集に関連し、rrdtoolはデータストレージとチャート生成に関連しています。
LAMPアーキテクチャ環境を構築する
Apacheを構成する
httpdをインストールします
[root@localhost ~]# yum install httpd -y
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
nginx | 2.9 kB 00:00
yum | 4.1 kB 00:00
nginx/x86_64/primary_db FAILED
http://nginx.org/packages/centos/7/x86_64/repodata/5aafc56eec8e29902c891c177fe8d2c8273e99e4fa4b4d6777128fd7f534a681-primary.sqlite.bz2: [Errno 12] Timeout on http://nginx.org/packages/centos/7/x86_64/repodata/5aafc56eec8e29902c891c177fe8d2c8273e99e4fa4b4d6777128fd7f534a681-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
nginx/x86_64/primary_db | 55 kB 00:04
...............省略安装过程.................
正在安装 : httpd-tools-2.4.6-40.el7.x86_64 1/3
正在安装 : mailcap-2.1.41-2.el7.noarch 2/3
正在安装 : httpd-2.4.6-40.el7.x86_64 3/3
yum/productid | 1.6 kB 00:00
验证中 : mailcap-2.1.41-2.el7.noarch 1/3
验证中 : httpd-tools-2.4.6-40.el7.x86_64 2/3
验证中 : httpd-2.4.6-40.el7.x86_64 3/3
已安装:
httpd.x86_64 0:2.4.6-40.el7
作为依赖被安装:
httpd-tools.x86_64 0:2.4.6-40.el7 mailcap.noarch 0:2.1.41-2.el7
完毕!
[root@localhost ~]#
httpdを開始します
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl enable httpd
httpサービスを開く
[root@localhost ~]# firewall-cmd --permanent --add-service=http
[root@localhost ~]# firewall-cmd --reload # 重启防火墙
mariadbデータベースを構成する
Mariadbデータベースをインストールします
[root@localhost ~]# yum install mariadb mariadb-server mysql-devel -y
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
............ 省略安装过程 .............
已安装:
mariadb.x86_64 1:5.5.44-2.el7 mariadb-devel.x86_64 1:5.5.44-2.el7
mariadb-server.x86_64 1:5.5.44-2.el7
作为依赖被安装:
keyutils-libs-devel.x86_64 0:1.5.8-3.el7
krb5-devel.x86_64 0:1.13.2-10.el7
libcom_err-devel.x86_64 0:1.42.9-7.el7
libselinux-devel.x86_64 0:2.2.2-6.el7
libsepol-devel.x86_64 0:2.1.9-3.el7
libverto-devel.x86_64 0:0.2.5-4.el7
openssl-devel.x86_64 1:1.0.1e-42.el7_1.9
pcre-devel.x86_64 0:8.32-15.el7
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
perl-DBD-MySQL.x86_64 0:4.023-5.el7
perl-DBI.x86_64 0:1.627-4.el7
perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7
zlib-devel.x86_64 0:1.2.7-15.el7
完毕!
[root@localhost ~]#
Mariadbデータベースを起動します
[root@localhost ~]# systemctl enable mariadb
[root@localhost ~]# systemctl start mariadb
Mariadbデータベースを初期化します
[root@localhost ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation:行379: find_mysql_client: 未找到命令
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!
[root@localhost ~]#
PHPとMariadbデータベースの接続をテストするためのユーザーchuidを作成します
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all privileges on *.* to chuid@localhost identified by '123456';
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@localhost ~]#
Mariadbデータベースを再起動します
[root@localhost ~]# systemctl restart mariadb
PHPを構成する
PHPをインストールする
[root@localhost ~]# yum -y install php php-mysql php-gd php-pear
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
.................省略安装过程...............
已安装:
php.x86_64 0:5.4.16-36.el7_1 php-gd.x86_64 0:5.4.16-36.el7_1
php-mysql.x86_64 0:5.4.16-36.el7_1 php-pear.noarch 1:1.9.4-21.el7
作为依赖被安装:
libzip.x86_64 0:0.10.1-8.el7 php-cli.x86_64 0:5.4.16-36.el7_1
php-common.x86_64 0:5.4.16-36.el7_1 php-pdo.x86_64 0:5.4.16-36.el7_1
php-process.x86_64 0:5.4.16-36.el7_1 php-xml.x86_64 0:5.4.16-36.el7_1
t1lib.x86_64 0:5.1.2-14.el7
完毕!
[root@localhost ~]#
タイムゾーンを変更する
[root@localhost ~]# vim /etc/php.ini
date.timezone =PRC
index.phpテストページを編集する
[root@localhost ~]# vim /var/www/html/index.php
<?php
phpinfo();
?>
[root@localhost ~]# systemctl restart httpd # 重启Apache
Firefoxブラウザを開いてIPアドレスを入力すると、次のページが表示され、PHP環境が正常にセットアップされたことを示します。
サボテンモニタリングを設定する
サボテンをインストールする
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
--2020-07-22 09:49:31-- http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
正在解析主机 www.cacti.net (www.cacti.net)... 104.28.8.127, 172.67.196.107, 104.28.9.127, ...
正在连接 www.cacti.net (www.cacti.net)|104.28.8.127|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://www.cacti.net/downloads/cacti-0.8.8f.tar.gz [跟随至新的 URL]
--2020-07-22 09:49:32-- https://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
正在连接 www.cacti.net (www.cacti.net)|104.28.8.127|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2594409 (2.5M) [application/octet-stream]
正在保存至: “cacti-0.8.8f.tar.gz”
100%[================================>] 2,594,409 180KB/s 用时 13s
2020-07-22 09:50:02 (190 KB/s) - 已保存 “cacti-0.8.8f.tar.gz” [2594409/2594409])
[root@localhost src]# ls | grep cacti
cacti-0.8.8f.tar.gz
[root@localhost src]# tar xf cacti-0.8.8f.tar.gz
[root@localhost src]# mv cacti-0.8.8f /var/www/html/cacti
サボテンデータベースを作成し、chuidユーザーにサボテンデータベースを操作する権限を付与します
[root@localhost src]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, 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 default character set utf8; # 创建数据库cacti,默认字符集utf8
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on cacti.* to chuid@localhost identified by '123456'; # 赋予chuid用户对cacti数据库的所有表操作权限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> use mysql
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cacti |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> exit
Bye
[root@localhost src]#
cacti.sqlをデータベースにインポートします
[root@localhost src]# cd ~
[root@localhost ~]# mysql -u chuid -p cacti < /var/www/html/cacti/cacti.sql
Enter password:
[root@localhost ~]#
config.phpとglobal.phpを編集し、データベースのログインユーザーとパスワードを変更します
[root@localhost ~]# vim /var/www/html/cacti/include/config.php
26 $database_type = "mysql";
27 $database_default = "cacti";
28 $database_hostname = "localhost";
29 $database_username = "chuid";
30 $database_password = "123456";
31 $database_port = "3306";
32 $database_ssl = false;
[root@localhost ~]# vim /var/www/html/cacti/include/global.php
34 $database_type = "mysql";
35 $database_default = "cacti";
36 $database_hostname = "localhost";
37 $database_username = "chuid";
38 $database_password = "123456";
39 $database_port = "3306";
40 $database_ssl = false;
rrdtoolを構成する
rrdtoolをインストールして画像を生成します
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# yum -y install rrdtool rrdtool-devel rrdtool-php rrdtool-perl
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
nginx | 2.9 kB 00:00
yum | 4.1 kB 00:00
................省略安装过程................
正在安装 : rrdtool-1.4.8-9.el7.x86_64 1/1
验证中 : rrdtool-1.4.8-9.el7.x86_64 1/1
已安装:
rrdtool.x86_64 0:1.4.8-9.el7
完毕!
[root@localhost src]#
[root@localhost src]# yum -y install gd gd-devel php-gd
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
软件包 gd-2.0.35-26.el7.x86_64 已安装并且是最新版本
软件包 php-gd-5.4.16-36.el7_1.x86_64 已安装并且是最新版本
[root@localhost src]#
SNMPを構成する
SNMPサービスをインストールする
[root@localhost src]# yum -y install net-snmp net-snmp-utils php-snmp net-snmp-libs
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
没有可用软件包 php-snmp。
软件包 1:net-snmp-libs-5.7.2-24.el7.x86_64 已安装并且是最新版本
........................省略安装过程....................
正在安装 : 1:net-snmp-agent-libs-5.7.2-24.el7.x86_64 1/3
正在安装 : 1:net-snmp-5.7.2-24.el7.x86_64 2/3
正在安装 : 1:net-snmp-utils-5.7.2-24.el7.x86_64 3/3
验证中 : 1:net-snmp-agent-libs-5.7.2-24.el7.x86_64 1/3
验证中 : 1:net-snmp-5.7.2-24.el7.x86_64 2/3
验证中 : 1:net-snmp-utils-5.7.2-24.el7.x86_64 3/3
已安装:
net-snmp.x86_64 1:5.7.2-24.el7 net-snmp-utils.x86_64 1:5.7.2-24.el7
作为依赖被安装:
net-snmp-agent-libs.x86_64 1:5.7.2-24.el7
完毕!
[root@localhost src]#
構成ファイルの編集
[root@localhost src]# vim /etc/snmp/snmpd.conf
41 com2sec notConfigUser 127.0.0.1 public
62 access notConfigGroup "" any noauth exact all none none
85 view all included .1 80
snmpdサービスプログラムを再起動します
[root@localhost src]# systemctl restart snmpd.service
[root@localhost src]# systemctl enable snmpd.service
chuidユーザーにディレクトリ権限を付与する
[root@localhost src]# useradd -r -M chuid
[root@localhost src]# chown -R chuid /var/www/html/cacti/rra
[root@localhost src]# chown -R chuid /var/www/html/cacti/log
写真をキャプチャするようにスケジュールされたタスクを構成する
注:「* / 5」は、タスクが5分ごとに実行されることを意味します
[root@localhost src]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php >> /tmp/cacti_rrdtool.log
ブラウザはサボテン管理ページにアクセスしてインストールします
このインターフェイスは、インストールが成功したことを示しています。
最初のアカウントパスワードはadminとadminです
ログイン後、パスワードを変更するように求められます
ログインパスワードを変更した後、[保存]をクリックして、サボテンインターフェイスを自動的に入力します
右上隅の2番目のボタンをクリックし、グラフでサボテンの画像を表示し、ローカルホストホストを選択します。
右側には、5分ごとのサボテンモニタリング画像が表示されます
画像がない場合は、手動で実行する必要があります
[root@localhost ~]# /usr/bin/php /var/www/html/cacti/poller.php
[root@localhost ~]#
監視ログを表示する
[root@localhost ~]# cat /var/www/html/cacti/log/cacti.log
07/22/2020 11:35:00 AM - POLLER: Poller[0] Maximum runtime of 298 seconds exceeded. Exiting.
07/22/2020 11:35:00 AM - SYSTEM STATS: Time:298.2214 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:0 RRDsProcessed:0
07/22/2020 11:40:00 AM - POLLER: Poller[0] Maximum runtime of 298 seconds exceeded. Exiting.
07/22/2020 11:40:00 AM - SYSTEM STATS: Time:298.8324 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:0 RRDsProcessed:0
07/22/2020 11:42:58 AM - CMDPHP: Poller[0] WARNING: Cacti Master Poller process terminated by user
07/22/2020 11:45:01 AM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval! The Poller Interval is '300' seconds, with a maximum of a '300' second Cron, but 312 seconds have passed since the last poll!