Ubuntu 22.04
Sponsored Link

Cacti : インストール
2022/12/14
 
Cacti をインストールして、システムの状態を監視します。
[1]
[2]
[3]
[4]
[5] Cacti および SNMP をインストールします。
root@dlp:~#
apt -y install cacti snmp snmpd snmp-mibs-downloader libnet-snmp-perl snmptrapd php-mysql php-snmp rrdtool
# apache2 を選択
   +-------------------------+ Configuring cacti +--------------------------+
   | Please select the web server for which Cacti should be automatically   |
   | configured.                                                            |
   |                                                                        |
   | Select "None" if you would like to configure the web server manually.  |
   |                                                                        |
   | Web server:                                                            |
   |                                                                        |
   |                                apache2                                 |
   |                                lighttpd                                |
   |                                None                                    |
   |                                                                        |
   |                                                                        |
   |                                 <Ok>                                   |
   |                                                                        |
   +------------------------------------------------------------------------+

# No を選択
 +---------------------------+ Configuring cacti +---------------------------+
 |                                                                           |
 | The cacti package must have a database installed and configured before    |
 | it can be used.  This can be optionally handled with dbconfig-common.     |
 |                                                                           |
 | If you are an advanced database administrator and know that you want to   |
 | perform this configuration manually, or if your database has already      |
 | been installed and configured, you should refuse this option.  Details    |
 | on what needs to be done should most likely be provided in                |
 | /usr/share/doc/cacti.                                                     |
 |                                                                           |
 | Otherwise, you should probably choose this option.                        |
 |                                                                           |
 | Configure database for cacti with dbconfig-common?                        |
 |                                                                           |
 |                    <Yes>                       <No>                       |
 |                                                                           |
 +---------------------------------------------------------------------------+
[6] SNMP (Simple Network Management Protocol) を設定します。
root@dlp:~#
vi /etc/snmp/snmp.conf
# 4行目 : コメント化

#
mibs :
root@dlp:~#
vi /etc/snmp/snmpd.conf
# 18, 19行目 : 任意のロケーション名称とメールアドレスに変更
sysLocation    "Server World"
sysContact     "root@dlp.srv.world"

# 71, 72行目 : コメント化
# 73行目 : 任意のコミュニティ名を追記
#rocommunity  public default -V systemonly
#rocommunity6 public default -V systemonly
rocommunity Serverworld localhost

root@dlp:~#
systemctl restart snmpd

# 動作確認
# [Serverworld] の箇所は設定したコミュニティ名

root@dlp:~#
snmpwalk -v 2c -c Serverworld localhost system

SNMPv2-MIB::sysDescr.0 = STRING: Linux dlp.srv.world 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1121) 0:00:11.21
SNMPv2-MIB::sysContact.0 = STRING: "root@dlp.srv.world"
SNMPv2-MIB::sysName.0 = STRING: dlp.srv.world
SNMPv2-MIB::sysLocation.0 = STRING: "Server World"
SNMPv2-MIB::sysServices.0 = INTEGER: 72
.....
.....
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.9 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.10 = Timeticks: (0) 0:00:00.00
[7] Cacti 用のユーザーとデータベースを MariaDB に登録し、テーブルをインポートしておきます。
root@dlp:~#
mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 60
Server version: 10.6.11-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04

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)]> create database cacti character set utf8mb4 collate utf8mb4_unicode_ci; 
Query OK, 1 row affected (0.00 sec)

# [password] は任意のパスワードに置き換え
MariaDB [(none)]> grant all privileges on cacti.* to cacti@'localhost' identified by 'password'; 
Query OK, 0 rows affected (0.00 sec)

# Cacti 動作要件として [mysql] DB の [time_zone_name] に [select] 権限付与
MariaDB [(none)]> grant select on mysql.time_zone_name to cacti@'localhost'; 

MariaDB [(none)]> flush privileges; 
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

# タイムゾーン情報設定

root@dlp:~#
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
root@dlp:~#
mysql -u cacti -p cacti < /usr/share/doc/cacti/cacti.sql

Enter password:  
# cacti ユーザーのパスワード
[8] Cacti の設定です。
root@dlp:~#
vi /usr/share/cacti/site/include/config.php
# 45行目 : DB 接続情報を変更
$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti';
$database_password = 'password';
$database_port     = '3306';
.....
.....

root@dlp:~#
vi /etc/mysql/mariadb.conf.d/50-server.cnf
# [mysqld] セクションに追記 (Cacti 要件)
[mysqld]
character-set-server=utf8mb4
character_set_client=utf8mb4
collation-server=utf8mb4_unicode_ci
max_heap_table_size=128M
tmp_table_size=128M
join_buffer_size=256M
innodb_buffer_pool_size=2048M
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_buffer_pool_instances=17
innodb_io_capacity=5000
innodb_io_capacity_max=10000
innodb_doublewrite=off

# 103, 104行目 : コメント化
#character-set-server  = utf8mb4
#collation-server      = utf8mb4_general_ci

root@dlp:~#
vi /etc/php/8.1/apache2/php.ini
# 968行目 : コメント解除してデフォルトタイムゾーン設定

date.timezone =
Asia/Tokyo
root@dlp:~#
vi /etc/php/8.1/apache2/php.ini
# 409行目 : Cacti 推奨値に変更

max_execution_time =
60
# 430行目 : Cacti 推奨値に変更

memory_limit =
512M
# 968行目 : コメント解除してデフォルトタイムゾーン設定

date.timezone =
Asia/Tokyo
root@dlp:~#
vi /etc/apache2/conf-available/cacti.conf
# 7行目 : 必要に応じてアクセス許可範囲を変更

#
Require all granted
Require host localhost
Require ip 10.0.0.0/24
root@dlp:~#
chown -R www-data /usr/share/cacti/site/resource/snmp_queries \
/usr/share/cacti/site/resource/script_server \
/usr/share/cacti/site/resource/script_queries \
/usr/share/cacti/site/scripts \
/var/log/cacti

root@dlp:~#
systemctl restart apache2 mariadb

関連コンテンツ