Skip to content

Testing Environment: Ubuntu

Mark Brugnoli-Vinten edited this page Jul 19, 2018 · 12 revisions

This page documents the process for installation of Cacti 1.x on Ubuntu Versions 18.04, 17.10 and 16.04

It follows the conventions documented in the Test Environments: Before You Start


Ubuntu 18.04

System setup

Configure the network

In order to configure the network, you may need to use the nmcli command or modify /etc/network/interfaces for the ens device found in dmesg.

The installer in Ubuntu 18.04 takes care of most of the basics so the following should no longer be necessary:

hostname _ssh_host_
echo "_ssh_host_" > /etc/hostname
apt install -y screen git openssh-server
useradd _ssh_user_
passwd _ssh_user_
echo "_ssh_user_     ALL=(ALL)     ALL" > /etc/sudoers.d/_ssh_user_

Note: Do NOT use a filename with a fullstop in it as sudo will ignore these by default

Enable SSH login via keys

Create the authorized_keys file with the appropriate SSH keys

mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
cat > .screenrc << EOF
startup_message off
altscreen on
msgwait 0

shell -s $SHELL
term xterm-256color
defscrollback 5000
termcapinfo xterm* ti@:te@
pushd $HOME/
bind R eval "source $HOME/.screenrc" "echo '.screenrc' reload"
bind \033 screen -t "Root Shell" 1 bash -c 'echo Logging in as root; sudo su'
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%'
activity "%c activity -> %n%f %t^G"
screen -t "User Shell" 0 bash -c 'pushd ~/ > /dev/null; bash' 
EOF

If you have predefined keys you wish to insert, simply edit the ~/.ssh/authorized_keys file

Install Apache, SQL and PHP

Package selection may be overkill but to ensure they are definitely installed.

apt install -y php apache2 openssl mysql-server \
php-mysql php-xml php-ldap php-gmp php-mbstring \
php-cli php-common php-pdo php-gd php-snmp \
snmp rrdtool

Website basics

Create some required directories

mkdir -p /etc/ssl/cacti/ \
/var/log/cacti/ \
/usr/share/cacti/{site,feature,develop} 
chown _ssh_user_:_website_user_ -Rv /usr/share/cacti/

Clone Cacti

Run the following as _ssh_user_

sudo su - _ssh_user_
cd /usr/share/cacti
git clone https://github.com/netniv/cacti/ site
cd site/
git remote add upstream https://github.com/cacti/cacti/ && git fetch --all 
cd ../
cp -Rva site/. develop
cp -Rva site/. feature

cd /usr/share/cacti/develop && git branch develop --set-upstream-to upstream/develop && git checkout develop
cd /usr/share/cacti/feature && git branch develop --set-upstream-to upstream/develop && git checkout develop

Change default permissions

Run the following as root

chown -Rv www-data:www-data \
/usr/share/cacti/{site,feature,develop}/resource \
/usr/share/cacti/{site,feature,develop}/scripts \
/usr/share/cacti/{site,feature,develop}/log \
/usr/share/cacti/{site,feature,develop}/cache \
/usr/share/cacti/{site,feature,develop}/rra

chmod u+rw,g+r,g-w,a+r -Rv /usr/share/cacti
chmod u+rw,g+rw,a+r -Rv \
/usr/share/cacti/{site,feature,develop}/log \
/usr/share/cacti/{site,feature,develop}/rra \
/usr/share/cacti/{site,feature,develop}/resource/

Checkout specific versons

cd /usr/share/cacti/site/ && git checkout release/_cacti_version_ 
cd /usr/share/cacti/develop && git branch develop --set-upstream upstream/develop && git checkout develop
cd /usr/share/cacti/feature && git branch feature/1.2.x --set-upstream upstream/<branch> && git checkout <branch>

Create SSL Certificate

mkdir -p /etc/ssl/cacti/
cd /etc/ssl/cacti/

openssl req -new -sha256 -nodes -out _cacti_host_.csr -newkey rsa:2048 -keyout _cacti_host_.key -config <(
cat <<-EOF
[req]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[dn]
C = GB
ST = Alive
L = The World
O = netniV
OU = IT
emailAddress = netniv@hotmail.com
CN = _cacti_host_

[req_ext]
subjectAltName = @alt_names

[alt_names]
DNS.1 = develop._cacti_host_
DNS.2 = feature._cacti_host_
EOF
)
openssl x509 -req -days 1825 -in _cacti_host_.csr -signkey _cacti_host_.key -out _cacti_host_.crt

