Hi There!! Hope you have been doing well 🙂
Today I will explain you how to install & setup Cacti Monitoring server on an RHEL/CentOS machine.
Cacti is an agent-less, open-source Apache-PHP-MySQL webserver based monitoring application. You can use Cacti to monitor performance of your Linux servers from a single location i.e. Cacti Server. It shows the data in the form of graphs for various performance parameters like CPU usage, RAM, Disk Space utilization, Number of processes, Ping statistics & many others. Cacti consists of PHP scripts that pull data from servers being monitored & store in its MySQL database. Then these PHP scripts plot the graphs using that data.
Cacti is an agent-less tool based on
SNMP(Server Network Monitoring Protocol) which means we don’t have to install Cacti agent on all individual servers that we want to be monitored. We just need
snmpd(SNMP daemon) package to be installed on all our client servers that Cacti server will monitor. I will come to Cacti client’s configuration in next post. In this post, I will only focus on Cacti server. Lets start with Cacti server setup 🙂
Install required software. Since Cacti depends on a lot of software, lets list down all the packages that need to be installed first. We need to install below mentioned packages.
php.x86_64 php-cli.x86_64 php-common.x86_64 php-mysql.x86_64 php-pdo.x86_64 rrdtool.x86_64 net-snmp.x86_64 net-snmp-devel.x86_64 net-snmp-libs.x86_64 net-snmp-perl.x86_64 net-snmp-utils.x86_64
Create cacti user. Create cacti user & assign its password. I have already created it.
[root@server ~]# id -a cactiuser uid=513(cactiuser) gid=515(cactiuser) groups=515(cactiuser)
Download & Install Cacti from its official site. Cacti tarball consists of PHP & MySQL scripts. Just unpack it to your Apache’s Document Root (by default, its
/var/www/html). You may wish to rename cacti directory as it consists of version number in its name. Install Apache first, if not already installed. Change ownership to cactiuser for this directory.
[root@server ~]# tar xzvf cacti-0.8.8e.tar.gz
[root@server ~]# chown -R cactiuser.cactiuser /var/www/html/cacti
[root@server ~]# ls -ld /var/www/html/cacti/ drwxr-xr-x. 13 cactiuser cactiuser 4096 Jul 18 20:01 /var/www/html/cacti/
Setup MySQL Database. As we know Cacti fetches data from servers & stores in MySQL database, we need to create a database for Cacti here. Install MySQL if its not installed & start
[root@server ~]# mysqladmin -uroot -p create cacti
Now we will need to create a user for Cacti database & grant it privileges.
[root@server ~]# mysql -uroot-p Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 23 Server version: 5.1.52 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiusr'; mysql> flush privileges;
Now that Cacti database user is ready, lets execute a few MySQL scripts to build up the database. Below command imports the database objects from cacti.sql script to cacti database.
[root@server ~]# mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql
Now edit the file
/var/www/html/cacti/include/config.php to update the database details as below.
/* make sure these values refect your actual database/host/user/password */ $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "cactiusr"; $database_port = "3306"; $database_ssl = false;
Cacti is ready to fetch data & store it. But we need to setup the polling interval first.
Setup polling interval. Polling means the time after which Cacti will pull data to be graphed. As you would have guessed it, we need to setup a
cron job for this. We will do it in cactiuser’s cron because for some reason, I was not able to run Cacti cron job with root user. Below is the syntax of this cron.
[root@server cacti]# crontab -l -u cactiuser */5 * * * * /usr/bin/php -q /var/www/html/cacti/poller.php > /dev/null 2>&1
If everything is done properly, we can now install Cacti web front-end (I told you, Cacti runs as a web application).
Install Cacti web front-end. Restart Apache service & then open your browser. Enter this address
You will see the installation screen like below. Just follow the instructions & go on to install it.
At this point, you will be shown if all pre-required Cacti components are installed or not. if everything is installed properly, you will see it highlighted in green. If not, then make sure the pre-required packages are installed.
Once the front-end is installed, it will ask you to enter the Admin password. Credentials are admin/admin. You will be forced to change it at this step.
Cacti is now successfully installed 🙂 We will have to wait for some time so that poller collects the data for graphs. Click on graphs tab and you will see options to see various graphs.
Since my VM doesn’t run continuously for hours or days, my graphs are not that good-looking 😉 By default, only the localhost will be monitored.
For client servers, there will be additional configurations that I will discuss in next post. Till then, keep playing with it 🙂