2017年2月5日 星期日

Install cacti 1.x, spine in CentOS 7 with mariadb (right, not mysql)

UPDATE:
Since new release is out, I added the procedures for upgrading cacti 1.0.1 to 1.0.x; and from 1.0.x to 1.1.x

NOTE:
Wouldn't it be better to use Ubuntu as cacti is packaged up and is so easy to install.  Actually yes and no. I have tried that on Ubuntu 16, and yes, it is just a few "apt-get install" and we are good to go.  But there are other problems as of Feb 2017, cacti 0.8.8h (from apt-get) is not very ready for php 7 and MySQL 5.7, especially on the plugins contributed from the community all along the years.  For instance, "split" function is gone in php 7 and it is quite common in the Cacti code base.  Another useful plugin "thold" for sending out alarms has even more serious problems with MySQL 5.7 as the SQL checking have become much more "strict" (I have tried turning off strict mode but still no luck).  But to be fair, it is not MySQL's fault really, "thold" is written in a rather "relax" way, and older MySQL would just let it pass with no problem.
So instead going through all the troubles, why not install the latest 1.x, though there is no yum or apt-get... But it is really nice that the new Cacti 1.0 has absorbed many useful plugins into the core code base, such as boost, autom8, ugroup etc.  I am not sure why thold is left out as it provides the basic alarming functionality that is what Cacti lacks.
After all, I think it would be still interesting to see if Cacti 1.0 can run smoothly in Ubuntu 16 as php 7 is supposed to have a much higher performance than php 5

Cacti official setup documentation: http://docs.cacti.net/manual:100:1_installation#requirements

Pre-req:
yum install net-snmp
yum install netsnmp-devel
yum install net-snmp-utils
yum install mariadb
yum install mariadb-devel
yum install gcc
yum install help2man
yum install rrdtools
yum install php
yum install php-snmp
yum install php-process
yum install php-mysql
yum install php-pdo
yum install php-ldap
yum install php-mbstring
yum install php-xml
yum install git

NOTE: make sure your system timezone and php.ini timezone is setup correctly (I have carelessly set a wrong system timezone and took me a lot of time to find out my data in rrd file is set in the wrong timeslot...)
In my case, type the following command "timedatectl set-timezone Asia/Hong_Kong"
vi /etc/php.ini
  => date.timezone = Asia/Hong_Kong

Download the sources
Visit Cacti official home and check on latest versions and patches: http://www.cacti.net/

wget http://www.cacti.net/downloads/cacti-1.0.1.tar.gz
tar xvzf cacti-1.0.1.tar.gz
mv cacti-1.0.1 /var/www/html/cacti
## make sure apache have full access to the folder
chown -R apache:apache /var/www/html/cacti


## Configure database and install cacti
# set root password
mysqladmin password

cd /var/www/html/cacti
vi include/config.php  ## change username/password as you like, which you would be using for database privileges setup
mysql -p
  > CREATE DATABASE cacti
  > grant all privileges on cacti.* to cactiuser@'localhost' identified by 'cactiuser';
  > grant select on mysql.time_zone_name to cactiuser@'localhost' identified by 'cactiuser';


## tuning Maria DB configurations (the syntax is just like mysql, so it is quite easy)
/etc/my.cnf.d/client.cnf
[client]
default-character-set=utf8



## this is just an example, you may need much larger values if you have a large site
## heap table size is specifically for performance enhancement, please refer to the following URL for details
http://logch.blogspot.hk/2017/02/tuning-cacti-10-performance-for-medium.html
/etc/my.cnf.d/server.cnf  [mysqld]
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
max_heap_table_size = 256M
max_allowed_packet = 16777216
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_per_table = on
innodb_doublewrite = off
innodb_additional_mem_pool_size = 80M
innodb_flush_log_at_trx_commit = 2


## create tables
mysql -p cacti < cacti.sql
## populate mysql time_zone_name table
mysql_tzinfo_to_sql  /usr/share/zoneinfo | mysql -p mysql

## now open a browser and open "http://your_server_ip/cacti/" and just follow the instructions.  If it says you are missing some modules, just yum install them.
https://www.youtube.com/watch?v=rqK5OnbF1BY

## Compile spine
wget http://www.cacti.net/downloads/spine/cacti-spine-1.0.1.tar.gz
tar xvzf cacti-spine-1.0.1.tar.gz
cd cacti-spine-1.0.1
./configure
make
make install

## Use spine
cd /usr/local/spine/etc/
(1) copy the "spine.conf.dist" to "spine.conf", and modify the DB related parameters inside, e.g. db name, user/pass (2) Then in Cacti UI -> Settings -> Paths, input the spine directories, e.g. Binary: /usr/local/spine/bin/spine Config: /usr/local/spine/etc/spine.conf (3) Settings -> Poller, choose spine instead of cmd.php


## Download thold plugin
# chdir to cacti plugins folder
cd /var/www/html/cacti/plugins
# download the source
git clone -b master https://github.com/Cacti/plugin_thold.git
# rename it to thold, yes it matters...
mv plugin_thold thold

Install Thold from the UI and a simple example can be found in video below (start at around 9:15)
https://www.youtube.com/watch?v=rqK5OnbF1BY


Upgrade from Cacti 1.0.1 to Cacti 1.0.x
# cd /var/www/html
# wget http://www.cacti.net/downloads/cacti-1.0.3.tar.gz
# tar xvzf cacti-1.0.3.tar.gz
# mv cacti cacti-1.0.1-old
# mv cacti-1.0.3 cacti
Update cacti/include/config.php on the database username and password
Open a web browser and open cacti url, e.g. http://x.x.x.x/cacti/, follow the steps and choose upgrade.

# cp -p cacti-1.0.1-old/rra/* cacti/rra/
Also copy whatever you have added by yourself from cacti-1.0.1-old/scripts/* and cacti-1.0.1-old/resource/* to cacti/scripts and cacti/resource.  That's it.

Upgrade from Cacti 1.0.x to Cacti 1.1.x
It should be pretty much the same
# cd /var/www/html
# wget http://www.cacti.net/downloads/cacti-1.0.3.tar.gz
# tar xvzf cacti-1.1.2.tar.gz
# mv cacti cacti-1.0.3-old
# mv cacti-1.1.2 cacti
Update cacti/include/config.php on the database username and password
Open a web browser and open cacti url, e.g. http://x.x.x.x/cacti/, follow the steps and choose upgrade.

Sample screen you would see in browser

2 則留言:

  1. Thanks For sharing this helpful and informative blog. I love the way that you describe the things. You are an incredible writer, Thank you so much for sharing the blog. Please keep sharing.
    Mobile Application Development
    Android App Development
    IOS App Development

    回覆刪除
  2. I really appreciate your post. The post has very good information that are helpful and contains unique information.Please keep sharing.
    V2Soft is a leading provider of IT services and Business consulting with offices in six countries around the world and headquarters in Michigan, USA.
    Here are some of the services:
    Application Development & Maintenance Services
    Testing Services
    Mobile Application Development

    回覆刪除