Create HTTPD configuation

echo 'NameVirtualHost *:443
NamevirtualHost *:80

<VirtualHost *:443>
        ErrorLog /var/log/cacti/site-error.log
        TransferLog /var/log/cacti/site-access.log
        CustomLog /var/log/cacti/site-request.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
        SSLCertificateFile /etc/ssl/cacti/_cacti_host_.crt
        SSLCertificateKeyFile /etc/ssl/cacti/_cacti_host_.key

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
                SSLOptions +StdEnvVars
        </Files>

        <Directory /usr/share/cacti/site/>
                AllowOverride All
        </Directory>

        DocumentRoot /usr/share/cacti/site/
        ServerName _cacti_host_
</VirtualHost>
<VirtualHost *:443>
        ErrorLog /var/log/cacti/develop-error.log
        TransferLog /var/log/cacti/develop-access.log
        CustomLog /var/log/cacti/develop-request.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
        SSLCertificateFile /etc/ssl/cacti/_cacti_host_.crt
        SSLCertificateKeyFile /etc/ssl/cacti/_cacti_host_.key

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
                SSLOptions +StdEnvVars
        </Files>

        <Directory /usr/share/cacti/develop>
                AllowOverride All
        </Directory>

        DocumentRoot /usr/share/cacti/develop
        ServerName _cacti_host_
</VirtualHost>
<VirtualHost *:443>
        ErrorLog /var/log/cacti/feature-error.log
        TransferLog /var/log/cacti/feature-access.log
        CustomLog /var/log/cacti/feature-request.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
        SSLCertificateFile /etc/ssl/cacti/_cacti_host_.crt
        SSLCertificateKeyFile /etc/ssl/cacti/_cacti_host_.key

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
                SSLOptions +StdEnvVars
        </Files>

        <Directory /usr/share/cacti/feature>
                AllowOverride All
        </Directory>

        DocumentRoot /usr/share/cacti/feature
        ServerName _cacti_host_
</VirtualHost>
' > /etc/apache2/sites-available/cacti.conf
a2enmod ssl ldap 
phpenmod ldap snmp gmp
a2ensite cacti
systemctl restart apache2
systemctl status apache2

Enable through firewall if required

This requires the iptables-persistent package since 16.04

iptables -I INPUT 1 -p tcp -m tcp --dport 80 -j ACCEPT
iptables -I INPUT 1 -p tcp -m tcp --dport 443 -j ACCEPT
netfilter-persistent save
netfilter-persistent reload

Configuration MySQL

Enable custom configurations

echo "[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
max_allowed_packet=18M
max_heap_table_size=98M
tmp_table_size=64M
join_buffer_size=64M
innodb_buffer_pool_size=488M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
default_time_zone='+00:00'
" > /etc/mysql/conf.d/cacti.cnf

systemctl restart mysql

Create databases and users

cacti_sql=`mktemp -t XXXXXXXXXXXX -u`

echo "use mysql;
create database if not exists cacti_site; 
create database if not exists cacti_feature; 
create database if not exists cacti_develop;
use cacti_site;
source /usr/share/cacti/site/cacti.sql;
use cacti_feature;
source /usr/share/cacti/feature/cacti.sql;
use cacti_develop;
source /usr/share/cacti/develop/cacti.sql;
" > $cacti_sql;

cacti_pw_site=`mktemp -t XXXXXXXXXXXX -u | sed 's/\/tmp\///'`
cacti_pw_develop=`mktemp -t XXXXXXXXXXXX -u | sed 's/\/tmp\///'`
cacti_pw_feature=`mktemp -t XXXXXXXXXXXX -u | sed 's/\/tmp\///'`

echo "
GRANT ALL PRIVILEGES ON cacti_site.* TO 'cacti_site'@'localhost' IDENTIFIED BY '$cacti_pw_site';
GRANT ALL PRIVILEGES ON cacti_develop.* TO 'cacti_develop'@'localhost' IDENTIFIED BY '$cacti_pw_develop';
GRANT ALL PRIVILEGES ON cacti_feature.* TO 'cacti_feature'@'localhost' IDENTIFIED BY '$cacti_pw_feature';
GRANT SELECT ON mysql.time_zone_name TO 'cacti_site'@'localhost';
GRANT SELECT ON mysql.time_zone_name TO 'cacti_develop'@'localhost';
GRANT SELECT ON mysql.time_zone_name TO 'cacti_feature'@'localhost';
FLUSH PRIVILEGES
" >> $cacti_sql

