zz:中文安装cacti使用手册

1、安装apache
tar xvf httpd-2.2.15.tar.tar
cd httpd-2.2.15
makedir /usr/local/apache2
./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most --with-mpm=worker --enable-disk-cache --enable-mem-cache
make 
make install

2、安装mysql
安装mysql
rpm -ivh MySQL-client-community-5.1.49-1.rhel5.i386.rpm
rpm -ivh MySQL-devel-community-5.1.49-1.rhel5.i386.rpm
rpm -ivh MySQL-server-community-5.1.49-1.rhel5.i386.rpm
service mysql stop
cp /usr/share/mysql/my-medium.cnf  /etc/my.cnf
service mysql start


3、安装php(php不能用5.3及以上的版本,因为废除了以前很多函数。导致cacti的程序不兼容)
3.1、安装jpegsrc.v6b.tar.gz
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir /usr/local/jpeg6/man
mkdir /usr/local/jpeg6/man/man1
gunzip jpegsrc.v6b.tar.gz
tar xvf jpegsrc.v6b.tar
cd jpeg-6b/
./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
make 
make install

3.2、安装libpng-1.4.3.tar.gz
gunzip libpng-1.4.3.tar.gz
tar xvf libpng-1.4.3.tar
cd libpng-1.4.3
./configure --prefix=/usr/local/libpng
make 
make install

3.3、安装freetype-2.4.1.tar.gz
gunzip freetype-2.4.1.tar.gz
tar xvf freetype-2.4.1.tar
cd freetype-2.4.1
./configure --prefix=/usr/local/freetype
make
make install

3.4、安装zlib-1.2.5.tar.gz
gunzip zlib-1.2.5.tar.gz
tar xvf zlib-1.2.5.tar
cd zlib-1.2.5
./configure --prefix=/usr/local/zlib
make
make install

3.5、安装gd库
前提是要安装 gettext
gunzip gettext-0.18.1.1.tar.gz
tar xvf  gettext-0.18.1.1.tar
cd gettext-0.18.1.1
./configure --prefix=/usr/local/gettext
make
make install
最好装gettext-devel以便能找到对应的库文件,否则会报错

gunzip gd-2.0.35.tar.gz
tar xvf gd-2.0.35.tar
cd gd-2.0.35
./configure --prefix=/usr/local/gd2 --with-jpeg-dir=/usr/local/jpeg6 --with-png=/usr/local/libpng --with-zlib-dir=/usr/local/zilb --with-freetype=/usr/local/freetype --enable-m4_pattern_allow
make 
make install

3.6、安装libxml2-2.7.7.tar.gz
gunzip libxml2-2.7.7.tar.gz
tar xvf libxml2-2.7.7.tar 
cd libxml2-2.7.7
./configure --prefix=/usr/local/libxml2
make
make install

3.7、安装libxslt-1.1.22.tar.gz
gunzip libxslt-1.1.22.tar.gz
tar xvf libxslt-1.1.22.tar
cd libxslt-1.1.22
./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
make 
make install

3.8、安装php5
gunzip php-5.2.14.tar.gz
tar xvf php-5.2.14.tar
cd php-5.2.14
./configure --prefix=/usr/local/php5  --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-gd=/usr/local/gd2  --with-ttf --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg6 --with-png-dir=/usr/local/libpng --with-zlib-dir=/usr/local/zlib --with-iconv --enable-xml --enable-mbstring  --enable-sockets --enable-gd-native-ttf  --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php5/etc
make
make install

cp php.ini-development  /usr/local/php5/etc/php.ini
vi  /usr/local/php5/etc/php.ini将register_globals = Off改成register_globals = On
;date.timezone =  改为date.timezone = utc
;extension=php_mbstring.dll 改为 extension=php_mbstring.dll
;mbstring.func_overload = 0修改为:mbstring.func_overload = 7


配置apache
最后修改httpd.conf,使apache能使用php,增加如下参数
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    AddType image/x-icon .ico

