Linux_mysql_cacti installation Configuration

Source: Internet
Author: User
Tags snmp
Cacti is an open-source network monitoring tool that monitors the status and load of hosts,
After adding a template, You can monitor the running status of the Apache server and MySQL server,
I installed this mainly to monitor the running status of the MySQL server.
 
Cacti Website: http://www.cacti.net/
 
Host environment: centos 5.5 updated on: 20100717
 
MySQL: mysql-5.0.77-4.el5_5.3
PHP: php-5.1.6-27.el5
Apache: httpd-2.2.3-43.el5.centos
Some components, such as SNMP, PHP-XML, and PHP-LDAP, are required during cacti installation (optional ),
You don't have to worry about this because the lamp environment is installed as many times as possible,
Even if not, use the yum command. I think centos is quite good,
Although the software is sometimes old, it can still be used. Manually associate SNMPProgramInstall,
Otherwise, some snmpwalk and snmpget will not be found during the first configuration.
[Root @ tigertall bin] # rpm-Qa | grep SNMP
Php-snmp-5.1.6-27.el5
Net-snmp-utils-5.3.2.2-9.el5_5.1
Net-snmp-5.3.2.2-9.el5_5.1
Net-snmp-devel-5.3.2.2-9.el5_5.1
Net-snmp-libs-5.3.2.2-9.el5_5.1
[Root @ tigertall bin] #
If the preceding components are missing, use Yum to install them.
 
Install cacti using yum
[Gaohu @ tigertall ~] $ Sudo Yum install cacti
 
This command automatically installs related components.
1. php Configuration Requirements
 
[Gaohu @ tigertall ~] $ PHP-m
 
This command can check which modules are installed in PHP.
 
MySQL. So and centos Yum are already configured in PHP extension support.
 
The conf file of httpd is configured in/Etc/httpd/CONF/httpd. conf
 
The default add-on (PHP, MySQL) configuration directory/etc/httpd/CONF. D.
[Root @ tigertall Conf. d] # ls
Bugzilla. conf manual. conf PHP. conf
Proxy_ajp.conf readme SSL. conf
Welcome. conf cacti. conf Perl. conf
PhpMyAdmin. conf python. conf
Squid. conf Webalizer. conf
[Root @ tigertall Conf. d] #
 
We can see that many web-related configurations are here.
 
The basic configuration of PHP is in/etc/PHP. ini.
[Root @ tigertall Conf. d] # cd/etc/PHP. d
[Root @ tigertall PHP. d] # ls
DBASE. ini GD. ini mcrypt. ini mysql. ini
Pdo_mysql.ini pgsql. ini xmlwriter. ini
Dom. ini LDAP. ini mhash. ini
Ncurses. ini pdo_pgsql.ini SNMP. ini XSL. ini
Eaccelerator. ini mbstring. ini mysqli. ini
PDO. ini pdo_sqlite.ini xmlreader. ini
[Root @ tigertall PHP. d] #
 
Some PHP extension components are configured in the PHP. d directory.
View mysql. ini and enable extension = mysql. So
 
View SNMP. In and enable extension = SNMP. So
 
If you want to enable the import template function, you also need to enable file upload and enable it in/etc/PHP. ini.
 
File_uloads = on;
 
Note the following:
 
Session. save_path =/tmp;
 

 
2. Apache configuration requirements
 In Apache configuration/etc/httpd/CONF. d/PHP. conf,
Check whether the statement is enabled. Generally,
It should have been enabled by default.
 
# PHP is an HTML-embedded scripting language which
# Attempts to make it
# Easy for developers to write dynamically
# Generated webpages.
Loadmodule php5_module modules/libphp5.so
#
# Cause the PHP interpreter to handle files
# With a. php extension.
Php5-script. php addhandler
Addtype text/html. php
#
# Add index. php to the list of files that
# Will be served as Directory
# Indexes.
Directoryindex index. php

3. MySQL Configuration Requirements
Remember to set a secret for root to protect your security.
 
You can use the following command to change the root password:
Mysqladmin -- user = root password somepassword
Mysqladmin -- user = root -- password reload

4.CactiInstall configurations
 1. Use the following command to install cacti. This will automatically install the required components.