cat /usr/share/cacti/site/include/config.php.dist | sed "s/^\(\\\$database_default.*=[ ']*\)cacti\([';]*$\)/\1cacti_site\2/g"| sed "s/^\(\\\$database_username.*=[ ']*\)cactiuser\([';]*$\)/\1cacti_site\2/g" | sed "s/^\(\\\$database_password.*=[ ']*\)cactiuser\([';]*$\)/\1$cacti_pw_site\2/g" > /usr/share/cacti/site/include/config.php

cat /usr/share/cacti/develop/include/config.php.dist | sed "s/^\(\\\$database_default.*=[ ']*\)cacti\([';]*$\)/\1cacti_develop\2/g"| sed "s/^\(\\\$database_username.*=[ ']*\)cactiuser\([';]*$\)/\1cacti_develop\2/g" | sed "s/^\(\\\$database_password.*=[ ']*\)cactiuser\([';]*$\)/\1$cacti_pw_develop\2/g" > /usr/share/cacti/develop/include/config.php

cat /usr/share/cacti/feature/include/config.php.dist | sed "s/^\(\\\$database_default.*=[ ']*\)cacti\([';]*$\)/\1cacti_feature\2/g"| sed "s/^\(\\\$database_username.*=[ ']*\)cactiuser\([';]*$\)/\1cacti_feature\2/g" | sed "s/^\(\\\$database_password.*=[ ']*\)cactiuser\([';]*$\)/\1$cacti_pw_feature\2/g" > /usr/share/cacti/feature/include/config.php

mysql -u root -p < $cacti_sql
mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql;

Finalise Cacti Setup

Set cacti defaults

Make the default url path be the root and set the PHP timezone.

sed -i "s/^\(\\\$url_path.*=[ ']*\)\/cacti\/\([';]*$\)/\1\/\2/g" /usr/share/cacti/site/include/config.php
sed -i "s/^\(\\\$url_path.*=[ ']*\)\/cacti\/\([';]*$\)/\1\/\2/g" /usr/share/cacti/develop/include/config.php
sed -i "s/^\(\\\$url_path.*=[ ']*\)\/cacti\/\([';]*$\)/\1\/\2/g" /usr/share/cacti/feature/include/config.php
sed -i "s/^[; ]*date\.timezone[ ]*=.*$/date.timezone = Europe\/London/gm" /etc/php/7.2/apache2/php.ini
sed -i "s/^[; ]*date\.timezone[ ]*=.*$/date.timezone = Europe\/London/gm" /etc/php/7.2/cli/php.ini
systemctl restart apache2

Enable the Cacti Poller

echo "* * * * * _website_user_ /usr/bin/php --define suhosin.memory_limit=512M /usr/share/cacti/site/poller.php 2>&1 | if [ -f /usr/bin/ts ] ; then ts \"\\%Y-\\%m-\\%d \\%H:\\%M:\\%.S\" ; else cat ; fi >> /usr/share/cacti/site/log/poller.log" > /etc/cron.d/cacti-site
echo "* * * * * _website_user_ /usr/bin/php --define suhosin.memory_limit=512M /usr/share/cacti/develop/poller.php 2>&1 | if [ -f /usr/bin/ts ] ; then ts \"\\%Y-\\%m-\\%d \\%H:\\%M:\\%.S\" ; else cat ; fi >> /usr/share/cacti/develop/log/poller.log" > /etc/cron.d/cacti-develop
echo "* * * * * _website_user_ /usr/bin/php --define suhosin.memory_limit=512M /usr/share/cacti/feature/poller.php 2>&1 | if [ -f /usr/bin/ts ] ; then ts \"\\%Y-\\%m-\\%d \\%H:\\%M:\\%.S\" ; else cat ; fi >> /usr/share/cacti/feature/log/poller.log" > /etc/cron.d/cacti-feature

Some notes on the above are:

  • Ensure any percentage signs are escaped with a backslash as cron will by default assume a new line when seeing a percentage sign resulting in errors such as

    /bin/sh: 1: Syntax error: Unterminated quoted string
    
  • To utilise the timestamp mechanisms, you must install moreutils to have /usr/bin/ts

    apt install -y moreutils
    