DirectoryIndex index.php index.html index.html.var

4、安装rrd
4.1、安装cgilib
gunzip cgilib-0.5.tar.gz
tar xvf cgilib-0.5.tar
cd cgilib-0.5
make CC=gcc CFLAGS="-O3 -fPIC -I."
mkdir -p /usr/local/cgilib/include
cp *.h /usr/local/cgilib/include/
mkdir -p /usr/local/cgilib/lib
cp libcgi* /usr/local/cgilib/lib/

4.2、安装libart_lgpl-2.3.21.tar.gz
gunzip libart_lgpl-2.3.21.tar.gz
tar xvf libart_lgpl-2.3.21.tar
cd libart_lgpl-2.3.21
./configure --disable-shared --prefix=/usr/local/libart_lgpl
make
make install

编辑/etc/ld.so.conf,增加如下参数
/usr/local/zlib/lib
/usr/local/freetype/lib
/usr/local/jpeg6/lib
/usr/local/cgilib/lib
/usr/local/libart_lgpl/lib
配置完后执行ldconfig命令,使用动态装入器装载到共享库

4.3、安装rrdtool(最好用1.3,目前cacti能支持的最高只到1.3)
gunzip rrdtool-1.4.4.tar.gz 
tar xvf rrdtool-1.4.4.tar
cd  rrdtool-1.4.4
./configure --prefix=/usr/local/rrdtool --disable-python --disable-tcl
make
make install

5、安装net-snmp
gunzip net-snmp-5.5.tar.gz
tar xvf net-snmp-5.5.tar
cd net-snmp-5.5
 ./configure --prefix=/usr/local/net-snmp --enable-developer
 make
 make install
 ln -s /usr/local/net-snmp/bin3 * * * *  /usr/local/php5/bin/php /usr/local/apache2/htdocs/poller.php


7、安装cacti-spine-0.8.7e.tar
tar xvf cacti-spine-0.8.7e.tar
cd cacti-spine-0.8.7e
./configure --prefix=/usr/local/spine --with-mysql --with-snmp=/usr/local/net-snmp
make
make install
查看/usr/local/spine/etc/spine.conf的配置是否正确


安装完后.连接到cacti网站登陆后进行设置
常规-->rrdtool应该程序的版本改成安装的版本(1.3.x)
路径-->设置不对的文件名,改成正确的路径+文件名


Cacti的使用简易教程 
1. 监控远程Linux主机
开启远程主机的SNMPD服务

2. 在Cacti里,进行如下操作,步骤的过程为:添加Devices(增加设备)->Graphs(增加图象)->Tree(增加到图象树)
2.1. Console->Management->Devices->add (增加监控设备)
Description:主机描述,可随便写
Hostname:主机IP地址
Host Template:主机模板,可以选UCD/Net snmp Host,也可以选None
SNMP Community:主机中的Community字段值,默认是public
SNMP Version:一般选Version1或Version2
2.2. Console->Management->Devices 选中刚才添加的主机,进入编辑界面(给监控主机增加要生成的"图像模板"和进行的"数据查询")
Associated Graph Templates:加入
1) ucd/net - CPU Usage
2) ucd/net - Load Average
3) ucd/net - Memory Usage
如果是本机,可以加入以下模板:
1) Linux - Memory Usage
2) Unix - Ping Latency
3) Unix - Load Average
4) Unix - Logged in Users
5) Unix - Processes
Associated Data Queries:加入
1) SNMP - Interface Statistics 
2.3. Console->Create ->New Graphs(生成2.2步骤中增加的图象和数据)
在列表框中选中刚添加的主机,再选中所有Graph Templates和Data Query,再Create。
2.4. Console->Management->Graph Trees->Default Tree->Add(使生成的图象和数据能在"查看图象"即在"Graphs"中以图象的方式显示出来)
Parent Item:父节点,默认是根
Tree Item Type:节点类型,Host
Host:选择主机
Sorting Type:排序方式
[Create]
2.5. Graphs->Default Tree->HostName查看看监控结果

