Tutorial Alibaba Cacti

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

How to install Cacti on instance Alibaba Cloud

Cacti is a free and open source web-based network monitoring and graphing tool designed as
the PHP front-end application for the RRDtool. Cacti is a complete frontend to RRDTool that stores all
of the necessary information to create graphs and populate them with data in a MySQL database. Cacti
allow us to check the services at an interval of time and resulting in the graph format. It is used to get a
graph data for the CPU and network bandwidth utilization and monitors the network traffic by polling a
router or switch via SNMP protocol. You can easily monitor the performance of your server, network,
router, switch, web application and other services like, Mysql, Apache, Mail server, and DNS using
Cacti. Cacti provide a fast poller, advanced graph templating, multiple data acquisition methods, and
user management features out of the box.
In this tutorial, we will be installing and configuring Cacti monitoring tool on an Alibaba Cloud Elastic
Compute Service (ECS) Ubuntu 18.04 server.

Requirements
✔ A fresh Alibaba Cloud Ubuntu 18.04 instance.
✔ A static IP address is set up in your instance.
✔ A root password is set up to your instance.

Launch Alibaba Cloud ECS Instance


First, Login to your Alibaba Cloud ECS Console. Create a new ECS instance, choosing Ubuntu 16.04
as the operating system with at least 2GB RAM. Connect to your ECS instance and log in as the root
user.
Once you are logged into your Ubuntu 18.04 instance, run the following command to update your base
system with the latest available packages.

# apt-get update -y

Install Apache, MariaDB and PHP


Cacti run on the web server, written in PHP and uses MariaDB to store their data. So, you will
need to install Apache, MariaDB and PHP to your server. You can install all of them by running the
following command:
#apt-get install -y apache2 mariadb-server mariadb-client php-mysql libapache2-mod-php7.2 -y

Next, you will also need to install some other required packages like, snmp, rrdtool and PHP
modules to your server. You can install them by running the following command:

#apt-get install php7.2-xml php7.2-ldap php7.2-mbstring php7.2-gd php7.2-gmp snmp php7.2-snmp rrdtool librrds-perl -y

Configure Database

By default, MariaDB installation is not secured. So, you will need to secure it first. You can
secure it by running the mysql_secure_installation script:
# mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none):


Set root password? [Y/n]: N
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

After securing MariaDB, log in to MariaDB console with the following command:

#mysql -u root -p

Enter your root password when prompt, then create a database and user for Cacti:

MariaDB [(none)]> create database cactidb;


MariaDB [(none)]> GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'password';

Next, flush the privileges with the following command:

MariaDB [(none)]> flush privileges;

Finally, exit from the MariaDB console with the following command:

MariaDB [(none)]> exit;

Next, you will need to change some MariaDB variables settings for better performances. You can do
this by editing /etc/mysql/mariadb.conf.d/50-server.cnf file:

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

Add the following lines under [mysqld] section:

collation-server = utf8mb4_unicode_ci
max_heap_table_size = 128M
tmp_table_size = 64M
join_buffer_size = 64M
innodb_buffer_pool_size = 512M
innodb_doublewrite = off
innodb_additional_mem_pool_size=96M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16

Save and close the file. When you are finished. Then, change Timezone setting in php.ini file:

#nano /etc/php/7.2/apache2/php.ini

Make the following changes:

#date.timezone = Asia/Kolkata

Save and close the file. Then, restart Apache and MariaDB service with the following command:

systemctl restart apache2


systemctl restart mysql

Download and Install Cacti

You can install Cacti using two ways, 1) Install Cacti from Ubuntu default repository and 2) Install
Cacti from Source.

Here, we will install Cacti from Source. You can download the latest version of the Cacti from their
official website using the following command:

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

Once the download is completed, extract the downloaded file and copy the extracted directory to the
Apache web root directory with the following command:

#tar -xvzf cacti-latest.tar.gz


#cp -r cacti-1.1.38 /var/www/html/cacti
Next, create a log file to store Cacti log and give proper permissions to the cacti directory with
the following command:
#touch /var/www/html/cacti/log/cacti.log
#chown -R www-data:www-data /var/www/html/cacti
#chmod -R 777 /var/www/html/cacti

Next, you will need to import cacti database tables from the cacti.sql file. You can do this with
the following command:

#cd /var/www/html/cacti
#mysql -u root -p cactidb < /opt/cacti/cacti.sql

Next, edit config.php file and provides Cacti database credentials:

#nano include/config.php

Make the following changes:

$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "password";
$database_port = "3306";
$database_ssl = false;

Save and close the file, when you are finished.