Ubuntu 17.10

System setup

Configure the network

In order to configure the network, you may need to use the nmcli command or modify /etc/network/interfaces for the ens device found in dmesg.

hostname _ssh_host_
echo "_ssh_host_" > /etc/hostname
apt install -y screen git openssh-server
useradd _ssh_user_
passwd _ssh_user_
echo "_ssh_user_     ALL=(ALL)     ALL" > /etc/sudoers.d/_ssh_user_

Note: Do NOT use a filename with a fullstop in it as sudo will ignore these by default

Enable SSH login via keys

Create the authorized_keys file with the appropriate SSH keys

mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
cat > .screenrc << EOF
startup_message off
altscreen on
msgwait 0

shell -s $SHELL
term xterm-256color
defscrollback 5000
termcapinfo xterm* ti@:te@
pushd $HOME/
bind R eval "source $HOME/.screenrc" "echo '.screenrc' reload"
bind \033 screen -t "Root Shell" 1 bash -c 'echo Logging in as root; sudo su'
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%'
activity "%c activity -> %n%f %t^G"
screen -t "User Shell" 0 bash -c 'pushd ~/ > /dev/null; bash' 
EOF

If you have predefined keys you wish to insert, simply edit the ~/.ssh/authorized_keys file

Install Apache, SQL and PHP

Package selection may be overkill but to ensure they are definitely installed.

apt install -y php apache2 openssl mysql-server \
php-mysql php-xml php-ldap php-gmp php-mbstring \
php-cli php-common php-pdo php-gd php-snmp \
snmp rrdtool

Website basics

Create some required directories

mkdir -p /etc/ssl/cacti/ \
/var/log/cacti/ \
/usr/share/cacti/{site,feature,develop} 
chown _ssh_user_:_website_user_ -Rv /usr/share/cacti/

Clone Cacti

Run the following as _ssh_user_

sudo su - _ssh_user_
cd /usr/share/cacti
git clone https://github.com/netniv/cacti/ site
cd site/
git remote add upstream https://github.com/cacti/cacti/ && git fetch --all 
cd ../
cp -Rva site/. develop
cp -Rva site/. feature

cd /usr/share/cacti/develop && git branch develop --set-upstream-to upstream/develop && git checkout develop
cd /usr/share/cacti/feature && git branch develop --set-upstream-to upstream/develop && git checkout develop

Change default permissions

Run the following as root

chown -Rv www-data:www-data \
/usr/share/cacti/{site,feature,develop}/resource \
/usr/share/cacti/{site,feature,develop}/scripts \
/usr/share/cacti/{site,feature,develop}/log \
/usr/share/cacti/{site,feature,develop}/cache \
/usr/share/cacti/{site,feature,develop}/rra

chmod u+rw,g+r,g-w,a+r -Rv /usr/share/cacti
chmod u+rw,g+rw,a+r -Rv \
/usr/share/cacti/{site,feature,develop}/log \
/usr/share/cacti/{site,feature,develop}/rra \
/usr/share/cacti/{site,feature,develop}/resource/

Checkout specific versons

cd /usr/share/cacti/site/ && git checkout release/_cacti_version_ 
cd /usr/share/cacti/develop && git branch develop --set-upstream upstream/develop && git checkout develop
cd /usr/share/cacti/feature && git branch feature/1.2.x --set-upstream upstream/<branch> && git checkout <branch>

Create SSL Certificate

mkdir -p /etc/ssl/cacti/
cd /etc/ssl/cacti/

openssl req -new -sha256 -nodes -out _cacti_host_.csr -newkey rsa:2048 -keyout _cacti_host_.key -config <(
cat <<-EOF
[req]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[dn]
C = GB
ST = Alive
L = The World
O = netniV
OU = IT
emailAddress = netniv@hotmail.com
CN = _cacti_host_

[req_ext]
subjectAltName = @alt_names

[alt_names]
DNS.1 = develop._cacti_host_
DNS.2 = feature._cacti_host_
EOF
)
openssl x509 -req -days 1825 -in _cacti_host_.csr -signkey _cacti_host_.key -out _cacti_host_.crt

Create HTTPD configuation

echo 'NameVirtualHost *:443
NamevirtualHost *:80

