Install Cacti on Google Cloud
In this posting you will be learning how to install Cacti on Google Cloud Platform using RockyLinux 8.
Addition Information
Step 1 – Swap Space
We will use the e2-micro instance with 0.25-2 vCPU ( 1 shared core) and 1 GB of RAM for this installation. Due to this limited memory, we are going to add some swap space to this system:
sudo fallocate -l 1G /swapfile sudo mkswap /swapfile sudo chmod 0600 /swapfile sudo swapon /swapfile
This will create a 1GB swapfile in the root directory. For it to be enabled during boot, we add a new statement to the /etc/fstab file:
sudo echo "/swapfile none swap defaults 0 0" >> /etc/fstab
Step 2 – Prerequisites
First, we must install some of the software packages needed for Cacti to run correctly. Using a minimal installation, we need to install the following repositories and packages
- epel and remi repository
- rrdtool
- Apache
- MariaDB
- PHP and modules
- gcc, net-snmp, and dev packages for spine installation
To use python for scripting purposes ( or ansible), we are also going to install it as well.
Let’s proceed with the package installation on our RockyLinux 8 system. So, we will enable the required EPEL ad REMI repositories:
sudo dnf install -y epel-release sudo dnf install -y dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm sudo dnf -y module reset php sudo dnf -y module enable php:remi-8.0 sudo dnf config-manager --set-enabled powertools
Now we can proceed with installing the packages:
dnf -y install mariadb-server php php-mysqlnd php-cli net-snmp-utils rrdtool gcc mariadb-devel dnf -y install net-snmp-devel autoconf automake libtool dos2unix wget php-posix php-ldap php-mbstring php-gd dnf -y install php-gmp php-zip php-json php-xml php-gettext php-curl php-intl help2man sudo dnf -y install net-snmp net-snmp-devel net-snmp-utils
Now let’s install git and python, and also make sure we have the setuptool-rust installed in case we want to run ansible. Lastly, we also install some tools to manage SELinux:
sudo dnf -y install git python3-pip python3-devel python3-dnf sudo dnf -y install policycoreutils-gui sudo pip3 install setuptools-rust sudo pip3 install --upgrade pip
To have all packages up-to-date, let’s do a quick upgrade on our system as well:
sudo dnf -y upgrade
The above completes the specifics for the install Cacti on Google Cloud. Most of the tasks below are also valid for a CentOS7/RHEL7 installation.
In the next step, we will make sure that our webserver and the database are automatically starting up after a reboot. To do this, use the following commands to enable these:
sudo systemctl enable httpd.service sudo systemctl enable mariadb.service sudo systemctl restart mariadb.service
Now that we have the database server started, we need to populate it with the timezone data:
# Create the timezone data and import it into the mysqldatabase sudo mysql_tzinfo_to_sql /usr/share/zoneinfo > /tmp/mysql_timezone.sql sudo mysql mysql < /tmp/mysql_timezone.sql
Next, we need to change some settings for the MariaDB server. These will ensure that spine and Cacti are utilizing the database connection optimally. The following settings are for a 1GB memory system.
Don’t worry; Cacti will provide you with some recommended settings for your system during the installation process.
So, let’s edit the /etc/my.cnf.d/mariadb-server.cnf file and add the following lines to the [mysqld] section:
max_heap_table_size=90M max_allowed_packet=16M tmp_table_size=6M join_buffer_size=6M innodb_file_per_table=ON innodb_buffer_pool_instances=3 innodb_buffer_pool_size=256M innodb_doublewrite=OFF innodb_lock_wait_timeout=50 innodb_flush_log_at_trx_commit=2 max_connections=50 character_set_server=utf8mb4 character_set_client=utf8mb4 collation_server=utf8mb4_unicode_ci default-time-zone='Europe/Berlin' 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 innodb_file_format=Barracuda innodb_large_prefix=1
Make sure to adapt the default-time-zone to your requirements
Next, we need to restart the web server as well as the Maria DB service to continue the installation:
systemctl restart httpd.service systemctl restart mariadb.service
[the_ad_placement id=”default-manual”]
Step 3 – Cacti Files
Let’s now move to the actual installation of Cacti. First, we need to download and extract it. As of this writing, the current Cacti Version is 1.2.22.
cd /var/www/html wget http://www.cacti.net/downloads/cacti-latest.tar.gz tar -xzvf cacti-latest.tar.gz
Let’s now rename the cacti directory:
mv cacti-1.2.27 cacti
Step 4 – File permissions
We also need to make sure that the ownership of the required cacti directory is set correctly:
chown -R apache.apache /var/www/html/cacti/rra /var/www/html/cacti/log
Step 5 – Cacti Database
Now that we have extracted the cacti files, we can prepare the database for the final installation step. Your first step should be securing the MySQL database. The following command will help you with this task on a CentOS system. Make sure to select a strong password for root, e.g., MyN3wpassw0rd
/usr/bin/mysql_secure_installation
Let’s create a new database and assign a unique user to it:
# Create the Cacti database and populate it with the default data mysqladmin -u root -p create cacti mysql -p cacti < /var/www/html/cacti/cacti.sql mysql -u root -p
With the last command, you should see a MySQL prompt where you can enter MySQL commands. Here we are going to create a unique cacti user. That user only needs to be able to connect from the local system and should also have a strong password. Enter the following commands and make sure to replace the password:
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost IDENTIFIED BY 'MyV3ryStr0ngPassword'; GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'MyV3ryStr0ngPassword'; flush privileges; exit
We now have the cacti files and the cacti database setup. The last step before moving to the web-based installer is setting the database credentials within the Cacti config file:
cd /var/www/html/cacti/include/ vi config.php
Change the $database_ lines to fit your new settings:
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "MyV3ryStr0ngPassword"; $database_port = "3306"; $database_ssl = false;
Depending on your installation, you should also uncomment the following line. In our example, we have to make sure the next line is there:
$url_path = "/cacti/";
Step 6 – Adding firewall rules
The following settings will enable the firewall and add access rules to HTTP and HTTPS from outside:
systemctl enable firewalld systemctl start firewalld firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
Step 7- Important PHP Settings
The default PHP installation usually has not configured the correct timezone or PHP error reporting. While not required to run Cacti, it’s highly recommended to enable error reporting to Syslog for troubleshooting issues with plugins or other scripts.
The following lines need to be enabled/configured in your /etc/php.ini file:
; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Europe/Berlin
and
; Log errors to syslog (Event Log on NT, not valid in Windows 95). error_log = syslog
We also increase the memory limit and max execution time:
memory_limit = 400M
max_execution_time = 60
We now restart the HTTP and PHP-FPM services so the changes become active
systemctl restart httpd.service systemctl restart php-fpm
Step 8 – Set SELinux Context for http directory
SELinux interferes with the installation, so let’s disable it. Nevertheless, we will prepare the HTML directory to have the correct SELinux context :
sudo setenforce 0 sudo chcon -R -t httpd_sys_rw_content_t /var/www/html sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html(/.*)?"
Step 8 – Running the Web-based installer
Let’s move on to the web-based installer.
TBD
Login with admin/admin, and you’re ready to go!
Please go to “Console -> System Utilities” and click on “Rebuild Poller Cache” after the first login!
Step 9 – Installing Spine
Now let us look into installing Spine as a replacement of the cmd.php poller.
The following task will download, compile and configure the spine poller:
## Install Spine cd /tmp wget https://files.cacti.net/spine/cacti-spine-latest.tar.gz tar -xzvf cacti-spine-latest.tar.gz cd cacti-spine-1.2.27 sudo ./bootstrap sudo ./configure sudo make sudo make install sudo chown root:root /usr/local/spine/bin/spine sudo chmod +s /usr/local/spine/bin/spine sudo cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf sudo sed -i "s/DB_Pass cactiuser/DB_Pass MyV3ryStr0ngPassword/ig" /usr/local/spine/etc/spine.conf
Step 10 – Cron Job
Cacti uses cron (scheduled task) to execute its polling process. It’s always a good idea to run this under a different user than root.
Let’s now add a new cron entry to your system for a 1-minute polling interval using the following command:
echo "*/1 * * * * apache php /var/www/html/cacti/poller.php &>/dev/null" >> /etc/cron.d/cacti
Need Commercial Support on how to install Cacti on Google Cloud Platform?
Urban-Software.de offers commercial Cacti support for Cacti itself and several plugins ( e.g., Thold ).
There’s going to be an on-demand solution in the future. You can contact us for more details using the contact form.
If you require free support, please visit the cacti forum!