首页 > 代码库 > Cacti的设置以及Spine轮询器

Cacti的设置以及Spine轮询器

Cacti的设置

    接着上一篇的cacti系列讲解,在配置选项中有两个子项目,Settings和Plugin Management。我们点击Settings后,出现以下界面。

wKiom1PoDdGwpcgIAAQaoHPu__g367.jpg

我们看到上图中,箭头指向的地方,我们可以针对这些项目进行设置。

首先我们看一下“General”,通用配置,配置的内容主要有以下几项

  • 日志

  • SNMP相关的设置

  • 其他配置

其实这里基本上不需要进行修改,保持默认的配置即可。如果需要修改,也就是“Required Tool Versions”和“SNMP Defaults”,修改后点击“Save”。


接下来看“Path”选项,很明显,这是和路径相关的。主要配置的内容有

  • 所需工具的路径(snmp, rrdtool, php)

  • Cacti日志文件的存放路径

  • Spine轮询优化器的路径(在下面的内容中我们马上讲解)

  • 结构化RRD路径(勾选此选项,那么每一个主机的RRD文件会单独存放在某个目录下)

    我们看到,这里的配置路径和刚开始安装和初始化Cacti时的检测的一致。所有的配置保持默认即可,基本不需要配置。

    唯一我们下面需要更改的地方就是 Alternate Poller Path, 先记住,我们下面再说。

wKiom1PoEbmBnyzZAAA98ULKqu4901.jpg


接下来看“Poller”选项,Cacti采集器的配置,主要配置内容有

  • 通用配置

  • 采集器参数设置

  • 主机高可用配置

  • 主机在线/宕机配置

    在Poller配置中我们可以选择“Poller Type”(采集器类型),cmd.php及poller.php采集器,此采集器是用php编写的,功能比较简单。另一种是spine采集器,是多线程的,效率比较高,适合大规模的监控。等一下我们就会详细介绍spine的安装使用,这里先别动。

wKiom1PoG52T2w64AAEjjE4JCxk324.jpg


接下来是“Graphs Export”选项,可以将我们生成的图片导出到什么地方。可以导出到本地,或是远程FTP服务器上,主要的配置选项有:

  • 通用配置

  • 图形树配置

  • 缩略图配置

  • 路径配置

  • 导出时间配置FTP选项等

我们一般不需要导出图形。


下面是“Visual”选项,主要设置Cacti页面是如何显示的,主要配置有

  • 图形管理配置

  • 数据查询配置

  • 图形创建配置

  • 数据源显示配置

  • 主机显示配置

  • 日志管理配置

  • 默认的RRDTool工具配置

保持默认的配置即可。


最后,我们讲解“Authentication”选项,主要有四种认证方式,分别为:

  • 无             无认证方式,所有的用户都将拥有全部访问权限(危险)

  • 内建验证       Cacti控制用户认证,这将允许你建立用户并设置它们访问Cacti的权限。

  • WEB基本认证    通过Apache控制用户认证,如果定义了模板用户,新用户将在第一次登陆时被创建,否则将会使用已定义的来宾用户权限。

  • LDAP认证       允许将认证交给LADP服务器,如果定义了模板用户,新用户将在第一次登录时被创建,否则,将会使用已定义的来宾用户权限,如果没有启用PHP的LDAP模块,下拉菜单中不会出现LDAP认证。

通常,我们会选择内建验证。


开启匿名访问用户:guest

第一步:User management -> 出现用户列表, 点击“用户名”

User management -> 点击“guest”, 会出现如下界面,勾选 Enabled

wKioL1PoIZbAUd7DAAQEr64sTJs123.jpg第二步:针对graph等进行默认的权限设置。也就是被圈住的各个选项,分别配置其访问的权限。



Cacti优化之spine轮询器

    由于效率的原因,在需要大量采集数据时,如果使用自带的cmd.php轮询器会比较慢,1分钟1次的采集频率可能无法完成轮询所有的被监控的机器。为了解决效率问题,Cacti官方也推出spine,采用多线程的方式高效的轮询。

这里直接引入官方的文档:http://www.cacti.net/spine_install.php


Spine Installation

Spine needs to be compiled before it can be used. If you found a binary package of Spine for your operating system, you can skip the next step about compiling Spine.

Compiling Spine

  • Compiling Spine for Windows under Cygwin

  • Compiling Spine for Redhat/Fedora Linux