<VirtualHost *:443>
        ErrorLog /var/log/cacti/site-error.log
        TransferLog /var/log/cacti/site-access.log
        CustomLog /var/log/cacti/site-request.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
        SSLCertificateFile /etc/ssl/cacti/_cacti_host_.crt
        SSLCertificateKeyFile /etc/ssl/cacti/_cacti_host_.key

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
                SSLOptions +StdEnvVars
        </Files>

        <Directory /usr/share/cacti/site/>
                AllowOverride All
        </Directory>

        DocumentRoot /usr/share/cacti/site/
        ServerName _cacti_host_
</VirtualHost>
<VirtualHost *:443>
        ErrorLog /var/log/cacti/develop-error.log
        TransferLog /var/log/cacti/develop-access.log
        CustomLog /var/log/cacti/develop-request.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
        SSLCertificateFile /etc/ssl/cacti/_cacti_host_.crt
        SSLCertificateKeyFile /etc/ssl/cacti/_cacti_host_.key

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
                SSLOptions +StdEnvVars
        </Files>

        <Directory /usr/share/cacti/develop>
                AllowOverride All
        </Directory>

        DocumentRoot /usr/share/cacti/develop
        ServerName _cacti_host_
</VirtualHost>
<VirtualHost *:443>
        ErrorLog /var/log/cacti/feature-error.log
        TransferLog /var/log/cacti/feature-access.log
        CustomLog /var/log/cacti/feature-request.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite DEFAULT:!EXP:!SSLv2:!DES:!IDEA:!SEED:+3DES
        SSLCertificateFile /etc/ssl/cacti/_cacti_host_.crt
        SSLCertificateKeyFile /etc/ssl/cacti/_cacti_host_.key

        <Files ~ "\.(cgi|shtml|phtml|php3?)$">
                SSLOptions +StdEnvVars
        </Files>

        <Directory /usr/share/cacti/feature>
                AllowOverride All
        </Directory>

        DocumentRoot /usr/share/cacti/feature
        ServerName _cacti_host_
</VirtualHost>
' > /etc/apache2/sites-available/cacti.conf
a2enmod ssl ldap 
phpenmod ldap snmp gmp
a2ensite cacti

Enable through firewall if required

This requires the iptables-persistent package since 16.04

iptables -I INPUT 1 -p tcp -m tcp --dport 80 -j ACCEPT
iptables -I INPUT 1 -p tcp -m tcp --dport 443 -j ACCEPT
netfilter-persistent save
netfilter-persistent reload

Configuration MySQL

Enable custom configurations

echo "[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
max_allowed_packet=18M
max_heap_table_size=98M
tmp_table_size=64M
join_buffer_size=64M
innodb_buffer_pool_size=488M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
default_time_zone='+00:00'
" > /etc/mysql/conf.d/cacti.cnf

service mysql restart

Create databases and users

cacti_sql=`mktemp -t XXXXXXXXXXXX -u`

echo "use mysql;
create database if not exists cacti_site; 
create database if not exists cacti_feature; 
create database if not exists cacti_develop;
use cacti_site;
source /usr/share/cacti/site/cacti.sql;
use cacti_feature;
source /usr/share/cacti/feature/cacti.sql;
use cacti_develop;
source /usr/share/cacti/develop/cacti.sql;
" > $cacti_sql;

cacti_pw_site=`mktemp -t XXXXXXXXXXXX -u | sed 's/\/tmp\///'`
cacti_pw_develop=`mktemp -t XXXXXXXXXXXX -u | sed 's/\/tmp\///'`
cacti_pw_feature=`mktemp -t XXXXXXXXXXXX -u | sed 's/\/tmp\///'`

echo "
GRANT ALL PRIVILEGES ON cacti_site.* TO 'cacti_site'@'localhost' IDENTIFIED BY '$cacti_pw_site';
GRANT ALL PRIVILEGES ON cacti_develop.* TO 'cacti_develop'@'localhost' IDENTIFIED BY '$cacti_pw_develop';
GRANT ALL PRIVILEGES ON cacti_feature.* TO 'cacti_feature'@'localhost' IDENTIFIED BY '$cacti_pw_feature';
GRANT SELECT ON mysql.time_zone_name TO 'cacti_site'@'localhost';
GRANT SELECT ON mysql.time_zone_name TO 'cacti_develop'@'localhost';
GRANT SELECT ON mysql.time_zone_name TO 'cacti_feature'@'localhost';
FLUSH PRIVILEGES
" >> $cacti_sql

