Ở bài viết Phần 1 trước đó ,các bạn đã cài đặt xong Ubuntu Server. Bây giờ chúng ta tiến hành đến việc Cài đặt cho Cacti nhé.


1. Điều kiện tiên quyết - Prerequisites

sudo apt update

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)


2. Install Apache & PHP

sudo apt install -y apache2 php-mysql libapache2-mod-php

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)3. Install PHP Extensions

sudo apt install -y php-xml php-ldap php-mbstring php-gd php-gmp


4. Install MariaDB

sudo apt install -y mariadb-server mariadb-client

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)


5. Install SNMP

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)


6. Database Tuning

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)Tiến hành Add/Update

collation-server = utf8mb4_unicode_ci
max_heap_table_size = 128M
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_buffer_pool_size = 512M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
innodb_io_capacity = 5000
innodb_io_capacity_max = 10000

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)Để lưu lại file bạn sửa, nhấn tổ hợp phím Ctrl + O > sau đó nhấn Enter 

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)Để thoát khỏi file bạn đang sửa, nhấn tổ hợp phím Ctrl + X

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)

Restart lại file bạn vừa update bằng lệnh: sudo systemctl restart mariadb


7. PHP Configuration

sudo nano /etc/php/7.4/apache2/php.ini

Sau khi bạn đã vào được file apache2 để chỉnh sửa. Nhấn tổ hợp phím Ctrl + Q để tiến hành tìm kiếm sửa đổi các thông tin sau:

date.timezone = Asia/Ho_Chi_Minh
memory_limit = 512M
max_execution_time = 60

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)

Sau khi đã trình sửa xong, các bạn làm tương tự Ctrl + O và nhấn Enter để lưu lại, Ctrl + X để thoát khỏi file.

Tiếp tục đến chỉnh sửa file cli, các bạn cũng làm tương tự như vậy với các thông số sau:

date.timezone = Asia/Ho_Chi_Minh
memory_limit = 512M
max_execution_time = 60

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)


8. Create Database

sudo mysql -u root -p

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)
create database cacti;

GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cacti';
flush privileges;
exit
Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)

sudo mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql
    Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)
sudo mysql -u root -p
GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
flush privileges;
exit

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)


9. Download & Configure Cacti

wget https://www.cacti.net/downloads/cacti-latest.tar.g

tar -zxvf cacti-latest.tar.gz

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)sudo mv cacti-1* /opt/cacti
sudo mysql -u root -p cacti < /opt/cacti/cacti.sql
sudo nano /opt/cacti/include/config.php

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)Thay đổi các thông tin của database:

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
$database_ssl = false;

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)

Tạo tệp crontab để lên lịch công việc

sudo nano /etc/cron.d/cacti

Thêm mục lập lịch sau vào crontab để Cacti có thể thăm dò ý kiến ​​mỗi 5 phút

*/5 * * * * www-data php /opt/cacti/poller.php > /dev/null 2>&1

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)Tạo một trang web mới cho Cacti bằng cấu hình sau:

sudo nano /etc/apache2/sites-available/cacti.conf

Alias /cacti /opt/cacti

  <Directory /opt/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>

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)Kích hoạt web đã tạo

sudo a2ensite cacti

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)

Khởi động Apache services

sudo systemctl restart apache2

Tạo tệp nhật ký cho Cacti và cho phép người dùng Apache (www-data) ghi dữ liệu vào thư mục Cacti.

sudo touch /opt/cacti/log/cacti.log
sudo chown -R www-data:www-data /opt/cacti/


10. Visit the below URL to begin the installation of Cacti

 

http://your_ip_address/cacti

Username: admin
Password: admin

Hướng dẫn cài đặt Cacti trên Ubunto Server Full Hướng dẫn chi tiết trên vCenter 6.7(P2)


Như vậy là các bạn đã cài đặt thành công Cacti rồi nhé! Ở bài viết sau mình sẽ hướng dẫn các bạn cách để tạo thiết bị, cũng như làm thế nào để giám sát hệ thống hiệu quả trên Cacti nhé. 

Chúc các bạn thành công