Compiling Spine for Redhat/Fedora Linux

Before you continue, check if any pre-compiled packages are available for your version of Redhat/Fedora Linux. These instructions will help you compile Spine from source if no binary packages are available.

Prerequisites

Make sure that the following packages are installed before attempting to compile Spine:

  • net-snmp-devel

  • mysql

  • mysql-devel

  • openssl-devel

Compiling Spine

Download the latest source distribution of Spine and run the following commands to get a working binary:

tar xvzf cacti-spine-0.8.7.tar.gz
cd spine-0.8.7
./configure
make

Now you must move your new binary, spine and spine.conf to a more permanent home such as /usr/local/spine. Edit thespine.conf file and specify your database connection information for Cacti.

You should now be ready to start using Spine!

Setting Up Spine

Once Spine is installed on your system, you must perform the following steps to make your Cacti installation aware of it.

  1. Login to Cacti as an admin user.

  2. Select Settings on the menu and click the Paths tab.

  3. Enter the complete path to your Spine binary in the Spine Poller File Path field and click Save.

  4. Click the Poller tab.

  5. Choose "spine" from the Poller Type dropdown box and click Save.

After completing these steps, Cacti will spawn Spine every 5 minutes instead of cmd.php. If you are having problems getting Spine to gather data, you can always temporarily change Poller Type back to "cmd.php".


鉴于有些同学看着英文就有点头晕,这里我也演示一下。

1、解决依赖关系

## 依赖于mysql mysql-devel net-snmp-devel openssl-devel
## 我们在安装cacti的时候已经安装 mysql  mysql-devel 所以,这里只需安装另外2个
[root@localhost ~]# yum -y install  net-snmp-devel openssl-devel

2、安装spine,下载的版本最好与cacti一致,spine-0.8.8b

[root@localhost ~]# tar xf cacti-spine-0.8.8b.tar.gz 
[root@localhost ~]# cd cacti-spine-0.8.8b
[root@localhost cacti-spine-0.8.8b]# ./configure
[root@localhost cacti-spine-0.8.8b]# make && make install

3、提供配置文件

[root@localhost ~]# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
## 编辑配置文件,请根据实际情况修改
[root@localhost ~]# vi /etc/spine.conf 
DB_Host         localhost
DB_Database     cactidb
DB_User         cactiuser
DB_Pass         cactiuser
DB_Port         3306
DB_PreG         0

# 这里的配置是怎么来的呢? 还记得吧, 就是 cacti/include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;

4、测试

[root@localhost ~]# /usr/local/spine/bin/spine
## 报错了
MYSQL: Connection Failed: Error:‘2003‘, Message:‘Can‘t connect to MySQL server on ‘shuttle‘ (61)‘
05/12/2012 07:14:22 PM - SPINE: Poller[0] FATAL: Connection Failed, Error:‘2003‘, Message:‘Can‘t connect to MySQL server on ‘shuttle‘ (61)‘ (Spine init)

## google了一下
You probably checked it out already but make sure: 
DB_Host 127.0.0.1
and NOT
DB_Host localhost

wKioL1PoK5_RMHa4AABsxGQF3o0675.jpg

OK, 再测试一下:

[root@localhost ~]# /usr/local/spine/bin/spine 
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8b starting
SPINE: Time: 0.1707 s, Threads: 5, Hosts: 2
[root@localhost ~]#

5、在cacti的WEB页面进行设置spine的路径

    前面,我们已经提到了。

Console -> Configureation -> Settings -> Alternate Poller Path -> Spine Poller File Path

输入spine的路径:默认安装在/usr/local/spine/bin/spine

wKiom1PoK5iRqptOAAFQqsCfm8g626.jpg

6、修改Cacti默认的Poller Types

Console -> Cacti Settings -> Poller -> Poller Type

在下拉框中,选择spine, 然后记得“Save”

wKioL1PoLTDh7Q8PAACj-QuoBLk804.jpg

注意:Spine不必为其添加计划任务,Cacti well spawn Spine every 5 minutes instead of cmd.php

而poller.php需要定义计划任务去执行,然后poller.php再去调度数据收集方法。


好了, 到这里就结束了。

本文出自 “Share your knowledge” 博客,请务必保留此出处http://skypegnu1.blog.51cto.com/8991766/1538459