LoginSignup
0
1

Ubuntu 22.04 に Cacti インストール

Posted at

Ubuntu 22.04 に Cacti インストール

前提環境

  • OS: Ubuntu Server 22.04.04 LTS
  • 仮想基盤: VMware ESXi
  • CPU: 2 vCPU
  • MEMORY: 4 GB
  • DISK: 100 GB
  • DB: MariaDB
  • Cacti: Version 1.2.26

OSインストール

  • 基本デフォルト
  • キーボードは日本語に設定

OSインストール後の基本設定

タイムゾーン設定

  • 現状確認
$ sudo timedatectl status
               Local time: Thu 2024-04-04 01:56:20 UTC
           Universal time: Thu 2024-04-04 01:56:20 UTC
                 RTC time: Thu 2024-04-04 01:56:20
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
$
  • UTC になっているので変更
$ sudo timedatectl set-timezone 'Asia/Tokyo'
  • 再度確認
$ sudo timedatectl status
  • dateコマンドでも確認
$ date
Thu 15 Feb 2024 10:54:29 AM JST

timesyncd 設定

  • 設定ファイル編集
$ sudo vi /etc/systemd/timesyncd.conf
  • 差分
  [Time]
+ NTP=NTP=ntp.nict.jp
  #FallbackNTP=ntp.ubuntu.com
  • systemd-timesyncd サービス restart 実施
$ sudo systemctl restart systemd-timesyncd
  • timesync-status で確認
$ sudo timedatectl timesync-status

sshd keepalive 設定変更

これは好みで。作業中に離席中にsshが切れると悲しいので、設定している。

$ sudo vi /etc/ssh/sshd_config
  • 差分
- #ClientAliveInterval 0
+ ClientAliveInterval 60
  • sshd restart
$ sudo /etc/init.d/ssh restart

ミドルウェアインストールと設定

パッケージアップデート

$ sudo apt update
$ sudo apt upgrade -y

apache2 インストール

$ sudo apt -y install apache2

PHP 8.3 インストール

  • レポジトリ追加
    ※Ubuntu24.04 では不要
$ sudo add-apt-repository ppa:ondrej/php
$ sudo add-apt-repository ppa:ondrej/apache2
$ sudo apt update
$ sudo apt upgrade -y
  • PHP 8.3 インストール
$ sudo apt -y install php8.3 php8.3-mbstring php-pear php8.3-gd php8.3-gmp php8.3-intl php8.3-ldap libapache2-mod-php8.3

PHP 初期動作チェック

  • バージョン確認
$ php -v
  • 簡単に動作チェック
$ echo '<?php echo `php -i`."\n"; ?>' > php_test.php
$ php php_test.php | head

php.ini 編集

  • apache2 の php.ini 編集
$ sudo cp -p /etc/php/8.3/apache2/php.ini /etc/php/8.3/apache2/php.ini.orig
$ sudo vi /etc/php/8.3/apache2/php.ini
  • 差分
 [Date]
 ; Defines the default timezone used by the date functions
 ; https://php.net/date.timezone
-;date.timezone =
+date.timezone = Asia/Tokyo

 ; https://php.net/date.default-latitude
 ;date.default_latitude = 31.7667
  • cli の php.ini 編集
$ sudo cp -p /etc/php/8.3/cli/php.ini /etc/php/8.3/cli/php.ini.orig
$ sudo vi /etc/php/8.3/cli/php.ini
  • 差分
 [Date]
 ; Defines the default timezone used by the date functions
 ; https://php.net/date.timezone
-;date.timezone =
+date.timezone = Asia/Tokyo

 ; https://php.net/date.default-latitude
 ;date.default_latitude = 31.7667
  • apache2 reload
$ sudo systemctl reload apache2
  • PHPテストページ作って確認
    ここはラクして root で実施。
$ sudo su
Password:
# echo '<?php phpinfo(); ?>' > /var/www/html/info.php

