Install Cacti on CentOS7
Cacti is an excellent open-source monitoring software that is implemented in php. It uses the snmp service to obtain data and then uses rrdtool to store and update data. When users view data, rrdtool generates charts and presents them to users. After CentOS7, the default database is MariaDB, which is a branch of MySQL and stores variables and calls them. The MariaDB database does not store the data captured by snmp. The data captured by snmp is stored in the rrd file generated by rrdtool. These files are located in the rra directory under the cacti directory.
I. Installation of related software
Most of them can be installed using yum:
Yum install httpd * ---- install Apache related services on the Web Server
Yum install php * ---- install PHP services
Yum install mariadb * ---- install MariaDB database services
Yum install net-snmp * ---- install SNMP-related services
Yum install rrdtoolrrdtool-devel rrdtool-php rrdtool-perl ---- install rrdtool to generate images
Yum install gdgd-develphp-gd --- the image library required by rrdtool to draw images
Ii. Configure SNMP
Vi/etc/snmp/snmpd. conf
① Change the default value under 41 rows (different, please search for them) to 127.0.0.1.
② Change the systemview under 62 rows (different, please search for them) to all
③ Comment out the # comment under the 85 rows (different, please search)
④ Start snmp
Systemctl start snmpd. service
Iii. MariaDB Database Configuration
① Enable MariaDB Database
Systemctl start mariadb. service
② Set the password for the root user (take wang as an example) and change the logon permission. The default password is null.
# Mysql-u root-p press enter and enter the password (blank)
MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set password = password ('wang') where user = 'root ';
MariaDB [mysql]> grant all privileges on *. * to root @ localhost identified by 'wang' with grant option;
MariaDB [mysql]> flush privileges;
③ Add a cacti user and a cacti database, and set permissions for the user
MariaDB [mysql]> create database cacti default character set utf8; # set the database character set utf8; otherwise, garbled characters
MariaDB [mysql]> grant all privileges on cacti. * to cacti @ localhost identified by 'cacti' with grant option;
MariaDB [mysql]> flush privileges;
Iv. Cacti Configuration
① Download cacti
Wgethttp: // www.cacti.net/downloads/cacti-0.8.8f.tar.gz # download cacti
Tar-zxvf cacti-0.8.8f.tar.gz # extract cacti
Music cacti-0.8.8f/var/www/html/cacti # Move to/var/www/html/cacti
② Import cacti table content to the created database
Cd/var/www/html/cacti
Mysql-ucacti-pcacticacti </var/www/html/cacti. SQL
③ Edit two. php files respectively.
Vi/var/www/html/cacti/include/config. php
Vi/var/www/html/cacti/include/global. php
The modified content is the same. The content is as follows:
④ Modifying file attributes:
Useradd-r-Mcacti
Chown-Rcacti/var/www/html/cacti/rra/
Chown-Rcacti/var/www/html/cacti/log/
⑤ Create a scheduling task:
# Crontab-e [enter the following content]
*/5 * php/var/www/html/cacti/poller. php>/dev/null2> & 1
⑥ Enable http service
Systemctl start httpd. service
7. Enter http: // localhost/cacti or 127.0.0.1/cacti in the browser to access the cacti Management page.
If:
Forbidden
You don't have permission to access/cacti on this server.
This is because SeLinux is enabled, causing permission problems.
1). View The SELinux status:
#/Usr/sbin/sestatus-v # If The SELinux status parameter is enabled, it is enabled.
SELinux status: enabled
# Getenforce # This command can also be checked
2). Disable SELinux:
A. temporarily shut down (no need to restart the machine ):
# Setenforce 0 # Set SELinux to permissive mode (disable SELinux)
# Setenforce 1 # Set SELinux to enforcing mode (enable SELinux)
B. To modify the configuration file, restart the machine:
# Vi/etc/selinux/config
Change SELINUX = enforcing to SELINUX = disabled
Restart the machine.
Enter http: // localhost/cacti again to go to the Web page and continue the installation.
5. Install Spine
By default, cmd. php polls data, and the speed is slow. Especially when many monitoring nodes exist, cmd. php is even less efficient. Therefore, we use Spine to poll data. Cacti-spine is a C language engine used to replace cmd. php's fast retrieval speed.
① Download and compile and install
# Wgethttp: // www.cacti.net/downloads/spine/cacti-spine-0.8.8f.tar.gz
# Tar-zxvf cacti-spine-0.8.8f.tar.gz
# Cd cacti-spine-0.8.8f
#./Configure
# Make
# Make install
② Modify the username and password information for accessing the database
# Cp/usr/local/spine/etc/spine. conf. dist/usr/local/spine/etc/spine. conf
# Vi/usr/local/spine/etc/spine. conf
Note: The default spine configuration file must be placed in/etc to take effect. Otherwise, the following error will be reported during the test:
SPINE: Poller [0] FATAL: Unable to read configuration file! (Spine init)
③ Test whether it is normal
#/Usr/local/spine/bin/spine
SPINE: Using spine config file [../etc/spine. conf]
SPINE: Version 0.8.8f starting
SPINE: Time: 2.0130 s, Threads: 1, Hosts: 2
④ Go to the Cacti page and set the spine path
Console-> Configuration-> Settings-> Paths-> Alternate Poller Path-> Spine Poller File Path
/Usr/local/spine/bin/spine
⑤ Modify the Poller Type used by Cacti
Console-> Cacti Settings-> Poller Type
Select spine from the drop-down list.
Several problems that cannot be shown:
① After Cacti is installed, no diagram is displayed, because rrdtool is not fully installed.
② If you cannot plot the data, it may be a clock problem, as shown below:
# Cat/var/www/html/cacti/log/cacti. log
1). # timedatectl # CentOS7 unified time management command
# Timedatectl set-local-rtc yes # yes indicates local time, and no indicates UTC time
# Rm-rf/var/www/html/rra/* # delete all files under/var/www/html/rra/
#/Usr/bin/php/var/www/html/cacti/poller. php -- force # force the poller program to regenerate the file
2) The cron time is incorrect with the time set of poller. php.
Generally, the update time of poller. php is 60 s, so the cron should be set to be updated every minute.
# Crontab-e [enter the following content]
*/1 ***** php/var/www/html/cacti/poller. php>/dev/null2> & 1
3). # cat/var/www/html/cacti/log/cacti. log
OK. Data collection is normal.
4.) Go to Cacti to view the information. It is OK.