3. 监控本地机
默认Cacti自动安装了监控本地机的模板,也可以自己重建,可按上面的方式,在第一步的Host Template中,选Local Linux Host就可,或者直接用IP,不用本地方式。
4. 日志
日志设置:Console -> Settings -> General -> Poller Logging Level,一般选Low既可,可以选Medium查看SNMPWALK的输出,Debug调试。
日志查看:Console -> Utilities -> View Log File
日志清除:Console -> Utilities -> Clear Log File
5. 图表删除
直接在Devices里删除主机,将删除相关所有数据。
在Console -> Graph Management里的Graph Management可单独删除一个图表,在Data Sources可删除一个查询。
6. 树的管理
Console -> Graph Trees,可以很方便的管理多台主机,将多台主机组成一个树形结构,并且,可以为树指定用户权限.
7. 权限的管理
Console -> User Management,可以管理用户,并指定权限.


报警的实现:

如果需要提供报警功能还需要安装其他插件
1、增加cacti插件的方法:为cacti系统安装Thold、Monitor等插件

插件下载地址:http://cactiusers.org/downloads/
注意下载时注意相应版本,版本不对会产生问题。

monitor插件,提供更简略、直观的设备状态图示; 
thold插件,提供设备异常预警。

安装thold、monitor插件:注意要先备份一下

(1)、安装Plugin Architecture补丁,安装后,才能启用thold、monitor插件

shell> tar zxvf cacti-plugin-arch.tar.gz -C /var/www/cacti 
shell> cd /var/www/cacti/ 
shell> patch -p1 -N < cacti-plugin-arch/cacti-plugin-0.8.7a-PA-v2.1.diff 
shell> /opt/mysql/bin/mysql -u cactiuser -p cactidb < pa.sql

(2)、安装thold、monitor插件

shell> tar zxvf settings-0.5.tar.gz -C /var/www/cacti/plugins 
shell> tar zxvf thold-0.3.4.tar.gz -C /var/www/cacti/plugins 
shell> tar zxvf monitor-0.8.2.tar.gz -C /var/www/cacti/plugins

shell> cd /var/www/cacti/plugins/ 
shell> /opt/mysql/bin/mysql -u cactiuser -p cactidb < thold/thold.sql 
shell> /opt/mysql/bin/mysql -u cactiuser -p cactidb < monitor/monitor.sql

(3)、修改config.php配置文件

shell> vi /var/www/cacti/include/config.php

$config['url_path'] = "/cacti/";  //改为cacti对应于web目录下的路径,本处为cacti 
$plugins = array(); 
$plugins[] = thold; 
$plugins[] = monitor;

(4)、刷新cacti系统的web管理界面,可以看到多出两个标签页(thold、monitor)。

(5)、使用monitor插件

1>打开“Console->Settings->Misc”,可以调整Monitor的各项配置。例如:勾选“Show Icon Legend”可以在监控页面显示图例;

“View”可以选用Tiles类型,以显示设备状态表格。 
2>为cacti添加新设备时,勾选上“Monitor Host”项。对已添加的设备可以通过“Management->Devices”进去修改。 
3>单击Web页面上方的“monitor”标签链接,可以进入查看各设备/主机的状态图示。

(6)、使用thold插件

1>打开“Console->Settings->Mail/DNS”,可以调整“SMTP Options”和“DNS Options”等配置,用于确保预警邮件能够发出。 
2>打开“Console->Settings->Alerting/Thold”,可以调整Thold的各项配置。例如:“Dead Host Notifications Email”处可填写设备当机时发送警告信息到哪个邮箱;勾选“Send alerts as text”项,可以设置只发送文本格式的邮件。 
3>打开“Templates->Threshold Templates”,可以添加、取出需要关联到预警系统的模板,例如:可以添加和“Interface-Traffic”模板的关联,选择“traffic_in”、“traffic_out”数据项,分别设置警告阈值“High Threshold”(如200000000比特/秒);可以添加和“Unix-Disk Space”模板的关联……。 
4>打开“Create->New Graphs”,选择需要提供预警的设备,单击右侧上方的“Auto-create thresholds”创建预警项目。 
5>打开“Management->Thresholds”,可以管理已经创建的预警项目。