[Root @ tigertall PHP. d] # Yum install cacti

2. Create a MySQL database
[Root @ tigertall PHP. d] # Mysqladmin-uroot-phandomse create cacti

3. Import Enter the default cacti Database
If you use yum for default installation, create a database script
By default /Usr/share/doc/cacti-0.8.7f/cacti. SQL
[Root @ tigertall PHP. d] # cd/usr/share/doc/cacti-0.8.7f/
Execute the database creation command
[Root @ tigertall 0.8.7.f] # Mysql-uroot-phandomse cacti <Cacti. SQL

4. Create a user and password for the cacti database,
Log on to the database
[Root @ tigertall 0.8.7.f] # Mysql-u root-P 'pass'
For user authorization, replace the username, database, and password with the settings you need.
Mysql> grant all on cacti. * To cactiuser @ localhost
--> Identified by 'Password';
Refresh permission
Mysql> flush privileges;

5. Edit the cacti configuration and set the data connection.
[Root @ tigertall include] # vi/usr/share/cacti/include/config. php
Here is the database type, user name, and password used for cacti connection.

/* 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 = "cactiuser ";
$ Database_port = "3306 ";

/* Default session name-session name must */

/* Contain Alpha characters */
# $ Cacti_session_name = "cacti ";


Set the above configurations as needed

6. directory permission settings
[Root @ tigertall include] # cd/usr/share/cacti/
[Root @ tigertall cacti] # ll RRA
Lrwxrwxrwx 1 Root 18 Jul 17 :07 RRA->/var/lib/cacti/RRA
[Root @ tigertall cacti] # ll log
Lrwxrwxrwx 1 Root 15 Jul 17 :07 log->/var/log/cacti/
From the above, we can see that RRA is actually a soft link of VaR/lib/cacti/RRA,
Log is a soft link of/var/log/cacti.
Change the permission of the preceding directory and change the owner as needed. The user is used to generate the following data.
[Root @ tigertall cacti] # chown-r gaohu RRA/log/

7. Configure the automatic job time
Edit crontab.
[Root @ tigertall log] # crontab-e
Add the following content,
*/5 * PHP/usr/share/cacti/poller. php>/dev/null 2> & 1

Note:
This place cannot follow the official documentation, and the user name for execution cannot be added,
Crontab does not execute the USER parameter at all. The official document is as follows:
*/5 * gaohu PHP/usr/share/cacti/poller. php>/dev/null 2> & 1
According to this setting, an error is reported:
07/17/2010 10:59:57 pm-poller: poller [0] Warning:
Cron is out of sync with the poller interval!
The poller interval is '000000' seconds,
With a maximum of a '000000' second Cron,
But 419 seconds have
Passed since the last poll!
An alarm is reported that the setting is 300 seconds, and the result is more than 400 seconds.

The above content means that every five minutes, execute the PHP script to collect statistics.
 

For a question, see the final section.

8. log on to the server
Log on to http: // your-webserver/cacti
At initial logon, the username and password are admin. After logon, you must change the password immediately.

4. Spine installation configuration (optional)


Spine is a C-language-based, fast polling engine. It is an optional alternative to the default cmd. php.
If you decide to use it,
You need to install and configure it explicitly. Cacti does not include this engine.
The simplest way to install spine is to use RPM or ports.
If you use yum for installation, you need to add the rpmforge software repository.
If you use the source code, you can download the source code package from the cacti main site. Download address:
Http://www.cacti.net/downloads/spine/cacti-spine-0.8.7g.tar.gz
1. SlaveDownload the spine source code package from the cacti website

2. decompress the package to the local directory and compile and install the package.
To install spine, you must support net-snmp-devel, MySQL, MySQL-devel, and OpenSSL-devel,
Check whether it has been installed.
Run the following command to compile and install the SDK:
Tar xvzf cacti-spine-0.8.7g.tar.gz
CD cacti-spine-0.8.7g
./Configure
Make
Make install
Installed in the/usr/local/Spine/directory by default.

