×
Community Blog How to Install Cacti on Ubuntu 16.04

How to Install Cacti on Ubuntu 16.04

In this tutorial, we will be installing and configuring Cacti on an Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 16.04 server.

By Hitesh Jethva, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

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 16.04 server.

Requirements

  • A fresh Alibaba Cloud Ubuntu 16.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 16.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.0 -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.0-xml php7.0-ldap php7.0-mbstring php7.0-gd php7.0-gmp snmp php7.0-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.0/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:

1

Now, accept the license agreement and click on Begin button. You will be redirected to the Cacti pre-installation check page:

2

3

4

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

5

Here, choose the installation type and click on the Next button. You should see the following page:

6

Make sure all the required values are correct. Then, click on the Next button. You should see the following page:

7

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:

8

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

9

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:

10

Congratulations! You have successfully installed Cacti monitoring tool on Ubuntu 16.04 server.

0 0 0
Share on

Alibaba Clouder

1,408 posts | 218 followers

You may also like

Comments

Alibaba Clouder

1,408 posts | 218 followers

Related Products