Configure Apache for Cacti

Next, you will need to create an Apache Virtual host file for Cacti. You can do this by creating
the following file:

#nano /etc/apache2/sites-available/cacti.conf
Add the following lines:

<VirtualHost *:80>
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>
</VirtualHost>

Save and close the file. Then, enable Apache virtual host file with the following command:

#a2ensite cacti
Finally, restart Apache service to apply all the changes:

#systemctl restart apache2

Next, you will need to create a cronjob for Cacti poller service that poll every five minutes.

#nano /etc/crontab

Add the following line:

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

Save and close the file. Then, restart cron service with the following command:

systemctl restart cron

Access Cacti Web Installation Wizard

Cacti is now installed. It's time to set up it through a web browser.

Open your web browser and type the URL http://your-server-ip/cacti. You will be redirected to
the Cacti license agreement page:
Now, accept the license agreement and click on Begin button. You will be redirected to the Cacti pre-
installation check page:

Make sure all the required packages are installed. Then, click on the Next button. You should see the
following page:
Here, choose the installation type and click on the Next button. You should see the following page:

Make sure all the required values are correct. Then, click on the Next button. You should see the
following page:
Here, select the Templates that you wish to use after the installation. Then, click on the Finish
button. You will be redirected to the Cacti login page:

Now, provide default username/password as admin/admin. Then, click on the Login button. You
will be redirected to the Change password page:

Here, change your current password and click on the Save button. You will be redirected to the
Cacti default dashboard as shown on the following page:
Congratulations! You have successfully installed Cacti monitoring tool on Ubuntu 18.04 server.
Tips and Triks Cacti
1. Problem Cacti corrupt database
After rebooting a Cacti server, the customer complained that no new graphs were drawn by the server. I
tried to run the poller.php script with the –-force option and noticed the following output:
“Poller[0] ERROR: SQL Failed! Error:’145′, Message:’Table ‘./cacti/poller_output’ is marked as
crashed and should be repaired’, SQL Fragment:”

Mysql has an option to check and repair the database. So I gave that a try via the following
command:

#mysqlcheck --auto-repair --databases cactidb

The command gives the following output:

cactidb.aggregate_graph_templates OK
cactidb.aggregate_graph_templates_graph OK
cactidb.aggregate_graph_templates_item OK
cactidb.aggregate_graphs OK
cactidb.aggregate_graphs_graph_item OK
cactidb.aggregate_graphs_items OK
cactidb.automation_devices OK
cactidb.automation_graph_rule_items OK
cactidb.automation_graph_rules OK
cactidb.automation_ips OK
cactidb.automation_match_rule_items OK
cactidb.automation_networks OK
cactidb.automation_processes OK
cactidb.automation_snmp OK
cactidb.automation_snmp_items OK
cactidb.automation_templates OK
cactidb.automation_tree_rule_items OK
cactidb.automation_tree_rules OK
cactidb.cdef OK
cactidb.cdef_items OK
cactidb.color_template_items OK
cactidb.color_templates OK
cactidb.colors OK
cactidb.data_debug OK
cactidb.data_input OK
cactidb.data_input_data OK
cactidb.data_input_fields OK
cactidb.data_local OK
cactidb.data_source_profiles OK
cactidb.data_source_profiles_cf OK
cactidb.data_source_profiles_rra OK
cactidb.data_source_purge_action OK
cactidb.data_source_purge_temp OK
cactidb.data_source_stats_daily OK
cactidb.data_source_stats_hourly OK
cactidb.data_source_stats_hourly_cache OK
cactidb.data_source_stats_hourly_last OK
cactidb.data_source_stats_monthly OK
cactidb.data_source_stats_weekly OK
cactidb.data_source_stats_yearly OK
cactidb.data_template OK
cactidb.data_template_data OK
cactidb.data_template_rrd OK
cactidb.external_links OK

After the repair I ran the poller.php script again with the –-force option and this time I didn’t receive
any errors and the graphs were updated again.
Afterwards I noticed that Cacti has a script of its own to repair the database. This script is called
repair_database.php and can be found in the directory /var/www/html/cli/.

2. Problem Error Timezone


Make sure on server Mysql with command

MariaDB [(none)]> show variables like '%time_zone%';


+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
Please open privilege time_zone on database cactidb. With command below

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;


MariaDB [(none)]> flush privileges;

You must to restart service mysql, to make sure config on cacti solved
#systemctl restart mysql

You must to check time_zone on config php in /etc/php/7.2/cli/php.ini and


/etc/php/7.2/apache2/php.ini

You might also like