Webブラウザで実際に見てみる
http://<サーバIPまたはFQDN>/info.php

  • 確認終わったらファイルは削除する
# rm /var/www/html/info.php

MariaDB

  • mariadb インストール
$ sudo apt -y install mariadb-server
  • 初期設定
$ sudo mysql_secure_installation
  • 認証の確認( Unix_Socket のはず )
$ sudo mysql
MariaDB [(none)]> show grants for root@localhost;

表示結果の中に unix_socket があるか確認する。

  • ユーザー情報一覧確認
MariaDB [(none)]> select user,host,password from mysql.user;
  • データベース一覧確認
MariaDB [(none)]> show databases;
  • MariaDB を抜ける
MariaDB [(none)]> exit
Bye
$

snmp その他 インストール

$ sudo apt -y install snmp snmpd snmp-mibs-downloader libnet-snmp-perl snmptrapd php-mysql php-snmp rrdtool

snmp 設定

mibs 行はコメントアウトしておく。

$ sudo vi /etc/snmp/snmp.conf
  • 差分
  # loading them by commenting out the following line.
- mibs :
+ #mibs :

  # If you want to globally change where snmp libraries, commands and daemons

snmpd 設定

$ sudo cp -p /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
$ sudo vi /etc/snmp/snmpd.conf
  • 差分
 #   this token in the snmpd.conf file will disable write access to
 #   the variable.
 #   arguments:  location_string
-sysLocation    Sitting on the Dock of the Bay
-sysContact     Me <me@example.org>
+sysLocation    設置場所などを入れる
+sysContact     <名前やコンタクトポイント> <メールアドレス>

 # sysservices: The proper value for the sysServices object.
 #   arguments:  sysservices_number

 #   are concatenated together (using ':'s).
 #   arguments: [transport:]port[@interface/address],...
 
-agentaddress  127.0.0.1,[::1]
+agentaddress  udp:161


-rocommunity  public default -V systemonly
-rocommunity6 public default -V systemonly
+rocommunity  <コミュニティ名>  localhost
+rocommunity  <コミュニティ名>  192.168.0.0/24(測定先のネットワーク)
  • snmpd restart
$ sudo systemctl restart snmpd
  • snmpd status で起動確認
$ sudo systemctl status snmpd
  • snmpwalk してみる
$ sudo snmpwalk -v 2c -c <コミュニティ名> localhost system

MariaDB に cacti用の設定

  • ログイン
$ sudo mysql
  • データベース 「cacti」 を作成
MariaDB [(none)]> create database cacti character set utf8mb4 collate utf8mb4_unicode_ci;
  • データベース cacti にパスワード設定
MariaDB [(none)]> grant all privileges on cacti.* to cacti@'localhost' identified by 'ほげ';
  • time_zone_name に select権限付与
MariaDB [(none)]> grant select on mysql.time_zone_name to cacti@'localhost';
  • MariaDB を抜ける
MariaDB [(none)]> exit;
  • /etc/mysql/mariadb.conf.d/50-server.cnf を編集
$ sudo cp -p /etc/mysql/mariadb.conf.d/50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf_orig
$ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
  • 差分
$ sudo diff -u /etc/mysql/mariadb.conf.d/50-server.cnf_orig /etc/mysql/mariadb.conf.d/50-server.cnf
[sudo] password for inoue:
--- /etc/mysql/mariadb.conf.d/50-server.cnf.orig        2023-12-02 12:44:37.000000000 +0900
+++ /etc/mysql/mariadb.conf.d/50-server.cnf     2024-04-09 12:39:54.401508992 +0900
@@ -8,6 +8,44 @@
 # this is only for the mysqld standalone daemon
 [mysqld]

