使用Cacti监控你的网络 - Cacti的安装
一、Cacti的安装
1.安装环境:Red Hat Enterprise Linux Server release 5.4 (Tikanga)
2.安装Apache、MySQL、PHP
(1).安装MySQL
//查看系统中是否已经安装了MySQL,如果是卸载所有以mysql开头的包。
# rpm -qa | grep mysql
# rpm -e mysql-*
# rm -f /etc/my.cnf
groupadd mysql
useradd mysql -c "start mysqld's account" -d /dev/null -g mysql -s /sbin/nologin
cd /usr/local/src/
tar -xzvf mysql-5.1.36.tar.gz
cd mysql-5.1.36
./configure \
--prefix=/usr/local/mysql \
--with-mysqld-user=mysql \
--without-debug \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--disable-shared \
--localstatedir=/var/lib/mysql \
--without-isam \
--without-innodb \
--enable-assembler
make && make install
cp support-files/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root:mysql /usr/local/mysql/
chown -R mysql:mysql /var/lib/mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
配置系统启动时自动启动MySQl
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
cd /etc/init.d
chmod 755 mysql
chkconfig --add mysql
chkconfig --level 3 mysql on
cp /usr/local/mysql/bin/mysql /usr/bin
mysql
use mysql;
UPDATE user SET Password=PASSWORD('ddl') WHERE user='root';
FLUSH PRIVILEGES;
(2).安装apache
cd /usr/local/src
tar -zxvf httpd-2.2.4.tar.gz
cd httpd-2.2.4
./configure --prefix=/usr/local/apache2 --enable-module=so --enable-rewrite
make && make install
设置自启动
cp support/apachectl /etc/init.d/httpd
修改/etc/init.d/httpd
vi /etc/init.d/httpd(在第两行之后添加如下内容)
#!/bin/sh
#
# Startup script for the Apache Web Server
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/log/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
chkconfig --add httpd
chmod 755 /etc/init.d/httpd
chkconfig httpd on
启动
/usr/local/apache2/bin/apachectl start
在RHEL5.4上报下面的错是因为开着selinux.关闭即可
[root@localhost bin]# ./apachectl start
httpd: Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf: Cannot load
/usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot
restore segment prot after reloc: Permission denied
(3).安装PHP
先安装zlib,freetype,libpng,jpeg以便于让PHP支持GD库(Cacti的WeatherMap插件必须要较新GD库的支持)
库文件下载地址:
1).安装zlib
cd /usr/local/src
tar -xzvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr/local/zlib
make && make install
(2).安装libpng
cd /usr/local/src
tar zxvf libpng-1.2.18.tar.gz
cd libpng-1.2.18/scripts/
mv makefile.linux ../makefile
cd ..
make && make install
注意,这里的makefile不是用./configure生成,而是直接从scripts/里拷一个
3).安装freetype
cd /usr/local/src
tar -xzvf freetype-2.3.4.tar.gz
cd freetype-2.3.4
./configure --prefix=/usr/local/freetype
make && make install
4).安装Jpeg
cd /usr/local/src
tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
mkdir /usr/local/libjpeg
mkdir /usr/local/libjpeg/include
mkdir /usr/local/libjpeg/bin
mkdir /usr/local/libjpeg/lib
mkdir /usr/local/libjpeg/man
mkdir /usr/local/libjpeg/man/man1
./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
make && make install
注意,这里configure一定要带--enable-shared参数,不然,不会生成共享库
5).安装Fontconfig
cd /usr/local/src
tar -zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
./configure --with-freetype-config=/usr/local/freetype-config
make && make install
6).安装GD
cd /usr/local/src
tar -zxvf gd-2.0.34.tar.gz
cd gd-2.0.34
./configure --prefix=/usr/local/libgd --with-png --with-freetype=/usr/local/freetype --with-
jpeg=/usr/local/libjpeg
make && make install
编译时显示以下信息:
** Configuration summary for gd 2.0.34:
Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: yes
Support for Xpm library: no
Support for pthreads: yes
7).编辑/etc/ld.so.conf,添加以下几行到此文件中
/usr/local/zlib/lib
/usr/local/freetype/lib
/usr/local/libjpeg/lib
/usr/local/libgd/lib
并执行ldconfig命令,使用动态装入器装载找到共享库
8).安装libxml
cd /usr/local/src/
tar -xzvf libxml2-2.6.25.tar.gz
cd libxml2-2.6.25
./configure
make && make install
9).安装PHP
cd /usr/local/src/
tar -zxvf php-5.2.3.tar.gz
cd php-5.2.3
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-gd=/usr/local/libgd \
--enable-gd-native-ttf \
--with-ttf \
--enable-gd-jis-conv \
--with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir=/usr/local/libjpeg \
--with-png-dir=/usr \
--with-zlib-dir=/usr/local/zlib \
--enable-xml \
--enable-mbstring \
--enable-sockets
make && make install
cp php.ini-dist /usr/local/php/lib/php.ini
修改apache配置文件httpd.conf
vi /usr/local/apache2/conf/httpd.conf
添加以下内容
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
AddType application/x-tar .tgz
AddType image/x-icon .ico
修改DirectoryIndex 行,添加index.php
修改为DirectoryIndex index.php index.html index.html.var
cd /usr/local/apache2/htdocs/
touch info.php
vi info.php
建立测试页面:info.php,添加以下内容:
phpinfo();
?>
重启动apache
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start
在浏览器中输入:进行测试。
对php编译选项的解释:
--prefix=/usr/local/php //指定PHP的安装目录
--with-apxs2=/usr/local/apache2/bin/apxs //支持Apache模块
--with-mysql=/usr/local/mysql //支持MySQl
--with-gd=/usr/local/libgd //支持GD库
--enable-gd-native-ttf //激活对本地 TrueType 字符串函数的支持
--with-ttf //激活对 FreeType 1.x 的支持
--with-freetype-dir=/usr/local/freetype //激活对 FreeType 2.x 的支持
--with-jpeg-dir=/usr/local/libjpeg //激活对 jpeg-6b 的支持
--with-png-dir=/usr //激活对 png 的支持
--with-zlib-dir=/usr/local/zlib //激活对zlib 的支持
--enable-mbstring //激活mbstring模块
--enable-gd-jis-conv //使JIS-mapped可用,支持日文字体
--with-mail //支持Mail函数
--enable-xml //支持XML
--enable-sockets //支持套接字
10).安装RRDTool
由于rrdtool-1.2.23需要一些库文件支持,故需先安装配置支持的环境,然后编译安装。直接运行以下bash脚本
就可以完成安装:
由于rrdtool-1.2.23需要一些库文件支持,故需先安装配置支持的环境,然后编译安装。直接运行以下bash脚本
就可以完成安装:
注意:将cgilib-0.5.tar.gz、zlib-1.2.3.tar.gz、libpng-1.2.18.tar.gz、freetype-2.3.5.tar.gz、
libart_lgpl-2.3.17.tar.gz、rrdtool-1.2.23.tar.gz放到/root/rrdtool-1.2.23目录下,将脚本保存
为/root/rrdtool-1.2.23/rrdtoolinstall.sh,并给执行权限chmod u+x
/root/rrdtool-1.2.23/rrdtoolinstall.sh
#!/bin/sh
BUILD_DIR=`pwd`
INSTALL_DIR=/usr/local/rrdtool
cd $BUILD_DIR
tar zxf cgilib-0.5.tar.gz
cd cgilib-0.5
make CC=gcc CFLAGS="-O3 -fPIC -I."
mkdir -p $BUILD_DIR/lb/include
cp *.h $BUILD_DIR/lb/include
mkdir -p $BUILD_DIR/lb/lib
cp libcgi* $BUILD_DIR/lb/lib
cd $BUILD_DIR
tar zxf zlib-1.2.3.tar.gz
cd zlib-1.2.3
env CFLAGS="-O3 -fPIC" ./configure --prefix=$BUILD_DIR/lb
make
make install
cd $BUILD_DIR
tar zxvf libpng-1.2.18.tar.gz
cd libpng-1.2.18
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \
./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
cd $BUILD_DIR
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.2.5
env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \
./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
cd $BUILD_DIR
tar zxvf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
env CFLAGS="-O3 -fPIC" ./configure --disable-shared --prefix=$BUILD_DIR/lb
make
make install
IR=-I$BUILD_DIR/lb/include
CPPFLAGS="$IR $IR/libart-2.0 $IR/freetype2 $IR/libpng"
LDFLAGS="-L$BUILD_DIR/lb/lib"
CFLAGS=-O3
export CPPFLAGS LDFLAGS CFLAGS
cd $BUILD_DIR
tar zxf rrdtool-1.2.23.tar.gz
cd rrdtool-1.2.23
./configure --prefix=$INSTALL_DIR --disable-python --disable-tcl && make && make install
//完成后建立符号连接
ln –s /usr/local/rrdtool/bin/* /usr/local/bin/
//执行rrdtool看是否安装正确
11).安装net-snmp
cd /usr/local/src/
tar zxvf net-snmp-5.2.4.tar.gz
./configure --prefix=/usr/local/net-snmp --enable-developer
make && make install
ln -s /usr/local/net-snmp/bin/* /usr/local/bin/
cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf
vi /usr/local/net-snmp/share/snmp/snmpd.conf
//修改snmpd.conf(修改COMMUNITY、允许抓取snmp数据的主机、抓取数据范围等)。
启动SNMP服务
/usr/local/net-snmp/sbin/snmpd
系统启动时启动SNMP服务
vi /etc/rc.d/rc.local
//在rc.local上加入一行/usr/local/net-snmp/sbin/snmpd
12).安装Cacti
cd /usr/local/src/
tar -zxvf cacti-0.8.6j.tar.gz
cp -r cacti-0.8.6j /usr/local/apache2/htdocs/cacti
vi /usr/local/apache2/htdocs/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
//添加cacti用户
useradd cacti -c "start cacti's account" -d /dev/null -s /sbin/nologin
//将rra目录的所有权给cacti用户
# chown -R cacti /usr/loca/apache2/htdocs/cacti/rra
//修改cacti目录所属组
# chgrp -R cacti /usr/loca/apache2/htdocs/cacti
//为cacti用户添加cron任务
crontab -u cacti –e
*/5 * * * * /usr/local/bin/php /usr/local/apache2/htdocs/cacti/poller.php > /dev/null 2>&1
注意:首次执行poller.php时请使用cacti用户,否则生成的rrd文件cacti将没有写入权限。
13).安装Cactid
CACTID 的安装需要以下支持:
o net-snmp-devel (需要编译安装net-snmp时添加--enable-developer选项)
o mysql
o mysql-devel (mysql源文件编译安装后默认支持)
o openssl-devel (Redhat默认安装)
# tar -zxvf cacti-cactid-0.8.6i.tar.gz
# cd cacti-cactid-0.8.6i
# ./configure --with-mysql=/usr/local/mysql --with-snmp=/usr/local/net-snmp
# make
//这时你将在此目录下看到多出了cactid、cactid.conf两个文件
# mkdir /usr/local/cactid
# cp cactid cactid.conf /usr/local/cactid
# vi /usr/local/cactid/cactid.conf //修改cactid配置文件
DB_Host 127.0.0.1
DB_Database cacti
DB_User cacti
DB_Pass cacti
14).数据库配置
#mysql -uroot -p
Password:
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.* to identified by "cacti";
Query OK, 1 row affected (0.00 sec)
mysql>exit
# cd /usr/local/apache2/htdocs/cacti
# mysql -uroot -pddl cacti < cacti.sql
Password:
15).完成cacti的安装
1).在浏览器中输入:
默认用户名:admin 密码:admin
2).更改密码
3).设置cacti用到的命令路径
snmpwalk Binary Path /usr/local/ bin/snmpwalk
snmpget Binary Path /usr/local/ bin/snmpget
RRDTool Binary Path /usr/local/ bin/rrdtool
PHP Binary Path /usr/local/bin/php
Cacti Log File Path /usr/local/apache2/htdocs/cacti/log/cacti.log
Cactid Poller File Path /usr/local/cactid/cactid
16).进入cacti后需确认更改以下位置:
Console>Settings>General> RRDTool Utility Version>RRDTool1.2.X
Console>Settings>Poller>Poller Type>cactid
相关下载:
mysql-5.1.36.tar.gz
httpd-2.2.4.tar.gz
zlib-1.2.3.tar.gz
libpng-1.2.18.tar.gz
freetype-2.3.4.tar.gz
jpegsrc.v6b.tar.gz
fontconfig-2.4.2.tar.gz
gd-2.0.34.tar.gz
libxml2-2.6.25.tar.gz
-
2.6.25.tar.gz/84ba8fd59f4e52dcd1fd368a61b3101e/libxml2-2.6.25.tar.gz
php-5.2.3.tar.gz
net-snmp-5.2.4.tar.gz
cacti-0.8.6j.tar.gz
cacti-cactid-0.8.6i.tar.gz
cgilib-0.5.tar.gz
zlib-1.2.3.tar.gz
libpng-1.2.18.tar.gz
freetype-2.3.5.tar.gz
libart_lgpl-2.3.17.tar.gz
rrdtool-1.2.23.tar.gz