1. 安装环境:Red Hat AS 4
2. 安装 Apache、MySQL、PHP (1).安装 MySQL
下载地址:http://dev.mysql.com/downloads/mysql/5.0.html
//查看系统中是否已经安装了 MySQL,如果是卸载所有以 mysql 开头的包。
# rpm –qa | grep mysql
# rpm –e mysql‐*
//查找/etc/my.cnf(MySQL 的选项配置文件),如果有请删除它,以免影响新安装版
本的启动。
# rm –f /etc/my.cnf
# tar –zxvf mysql‐standard‐5.0.27‐linux‐i686‐glibc23.tar.gz
# cp –rf mysql‐standard‐5.0.27‐linux‐i686‐glibc23 /usr/local/
//建立符号链接,如果以后有新版本的 MySQL 的话,你可以仅仅将源码解压到新
的路径,然后重新做一个符号链接就可以了。这样非常方便,数据也更加安全。
# ln –s mysql‐standard‐5.0.27‐linux‐i686‐glibc23 /usr/local/mysql
//添加用于启动 MySQL 的用户及用户组(如果以前安装过 MySQl,用户及用户组
可能已存在)。
# useradd mysql
# groupadd mysql
//初始化授权表
# cd /usr/local/mysql
# scripts/mysql_install_db
//修改 MySQl 目录的所有权
# cd /usr/local
# chgrp –R mysql mysql‐standard‐5.0.27‐linux‐i686‐glibc23
# chgrp –R mysql
# chown –R mysql mysql‐standard‐5.0.27‐linux‐i686‐glibc23/data
# chown –R mysql mysql/data
# ln –s /usr/local/mysql/bin/* /usr/local/bin/
//启动 Mysql
# bin/safe_mysqld ‐‐user=mysql &
//配置系统启动时自动启动 MySQl
# cp support‐files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig ‐‐add mysqld
//修改MySQL的最大连接数
# vi /etc/my.cnf
//添加以下行
[mysqld]
set-variable=max_connections=1000
set-variable=max_user_connections=500
set-variable=wait_timeout=200
//max_connections设置最大连接数为1000
//max_user_connections设置每用户最大连接数为500 //wait_timeout表示200秒后将关闭空闲(IDLE)的连接,但是对正在工作的连接
不影响。
//保存退出,并重新启动MySQL
//重新启动MySQL后使用下面的命令查看修改是否成功
# mysqladmin -uroot -p variables
Password:
//可以看到以下项说明修改成功
| max_connections | 1000
| max_user_connections | 500
| wait_timeout | 200
(2).安装 Apache
下载地址:http://httpd.apache.org/
# tar –zxvf httpd‐2.2.4.tar.gz
# cd httpd‐2.2.4
# ./configure ‐‐prefix=/usr/local/apache ‐‐enable‐so
//编译时加上加载模块参数--enable-so
# make
# make install
#vi /usr/local/apache/conf/httpd.conf
//修改Apache配置文件,添加ServerName www.yourdomain.com (或ServerName 本
机ip)
# vi /etc/rc.d/rc.local
//在 rc.local 上加入一行/usr/local/apache/bin/apachectl –k start,系统启动时启动
Apache 服务。
(3).安装 PHP
先安装zlib,freetype,libpng,jpeg以便于让PHP支持GD库(Cacti的WeatherMap
插件必须要 GD 库的支持)
库文件下载地址:http://oss.oetiker.ch/rrdtool/pub/libs/
1).安装 zlib
tar zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr/local/zlib
make
make install
2).安装 libpng
tar zxvf libpng-1.2.16.tar.tar
cd libpng-1.2.16 cd scripts/
mv makefile.linux ../makefile
cd ..
make
make install
注意,这里的 makefile不是用./configure生成,而是直接从 scripts/里拷一个
3).安装 freetype
tar zxvf freetype-2.3.4 .tar.gz
cd freetype-2.3.4
./configure --prefix=/usr/local/freetype
make
make install
4).安装 Jpeg
tar -zxf jpegsrc-1.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
//可以用 mkdir -p /usr/local/libjpeg/man/man1 一步创建多层目录
./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
make && make install
注意,这里 configure一定要带--enable-shared参数,不然,不会生成共享库
5).安装 Fontconfig
tar -zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2
make
make install
6).安装 GD
tar -zxvf gd-2.0.34.tar.gz
cd gd-2.0.34
./configure --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,RedHat AS 4默认安装 libxml包,但版本太低,PHP5需要更高
版本的 libxml包。
# tar –zxvf libxml2-2.6.25.tar.gz
# cd libxml2-2.6.25
# ./configure
# make
# make install
9).安装 PHP
PHP 下载地址:http://www.php.net/downloads.php#v5
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
# ln –s /usr/local/php/bin/* /usr/local/bin/
# vi /usr/local/apache/conf/httpd.conf
查找 AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在其下加入 AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType image/x-icon .ico
修改DirectoryIndex 行,添加 index.php
修改为DirectoryIndex index.php index.html index.html.var # vi /usr/local/apache/htdocs/test.php
添加以下行:
2. MySQL stats模板
论坛讨论:http://forums.cacti.net/about11010.html
下载地址:http://www.faemalia.net/mysqlUtils/
功能:用来监控 MySQL 状态,其中包括索引使用情况、查询、排序、锁定情况等。
1) . 将 mysql_stats.php 和 dumpMemcachedStats.php脚本放到 cacti脚本目
录下( /usr/local/apache/htdocs/cacti/scripts/ ),导入模板时注意选择
cacti_host_template_temysql_host-step300-heartbeat600.xml 和
cacti_host_template_memcached_host-step300-heartbeat600.xml模板
2).配置MySQL服务器,让cacti所在机器能够访问 MySQL 服务器的状态信息,必
须拥有"process"权限。如果要监控 InnoDB状态,还必须有"SUPER"权限。
GRANT PROCESS ON * TO cacti@'cactimachine' IDENTIFIED by 'cacti';
GRANT SUPER ON * TO cacti@'cactimachine' IDENTIFIED BY 'cacti';
3).创建Graph。在Console选项卡下的左侧菜单栏中选择Devices,为要监控的主机
新建一个Devices或选择已有Devices。在Associated Graph Templates中添加想要
监控MySQL状态的Graph Templates(如teMySQL – Index Usage模板,此套模板是
以teMySQL开头的一系列模板) 。并点击最上面的Create Graphs for this
Host链接,在Graph Templates的选择框中选择teMySQL – Index Usage,然后点击
Create按钮,出现以下WEB页。
填写以下内容:
1).Data Source 选择定义的数据源模板;
2).Color 只有“Graph Item Type”图形类型选择的是AREA, STACK, LINE1, LINE2,
LINE3其中之一,才能够为数据源选择颜色;
3).Graph Item Type 定义图形的项类型,因为是首个图形项,所以要选择“AREA”;
4).Text Format 定义一个显示名称; 其它的数值保持默认,点击“create”。
点击 Add 继续添加“Graph template Items”。
添加当前运行值,填写以下内容:
1).Data Source 选择“Windows - CPU Usage - (WindowsCPU)”
2).Graph Item Type 选择“GPRINT”图形项类型,只有这个类型才能定义当前、平均和
最大值。
3).Consolidation Function 选择“LAST”,表示当前运行的值
4).Text Format 定义图表中显示的名称
点击最上边的Create Graphs for this Host 连接。选中想要的作图模板,点击“create”
按钮为主机创建监控图。
将新建的监控图添加到 Graph Trees 节点上,先在 Graph Trees 创建一个节点,然后在
Graph Management中选中想要添加到此节点的监控图,在Choose an action 下拉框
中选择Place on a Tree(此节点的根节点) ,点击go按钮。
选择想要将监控图添加到的节点。
填写以下信息,在 Low Threshold文本框中填入 1000,意思是当剩余的硬盘空间小
于 1000M 时,发送邮件报警。在Threshold CDEF下拉框选择Divide by 1024,
填入警报邮箱,完成Threshold 模板的添加。
应用刚才创建的Threshold模板。在console选项卡下点击Devices,选择要应用此模
板的Host,点击最上面的Create Graphs for this Host链接,然后点击
Auto-create thresholds链接来应用刚创建的Threshold模板。
设置完成后在 console选项卡下左侧菜单中点击 Thresholds 。
在此可以管理已创建的警报。
点击 threshld 选项卡可以查看警报的触发情况。
4. 其它插件
其它插件可到http://cactiusers.org/downloads/自行下载安装,在此只略述一二。
1) .Discovery: This plugin adds the ability to auto-discover devices on a subnet that
are not monitored by Cacti and and tells you if they are SNMP enabled.
2) . Flowviewer: A simple viewer for viewing reports based on data from flows created
by Netflow.
3).Settings:This plugin houses common settings and functions used by different
plugins.
4).Network Weathermap:这是一个比较复杂的cacti 插件,他需要GD库的支持,可以参照
cacti 的安装小节来支持GD 库。使用它可以画出漂亮的网络状况图。
官网说明:http://www.network-weathermap.com/node/79
下载地址:http://www.network-weathermap.com/download
安装方法:
http://www.network-weathermap.com/manual/0.92/pages/install-cacti-editor.html