cat /usr/share/cacti/site/include/config.php.dist | sed "s/^\(\\\$database_default.*=[ ']*\)cacti\([';]*$\)/\1cacti_site\2/g"| sed "s/^\(\\\$database_username.*=[ ']*\)cactiuser\([';]*$\)/\1cacti_site\2/g" | sed "s/^\(\\\$database_password.*=[ ']*\)cactiuser\([';]*$\)/\1$cacti_pw_site\2/g" > /usr/share/cacti/site/include/config.php

cat /usr/share/cacti/develop/include/config.php.dist | sed "s/^\(\\\$database_default.*=[ ']*\)cacti\([';]*$\)/\1cacti_develop\2/g"| sed "s/^\(\\\$database_username.*=[ ']*\)cactiuser\([';]*$\)/\1cacti_develop\2/g" | sed "s/^\(\\\$database_password.*=[ ']*\)cactiuser\([';]*$\)/\1$cacti_pw_develop\2/g" > /usr/share/cacti/develop/include/config.php

cat /usr/share/cacti/feature/include/config.php.dist | sed "s/^\(\\\$database_default.*=[ ']*\)cacti\([';]*$\)/\1cacti_feature\2/g"| sed "s/^\(\\\$database_username.*=[ ']*\)cactiuser\([';]*$\)/\1cacti_feature\2/g" | sed "s/^\(\\\$database_password.*=[ ']*\)cactiuser\([';]*$\)/\1$cacti_pw_feature\2/g" > /usr/share/cacti/feature/include/config.php

mysql -u root -p < $cacti_sql
mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql;

Finalise Cacti Setup

Set cacti defaults

Make the default url path be the root and set the PHP timezone.

sed -i "s/^\(\\\$url_path.*=[ ']*\)\/cacti\/\([';]*$\)/\1\/\2/g" /usr/share/cacti/site/include/config.php
sed -i "s/^\(\\\$url_path.*=[ ']*\)\/cacti\/\([';]*$\)/\1\/\2/g" /usr/share/cacti/develop/include/config.php
sed -i "s/^\(\\\$url_path.*=[ ']*\)\/cacti\/\([';]*$\)/\1\/\2/g" /usr/share/cacti/feature/include/config.php
sed -i "s/^[; ]*date\.timezone[ ]*=.*$/date.timezone = Europe\/London/gm" /etc/php/7.2/apache2/php.ini
sed -i "s/^[; ]*date\.timezone[ ]*=.*$/date.timezone = Europe\/London/gm" /etc/php/7.2/cli/php.ini
systemctl restart apache2

Enable the Cacti Poller

echo "* * * * * _website_user_ /usr/bin/php --define suhosin.memory_limit=512M /usr/share/cacti/site/poller.php 2>&1 | if [ -f /usr/bin/ts ] ; then ts \"\\%Y-\\%m-\\%d \\%H:\\%M:\\%.S\" ; else cat ; fi >> /usr/share/cacti/site/log/poller.log" > /etc/cron.d/cacti-site
echo "* * * * * _website_user_ /usr/bin/php --define suhosin.memory_limit=512M /usr/share/cacti/develop/poller.php 2>&1 | if [ -f /usr/bin/ts ] ; then ts \"\\%Y-\\%m-\\%d \\%H:\\%M:\\%.S\" ; else cat ; fi >> /usr/share/cacti/develop/log/poller.log" > /etc/cron.d/cacti-develop
echo "* * * * * _website_user_ /usr/bin/php --define suhosin.memory_limit=512M /usr/share/cacti/feature/poller.php 2>&1 | if [ -f /usr/bin/ts ] ; then ts \"\\%Y-\\%m-\\%d \\%H:\\%M:\\%.S\" ; else cat ; fi >> /usr/share/cacti/feature/log/poller.log" > /etc/cron.d/cacti-feature

Some notes on the above are:

  • Ensure any percentage signs are escaped with a backslash as cron will by default assume a new line when seeing a percentage sign resulting in errors such as

    /bin/sh: 1: Syntax error: Unterminated quoted string
    
  • To utilise the timestamp mechanisms, you must install moreutils to have /usr/bin/ts

    apt install -y moreutils
    
You can’t perform that action at this time.