+# required for multiple language support
+character-set-server=utf8mb4
+collation-server=utf8mb4_unicode_ci
+
+# Memory tunables - Cacti provides recommendations at upgrade time
+max_heap_table_size=61M
+max_allowed_packet=500M
+tmp_table_size=64M
+join_buffer_size=64M
+#sort_buffer_size=10K
+
+# important for compatibility
+sql_mode=NO_ENGINE_SUBSTITUTION
+
+# innodb settings - Cacti provides recommendations at upgrade time
+innodb_buffer_pool_instances=16
+innodb_flush_log_at_trx_commit=2
+innodb_buffer_pool_size=954M
+#innodb_sort_buffer_size=XXX
+innodb_doublewrite=OFF
+
+# required
+innodb_file_per_table=ON
+innodb_file_format=Barracuda
+innodb_large_prefix=1
+
+# not all version support
+innodb_flush_log_at_timeout=3
+
+# for SSD's/NVMe
+innodb_read_io_threads=32
+innodb_write_io_threads=16
+innodb_io_capacity=10000
+innodb_io_capacity_max=20000
+innodb_flush_method=O_DIRECT
+
+
+
 #
 # * Basic Settings
 #
@@ -87,8 +125,8 @@

 # MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
 # utf8 4-byte character set. See also client.cnf
-character-set-server  = utf8mb4
-collation-server      = utf8mb4_general_ci
+#character-set-server  = utf8mb4
+#collation-server      = utf8mb4_general_ci

 #
 # * InnoDB
$
  • タイムゾーン情報設定
$ sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | sudo mysql -u root mysql
  • アクセス許可設定
$ sudo mysql
MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
MariaDB [(none)]> ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
  • mariadb 再起動
$ sudo systemctl restart mariadb
  • mariadb 起動確認
$ sudo systemctl status mariadb

PHP 追加設定

  • /etc/php/8.3/apache2/php.ini 編集
$ sudo vi /etc/php/8.3/apache2/php.ini
  • 差分
$ sudo diff -u /etc/php/8.3/apache2/php.ini.orig /etc/php/8.3/apache2/php.ini
--- /etc/php/8.3/apache2/php.ini.orig   2024-03-16 17:40:08.000000000 +0900
+++ /etc/php/8.3/apache2/php.ini        2024-04-08 16:16:19.548067938 +0900
@@ -416,7 +416,7 @@
 ; Maximum execution time of each script, in seconds
 ; https://php.net/max-execution-time
 ; Note: This directive is hardcoded to 0 for the CLI SAPI
-max_execution_time = 30
+max_execution_time = 60

 ; Maximum amount of time each script may spend parsing request data. It's a good
 ; idea to limit this time on productions servers in order to eliminate unexpectedly
@@ -442,7 +442,7 @@

 ; Maximum amount of memory a script may consume
 ; https://php.net/memory-limit
-memory_limit = 128M
+memory_limit = 512M

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Error handling and logging ;
@@ -986,7 +986,7 @@
 [Date]
 ; Defines the default timezone used by the date functions
 ; https://php.net/date.timezone
-;date.timezone =
+date.timezone = Asia/Tokyo

 ; https://php.net/date.default-latitude
 ;date.default_latitude = 31.7667
$ 
  • /etc/php/8.3/cli/php.ini 編集 編集
$ sudo vi /etc/php/8.3/cli/php.ini
  • 差分
$ sudo diff -u /etc/php/8.3/cli/php.ini.orig /etc/php/8.3/cli/php.ini
--- /etc/php/8.3/cli/php.ini.orig       2024-03-16 17:40:08.000000000 +0900
+++ /etc/php/8.3/cli/php.ini    2024-04-08 16:18:49.803783823 +0900
@@ -416,7 +416,7 @@
 ; Maximum execution time of each script, in seconds
 ; https://php.net/max-execution-time
 ; Note: This directive is hardcoded to 0 for the CLI SAPI
-max_execution_time = 30
+max_execution_time = 60

 ; Maximum amount of time each script may spend parsing request data. It's a good
 ; idea to limit this time on productions servers in order to eliminate unexpectedly
@@ -442,7 +442,8 @@

 ; Maximum amount of memory a script may consume
 ; https://php.net/memory-limit