2、cacti监控硬盘I/O的方法:

cacti本身的模板只可以监控硬盘的使用大小,而不能监控使用百分率,所以我们可以自定义cdef来监控硬盘使用率,并借助thold插件实现报警功能。网上找的资料都是在cacti.0.8.6版上实现的,而我用的是cacti.0.8.7版。因此,根据实际情况做如下改动:

在cacti目录下,vi global_arrays.php 
搜索custom_data_source_types,修改这一段如下:

$custom_data_source_types = array( 
        "CURRENT_DATA_SOURCE" => "Current Graph Item Data Source", 
        "ALL_DATA_SOURCES_NODUPS" => "All Data Sources (Don't Include Duplicates)", 
        "ALL_DATA_SOURCES_DUPS" => "All Data Sources (Include Duplicates)", 
        "SIMILAR_DATA_SOURCES_NODUPS" => "All Similar Data Sources (Don't Include Duplicates)", 
        "SIMILAR_DATA_SOURCES_DUPS" => "All Similar Data Sources (Include Duplicates)", 
        "CURRENT_DS_MINIMUM_VALUE" => "Current Data Source Item: Minimum Value", 
        "CURRENT_DS_MAXIMUM_VALUE" => "Current Data Source Item: Maximum Value", 
        "CURRENT_GRAPH_MINIMUM_VALUE" => "Graph: Lower Limit",

//添加以下两行 
"CURRENT_GRAPH_MAXIMUM_VALUE" => "Graph: Upper Limit", 
        "VALUE_OF_HDD_TOTAL" => "Value of hdd_total data source");

//中文版汉化为: 
        "CURRENT_GRAPH_MAXIMUM_VALUE" => "图像: 上限", 
        "VALUE_OF_HDD_TOTAL" => "所有硬盘数据的值");

在cacti界面的Graph Management-cdefs新建cdef模块,名字自己起,添加字段如下:

Item #1 Special Data Source: CURRENT_DATA_SOURCE      
Item #2 Custom String: 100      
Item #3 Operator: *      
Item #4 Special Data Source: VALUE_OF_HDD_TOTAL      
Item #5 Operator: / 


也就是说 
cdef=CURRENT_DATA_SOURCE,100,*,VALUE_OF_HDD_TOTAL,/ 
  
这样就可以在Threshold Templates里面添加监控硬盘的模块了,我添加的是Host MIB - Hard Drive Space ,最后在Threshold CDEF里面选择刚自定义的cdef,这样就可以正常监控硬盘使用率了。

官方论坛上有介绍,地址http://forums.cacti.net/about8777-0-asc-0.html

下面把使用方法摘录如下:

1. Copy net-snmp_devio.xml to /resource/snmp_queries/net-snmp_devio.xml

2. Import all *_templ.xml via Cacti "Import Templates" interface - These templates should include all their dependancies

3. Add "ucd/net - Get Device I/O" Data Query to your SNMP Enabled host using the "Index Count Changed" Re-index Method.

4. Create Graphs for your desired Disk and/or Memory devices.

总体注意事项:

1)、很重要的一点:在cacti的设备中一定要选择snmp的版本为>=2,否则会获取不到cpu和网卡等相关信息。

2)、cacti自带的local视图内存监控单位是错误的,可以删掉重新创建,就会改正。

3)、系统监控中,cpu图标的 200m这类数字,表示的是 万分之多少,我的理解cacti是为了方便显示画图。

4)、权限问题:cacti_path/rra log目录的权限一定要给cacti的新用户,否则会出错:有图,但是没有数据。

猜你喜欢

转载自laibulai.iteye.com/blog/941644
今日推荐