3. Copy a spine configuration file.
[Root @ tigertall etc] # cd/usr/local/Spine/etc/
[Root @ tigertall etc] # cp spine. conf. Dist spine. conf
Edit the spine. conf file and set the connection information of cacti data.
Db_host localhost # host address
Db_database cacti # Database
Db_user gaohu # Database User
Db_pass pass # database connection password
Db_port 3306 # database connection Port
Db_preg 1 # If you want to work with cacti 0.8.7 before 0.8.7g,
# Configure to 1.
# Because cacti 0.8.7e is set to 1 during host installation.
# If both are installed from the source code of the G version, you can set it to 0.
4. Set spine
A) log on to cacti as an admin user.
B) Select Settings from the directory menu and select the paths tab.
C) enter the full path of the spine executable program in "Spine poller file path,
For me, it is/usr/local/Spine/spine. Save the settings.
D) Select the poller tab.
E) In the poller type drop-down box settings, select "spine ".

After completing these settings, cacti executes the spine every five minutes to replace the original cmd. php.
If you have any problems when using spine, you can switch "poller type" back to "cmd. php" at any time ".


4. Application patches (optional)

After the installation is complete, you can apply the appropriate patches if necessary. However, do not apply the old version patches to the new version.


This is the general installation process.


5. cacti settings

Next article, please write it.

6. Strange problem ^_^.
 1. No image after installation and configuration
For the first time, you need to manually execute PHP/usr/share/cacti/poller. php,
After a few minutes, the image can be displayed.

2. Strange Permissions
In the configuration in section 3rd, we use gaohu as the cacti user.
However, when you use Yum to install cacti, the system automatically creates a cacti user.
According to cacti requirements, the first time an instance uses gaohu,
When PHP/usr/share/cacti/poller. php is executed,
You must use the user with write authorization for the preceding log directory.
However, when executing this command, it is likely to report
[Gaohu @ tigertall ~] $ PHP/usr/share/cacti/poller. php
PHP warning: Include (/usr/share/cacti/include/config. php ):
Failed to open stream: Permission denied in
/Usr/share/cacti/include/global. php on line 45
PHP warning: Include (): Failed
Opening '/usr/share/cacti/include/config. php'
Sion (include_path = '.:/usr/share/pear:/usr/share/php ')
In/usr/share/cacti/include/global. php on line 45
Fatal: cannot connect to MySQL server on 'localhost '.
Please make sure you have specified
A valid MySQL database name in 'include/config. php'
Only the last sentence is displayed at the beginning. I always thought that there was a problem with MySQL. As a result, I checked the port and there was no problem.
[Gaohu @ tigertall cacti] $ sudo netstat-APN | grep 3306
TCP 0 0 0.0.0.0: 3306 0.0.0.0: * Listen 3504/mysqld

I thought it was a database problem. It may be due to insufficient permissions on the cacti database,
Therefore, the gaohu user is granted full remote permissions.
Then I felt strange when I saw the above error.
PHP warning: Include (/usr/share/cacti/include/config. php ):
Failed to open stream: Permission denied in
/Usr/share/cacti/include/global. php on line 45

When poller. php is called,/usr/share/cacti/include/global. php is called,
Then I tracked the path and found something strange.
[Gaohu @ tigertall cacti] $ ll include/global. php
-RW-r -- 1 Root 7410 May 20 include/global. php
[Gaohu @ tigertall cacti] $ ll/usr/share/cacti/include/config. php
Lrwxrwxrwx 1 Root 17 Jul 17 :07
/Usr/share/cacti/include/config. php->/etc/cacti/DB. php
[Gaohu @ tigertall cacti] $ ll/etc/cacti/DB. php
-RW-r ----- 1 cacti Apache 1915 Jul 17/etc/cacti/DB. php
This dB. php file can only be read and written by cacti users and Apache users, and can only be written by cacti users,
Gaohu users are only common users who can Su and do not belong to the Apache Group. Therefore, they naturally do not have permissions. An error is reported.
Two solutions: 1. Add gaohu to the Apache Group,
2. Change the attributes of the/etc/catic/DB. php file.
I use the first one. Maybe the second one will be better.
In fact, there are still 3rd ways,
It is to switch the previous files to the cacti users for those who switch the owner and edit the scheduled jobs,
However, the default installed cacti does not have a logon terminal,
So there is no way to switch to Su-cacti, which is not good for general users. Select as needed.

Then you can work.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.