-memory_limit = -1
+#memory_limit = -1
+memory_limit = 512M

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Error handling and logging ;
@@ -986,7 +987,7 @@
 [Date]
 ; Defines the default timezone used by the date functions
 ; https://php.net/date.timezone
-;date.timezone =
+date.timezone = Asia/Tokyo

 ; https://php.net/date.default-latitude
 ;date.default_latitude = 31.7667
$ 

Cacti インストールや設定

  • ダウンロード
$ cd /usr/local/src
$ sudo wget https://www.cacti.net/downloads/cacti-latest.tar.gz
  • 展開
$ sudo tar -zxvf cacti-latest.tar.gz
  • apache の www ディレクトリへ移動させる
$ sudo mv cacti-1.2.26 /var/www/html/cacti
  • 権限調整
$ sudo chown -R www-data:www-data /var/www/html/cacti/
  • cacti データを cacti データベースにインポート
$ sudo mysql -u root -p cacti < /var/www/html/cacti/cacti.sql
Enter password: (cacti db のパスワード)
$
  • /var/www/html/cacti/include/config.php の編集
$ sudo cp -p /var/www/html/cacti/include/config.php /var/www/html/cacti/include/config.php.orig
$ sudo vi /var/www/html/cacti/include/config.php
  • 差分
$ sudo diff -u /var/www/html/cacti/include/config.php.orig /var/www/html/cacti/include/config.php
--- /var/www/html/cacti/include/config.php.orig 2023-12-24 11:17:14.000000000 +0900
+++ /var/www/html/cacti/include/config.php      2024-04-08 16:29:14.937822625 +0900
@@ -29,8 +29,8 @@
 $database_type     = 'mysql';
 $database_default  = 'cacti';
 $database_hostname = 'localhost';
-$database_username = 'cactiuser';
-$database_password = 'cactiuser';
+$database_username = 'cacti';
+$database_password = 'ほげ';
 $database_port     = '3306';
 $database_retries  = 5;
 $database_ssl      = false;
$ 
  • cacti の cron実行ファイルを用意する
$ sudo vi /etc/cron.d/cacti
  • ファイルの中身
*/5 * * * * www-data php /var/www/html/cacti/poller.php > /dev/null 2>&1
  • cacti のログファイルを作成
$ sudo touch /var/www/html/cacti/log/cacti.log
  • /var/www/html/cacti/ ディレクトリの権限調整(再調整)
$ sudo chown -R www-data:www-data /var/www/html/cacti/

apache2 設定

  • /etc/apache2/sites-available/cacti.conf 作成
$ sudo vi /etc/apache2/sites-available/cacti.conf
  • ファイルの中身
Alias /cacti /var/www/html/cacti

<Directory /var/www/html/cacti>
    Options +FollowSymLinks
    AllowOverride None
    <IfVersion >= 2.3>
       Require all granted
    </IfVersion>
    <IfVersion < 2.3>
       Order Allow,Deny
       Allow from all
    </IfVersion>
AddType application/x-httpd-php .php

    <IfModule mod_php.c>
        php_flag magic_quotes_gpc Off
        php_flag short_open_tag On
        php_flag register_globals Off
        php_flag register_argc_argv On
        php_flag track_vars On
        # this setting is necessary for some locales
        php_value mbstring.func_overload 0
        php_value include_path .
     </IfModule>
DirectoryIndex index.php
</Directory>
ServerName cacti
  • apache2 仮想ホスト有効化
$ sudo a2ensite cacti
Enabling site cacti.
To activate the new configuration, you need to run:
  systemctl reload apache2
$ 
  • apache2 再起動
$ sudo systemctl restart apache2
  • apache2 ステータス確認
$ sudo systemctl status apache2

各種テンプレートの移植

  • 別ホストでcactiが動いている場合は、テンプレートをエクスポートしてインポートする。

監視ホストを設定

  • GUI でホストを追加していく
  • グラフTreeもGUIでポチポチと

終わり

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1