Build Cacti monitoring and common fault solutions for CentOS

Source: Internet
Author: User
Tags cairo mcrypt php source code rrdtool snmpwalk snmpv3

Prepare the environment:
1. configure the firewall and enable port 80 and port 3306
Vi/etc/sysconfig/iptables
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT (allow port 80 to pass through the firewall)
-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT (allow port 3306 to pass the firewall)
Note: Many buddies add these two rules to the last line of the firewall configuration, resulting in firewall startup failure. The correct rule should be added to the default port 22.
The firewall rules are as follows:
* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [0: 0]
-A input-mstate -- state ESTABLISHED, RELATED-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-I lo-j ACCEPT
-A input-mstate -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT
-A input-mstate -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
-A input-mstate -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT
-A input-jREJECT -- reject-with icmp-host-prohibited
-A forward-jREJECT -- reject-with icmp-host-prohibited
COMMIT
/Etc/init. d/iptablesrestart # restart the firewall to make the configuration take effect.
Ii. Disable SELINUX
Vi/etc/selinux/config
# SELINUX = enforcing # comment out
SELINUX = disabled # Add
: Wq save, close
Shutdown-r now # restart the system
Iii. system conventions
Software source code package storage location:/usr/local/src
Source code package compilation and installation location:/usr/local/software name
4. download the software package
Http://wwwNaNake.org/files/v2.8/cmake-2.8.7.tar.gz
Ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
Http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
Http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
5. Install the compilation tool and library file (use the CentOS yum command for installation)
Yum install make autoconfautomake gcc-c ++ zlib-devel openssl-devel pcre-devel gdkernel kernel-headers compat * mpfr cpp glibc libgomp libstdc ++-devel pplcloog-ppl keyutils -libs-devel libcom_err-devel libsepol-devel libselinux-develkrb5-devel zlib-devel libXpm * freetype libjpeg * libpng * php-common php-gdncurses * libtool * libxml2 libxml2-devel patch
Installation Steps
Use putty to remotely log on to the server.
1) install libmcrypt
Cdlibmcrypt-2.5.7./configuremake & make install
Ldconfigcd libltdl/./configure -- enable-ltdl-install make & make install
2) install cmake./configure -- prefix =/usrmake & make install
3) install apryum-yremoveapr
./Configure -- prefix =/usr/local/webserver/aprmake & make install
4) install apr-util
./Configure -- prefix =/usr/local/webserver/apr-util -- with-apr =/usr/local/webserver/apr/bin/apr-1-config
1. Install mysql
# Nginxyum-yinstall pcre-develzlib-devel
Step 2: Add a MYSQL installation user
Groupaddmysql
Useradd-gmysqlmysql-s/bin/false
Step 3: Compile and install
Cd mysql-5.5.21
Cmake \
-DCMAKE_INSTALL_PREFIX =/usr/local/webserver/mysql \
-DMYSQL_DATADIR =/user/local/webserver/mysql/data \
-DSYSCONFDIR =/etc \
-DEXTRA_CHARSETS = all \
-DDEFAULT_CHARSET = utf8 \
-DDEFAULT_COLLATION = utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
-DWITH_ARCHIVE_STORAGE_ENGINE = 1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE = 1 \
-DWITH_FEDERATED_STORAGE_ENGINE = 1 \
-DWITH_PARTITION_STORAGE_ENGINE = 1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE = 1 \
-DMYSQL_UNIX_ADDR =/usr/local/webserver/mysql/tmp/mysqld. sock \
-DMYSQL_TCP_PORT = 3306 \
-DWITH_DEBUG = 0 \
-DENABLED_LOCAL_INFILE = 1
Make & make install
Step 4: Set mysql
# There are five configuration information files in the support-files directory (it is important to copy the corresponding cnf file based on your memory, otherwise mysql will never start ):
# My-small.cnf (memory <= 64 M) # my-medium.cnf (memory 128 M) # my-large.cnf (memory 512 M)
# My-huge.cnf (memory 1 GB-2 GB) # my-innodb-heavy-4G.cnf (memory 4 GB)
Cp./support-files/my-huge.cnf/etc/my. cnf
Vi/etc/my. cnf
# Add in [mysqld]
Datadir =/usr/local/webserver/mysql/data
Wait-timeout = 30
Max_connections = 512
# Modify in the [mysqld] Section
Max_allowed_packet = 16 M
Step 5: Set permissions
Chown-R root. mysql.
Chown-Rmysql. mysql data
Step 6: generate a new mysql authorization table
// Use the mysql_install_db script to generate a new mysql authorization table
Cd/usr/local/webserver/mysql/scripts
./Mysql_install_db -- user = mysql -- basedir =/usr/local/webserver/mysql -- datadir =/usr/local/webserver/mysql/data
Step 7: add the mysql server to the System Service
Cpsupport-files/mysql. server/etc/init. d/mysqld # Add Mysql to the system to start
Chmod 755/etc/init. d/mysqld # Add execution permission
Chkconfigmysqldon # Add to startup
Vi/etc/init. d/mysqld # Edit
Basedir =/usr/local/webserver/mysql # MySQL installation path
Datadir =/usr/local/webserver/mysql/data # MySQl database storage directory
Service mysqldstart # Start
Step 8: Add mysql service to system environment variables
Vi/etc/profile # Add the mysql service to the system environment variable: Add the following line at the end
ExportPATH = $ PATH:/usr/local/webserver/mysql/bin
# Make the environment variable effective immediately: source/etc/profile
The following two lines link the myslq library file to the default system location, so that you do not need to specify the mysql library file address when compiling software such as PHP.
// Set the soft connection so that mysql, mysqldump, and mysqladmin bin commands can be directly run in shell
Ln-s/usr/local/webserver/mysql/include/mysql/usr/bin
Ln-s/usr/local/webserver/mysql/bin/mysqldump/usr/bin
Ln-s/usr/local/webserver/mysql/bin/mysqladmin/usr/bin
Step 9: Set the password
Mysqladmin-uroot password "ellisqin"
2. Install apache2
. /Configure -- prefix =/usr/local/webserver/apache -- with-apr =/usr/local/webserver/apr -- with-apr-util =/usr/local/webserver/ apr-util -- enable-static-support -- enable-mod-shared = most -- enable-speling -- enable-forward -- enable-ssl -- with-ssl -- enable-cache-disk -- enable-cgid -- enable-module = so -- with-mysql =/usr/local/webserver/mysql -- sysconfdir =/usr/local/lamp/etc
#/Usr/local/webserver/apache/bin/apachectl-k start # start
# Vi/usr/local/webserver/apache/conf/httpd. conf # edit the configuration file
Find: # ServerNamewww.example.com: 80 and change it to ServerName www.pphc.com: 80.
Find: DirectoryIndex index.html and change it to: DirectoryIndex index.html index. php.
Locate: Options Indexes FollowSymLinks and change it to: Options FollowSymLinks # do not display the directory structure
Locate AllowOverride None and change it to: AllowOverride All # enable apache to support pseudo-static, there are two changes
LoadModulerewrite_modulemodules/mod_rewrite.so # cancel the preceding annotation and enable apache to support pseudo-static
Vi/etc/profile # Add apache service system environment variables
Add the following line at the end
ExportPATH = $ PATH:/usr/local/webserver/apache/bin
Cp/usr/local/webserver/apache/bin/apachectl/etc/init. d/httpd # Add apache to the system startup
Vi/etc/init. d/httpd # edit the file
In #! Add the following two lines under/bin/sh:
# Chkconfig: 234510 90
# Descrption: Activates/DeactivatesApache Web Server
Chowndaemon. daemon-R/usr/local/webserver/apache/htdocs # change the directory owner
Chmod700/usr/local/webserver/apache/htdocs-R # change apache website directory permissions
Chkconfighttpdon # Set startup
3. install php
Yum install libjpeg-devel net-snmp-utils gmpgmp-devel php-mysql * freetype * object * bzip2 * gd-devel libpng-develfreetype-deve l libxml2-devel curl-devel
Ln-s/usr/local/lib/libiconv. so.2/usr/lib64/
. /Configure -- prefix =/usr/local/webserver/php -- with-apxs2 =/usr/local/webserver/apache/bin/apxs -- with-mysql =/usr/local/webserver/ mysql -- with-gd -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- enable-sockets
# Makemakeinstall
Cpphp. ini-production/usr/local/webserver/php/etc/php. ini # copy the php configuration file to the installation directory
Ln-s/usr/local/webserver/php/bin/*/usr/local/bin # create a soft link to the configuration file
Vi/usr/local/webserver/php/etc/php. ini # Edit
Find:; open_basedir =
Modify it to: open_basedir =.:/tmp/# It is important to prevent php trojans from being cross-site !!
# List functions that can be disabled by PHP. If some programs need this function, they can be deleted and disabled.
Locate:; date. timezone =
Changed to: date. timezone = 'Asia/Shanghai' (* Important *). If this parameter is not modified, the PHP file cannot be opened.
Find: expose_php = On
Change to: expose_php = OFF # disable display of php version information
Find: display_errors = On
Changed to display_errors = OFF # Disable Error Message
8. Configure apache to support php
Vi/usr/local/webserver/apache/conf/httpd. conf # edit the apache configuration file
Add,
AddTypeapplication/x-httpd-php.php (Note: There is a space in front of the php. php point)
/Usr/local/webserver/apache/bin/apachectl-k restart # restart apache
Service mysqldrestart # restart mysql
So far, CentOS 6.2 compilation and installation of Apache2.4.2 + mysql5.25 + PHP5.3.13 has been configured.
4. rrdtool Installation
Yum install zib libpng freetype libjpeg fontconfiggd libxml2 cairo-devel libxml2-devel pango-devel
Yum install libxml2-devellibpng-devel pkgconfig glib pixman pango-devel freetype-develfontconfig cairo-devel libart_lgpl libart_lgpl-devel
#./Configure -- prefix =/usr/local/rrdtool
The following error may be reported:
Configure: error: Please fix the library issues listed above and try again.
Check whether perl and perl-devel are installed. If they are not installed in make, an error is returned.
Solution: yum-y installpango-develpango * perlperl-devel
# Make & make install
# Ln-s/usr/local/rrdtool/bin/*/usr/local/bin/
5. Install cacti
# Mvcacti-0.8.8a/usr/local/webserver/apache/htdocs/
# Mysql-uroot-pellisqin
Mysql> createdatabase cacti;
Query OK, 1 rowaffected (0.03 sec)
Mysql> grantall privileges on cacti. * to cactiuser @ localhost \
-> Identified by "ellisqin ";
Mysql> flushprivileges;
Query OK, 0 rowsaffected (0.02 sec) // reload MySQL authorization table
# Mysql-ucactiuser-pellisqin cacti <cacti. SQL // import the cacti Database
# Viinclude/config. php
$ Database_default = "cacti ";
$ Database_hostname = "127.0.0.1 ";
$ Database_username = "cactiuser ";
$ Database_password = "ellisqin ";
# Crontab-e: Add the following content to make cacti collect data every five minutes
*/5 * envLANG = C/usr/local/webserver/app/bin/php/usr/local/webserver/apache/htdocs/cacti/poller. php
# Service crondstart
Access http: // ip/cacti
Question 1: Warning: strtotime () [function. strtotime]:
Solution
1: Change php. ini
Date. timezone = 'Asia/Shanghai'
2: Write in program code
# Vi include/global. php
<? Php
Date_default_timezone_set ('Asia/Shanghai'); // Add this line
/*
Question 2The following PHP extensions are missing: * sockets
It turns out that socket support is not configured when php is installed.
Ah, there is no way to re-compile php and add socket support
1. Do not stop apache
2. Go to the apache Module Directory and back up the php module.
Cd/usr/local/apache2/modules/
Cp libphp5.solibphp5. so. bak
3. Go to the php source code directory. A successful config. nice file will be generated after compilation. open the file and reconfigure it to support socket.
Cd/usr/local/src/php-5.2.4
Viconfig. nice
Add a row
'-- Enable-sockets'
4. regenerate the configuration file
Shconfig. nice
5. recompile
Make & make install
6. Restart apache
/Usr/local/apache2/bin/apachectl restart
---------------- Load other modules --------------
6. Centos Linux machines are monitored in two versions.
Yum installnet-snmp net-snmp-devel net-snmp-utils
First version V3
In my test environment, net-snmp in CentOS cannot be used normally in selinux. If you want to use snmp v3, disable selinux first.
Net-snmp-config -- create-snmpv3-user-ro-A hnjingpw-a MD5 qin
The preceding command creates an snmpv3 user, which is read-only and uses MD5. the user name is qin and the password is hnjingpw.
Note: Disable the net-snmp service before running it.
We can use snmpwalk to check whether the snmp service is enabled normally.
Shell> snmpwalk-v 3-u qin-a MD5-A "hnjingpw"-l authNoPriv 127.0.0.1 sysDescr
# Shell> service snmpd start
V2.
Edit the snmp configuration file/etc/snmp. conf
Modify: com2secnotconfiguserdefapublic public
Changed to com2sec notConfigUser127.0.0.1 (which machine is allowed to capture data) public
Modify: accessnotConfigGroup "" anynoauthexactsystemview none
Changed to: accessnotConfigGroup "" anynoauthexactall none
Remove the comment # view allincluded. 180
7. Install Plugin Architecture (not required)
Agent http://cactiusers.org/
# Mysql-ucactiuser-pellisqin cacti <pa. SQL
# Cpcacti-plugin-0.8.7h-PA-v3.0.diff/usr/local/webserver/apache/htdocs/cacti/
# Patch-p1-N <cacti-plugin-0.8.7h-PA-v3.0.diff
# Viinclude/global. php
$ Database_password = "ellisqin ";
$ Url_path = "/cacti /";
$ Config ['url _ path'] = $ url_path;
8. net-snmp Installation
If you have installed net-snmpnet-snmp-devel net-snmp-utils, you do not need to install step 2.
# Yum-y installmysql-devel net-snmp-devel (* Important *) if not installed, net-snmp cannot be installed.
#./Configure -- prefix =/usr/local/net-snmp
# Make & make install
# CpEXAMPLE. conf/usr/local/net-snmp/share/snmp/snmpd. conf
# Ln-s/usr/local/net-snmp/bin/*/usr/local/bin/
9. cacti-spine Installation
Cacti uses cmd to collect data. php script. The minimum polling time of this script is 5 minutes. That is to say, we use cmd. php cannot set the cacti polling time to polling once per minute. Therefore, we need to install an additional efficient polling tool Spine.
#. /Configure -- prefix =/usr/local/cacti-spine -- with-mysql =/usr/local/webserver/mysql -- with-snmp =/usr/local/net-snmp (optional, if the net-snmp source code is installed, it must be added)
# Make & make install
# Cd/usr/local/cacti-spine/etc/
# Cpspine. conf. distspine. conf
# Vispine. conf // configure the mail to connect to the cacti Database
Error: configure: error: Cannot find MySQL headers. Use -- with-mysql = to specify
Solution: # yum-y installmysql-devel
Error: configure: error: Cannot find SNMP headers
Solution: # yum-y installnet-snmp-devel
# Vispine. conf
DB_Host127.0.0.1
DB_Databasecacti
DB_Usercactiuser
DB_Passellisqin
Cacti-spine reports log errors
Cat/var/spool/mail/root
/Usr/local/spine/bin/spine: error while loading shared libraries: libmysqlclient_r.so.18: cannot openshared object file: No such file or directory
Make a soft link to solve the problem
Ln-s/usr/local/webserver/mysql/lib/libmysqlclient. so.18/usr/lib64

Cacti details: click here
Cacti: click here

In RHEL6.4, the Cacti + Spine monitoring host is used to send mail alarms.

Use Cacti + Spine to monitor remote hosts in RHEL6.4

CentOS 5.5 complete installation of Cacti + Spine

Cacti construction document under CentOS 6

Detailed description of Cacti monitoring deployment under RHEL5.9

How to install Cacti in CentOS 6.3

Quick installation and configuration of Cacti in CentOS Linux

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.