ddsdjn 发表于 2019-1-11 07:10:52

cacti安装配置使用详结

  最近有一个项目内服务器频繁出现问题,需要单独建立一套监控系统,暂使用cacti来监控,时间关系以后再考虑nagois+cacti结合或zabbix.
  所需软件包下载路径:
http://packages.express.org/rrdtool/rrdtool-1.4.5-1.el5.wrl.x86_64.rpm
http://packages.express.org/rrdtool/rrdtool-devel-1.4.5-1.el5.wrl.x86_64.rpm
http://packages.express.org/rrdtool/rrdtool-perl-1.4.5-1.el5.wrl.x86_64.rpm
http://www.cacti.net/downloads/cacti-0.8.7h.tar.gz
  ============
基础环境准备
============
1. 系统安装包环境:
base
editors
development librarys
development tools
x software development

yum groupinstall "develop tools"
yum install gcc gcc-c++   gcc编译环境必须有
  2. cacti的LAMP环境准备:
yum install httpd php php-mysql mysql mysql-server
  3. cacti的mysql环境准备:
启动mysql并添加开机启动:
chkconfig --add mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
mysql_install_db
  cacti用户的创建:
useradd -s /sbin/nologin cactiuser
  4. 服务器端和客户端所需软件snmp安装,利用snmp协议(简单网络管理协议)获取数据:
unix系统安装的都是net-snmp或ucd-snmp(其实两个都是同一组人写的)。
这里说的安装SNMP服务并不是要求安装SNMPD,其实是Cacti需要用到net-snmp中的两个命令――snmpwalk和snmpget进行数据的采集。
yuminstallnet-snmp-develnet-snmp-perlnet-snmp-utilsphp-snmp
  配置文件更改:/etc/snmp/snmpd.conf
1)查找字段更改代码.


[*]#         sec.name       source   community
[*]com2sec   notConfigUser   default   public

  将"comunity"字段改为你要设置的密码.比如"public".
将“default”改为你想哪台机器可以看到你的snmp信息,授权cacti服务器IP如


[*]#       sec.namesource          community
[*]com2sec notConfigUser192.168.7.250       public
[*]com2sec notConfigUser127.0.0.1       public

  也可以添加多台cacti-server的IP来监控
  2)查找以下字段将read对应权限none改为all


[*]#       group      context   sec.modelsec.levelprefixread   writenotif
[*]accessnotConfigGroup""      any       noauth    exactallnonenone

  3)查找以下字段去掉view前面的#号:


[*]##         incl/excl subtree                        mask
[*]viewall    included.1                               80
[*]## -or just the mib2 tree-
[*]viewmib2   included.iso.org.dod.internet.mgmt.mib-2 fc

  启动net-snmp:
snmpd -d /etc/snmp/snmpd.conf或
/etc/init.d/snmpd start
/etc/init.d/snmptrapd start
snmpget -v 1 -c public localhost system.sysUpTime.0 测试
  
============
cacti-server的安装
============
1.安装rrdtool的支持
rrdtool处理rrd 数据库,它用向rrd数据库存储和读取数据来绘图生成输出结果
yum install php-snmpphp-mbstring gd-*x86_64 libart*x86_64
rpm -ivh rrdtool-perl-1.4.5-1.el5.wrl.x86_64.rpm rrdtool-1.4.5-1.el5.wrl.x86_64.rpm rrdtool-devel-1.4.5-1.el5.wrl.x86_64.rpm
  2.cacti的安装及导入数据库
#tar -zvxf cacti-0.8.7h.tar.gz -C/var/www/html/
#cd /var/www/html/
#mv cacti-0.8.7hcacti
#chown cactiuser.apache cacti –R
#chmod 775 cacti –R
#mysql -uroot -p cacti < cacti.sql   导入cacti数据库,这里无论是以cactiuser或root用户导入,只要数据库中赋予cactiuser对cacti数据库的all权限就好了
  创建cactiuser用户并授权cacti数据库all权限
# mysql


[*]mysql>create database cacti;   
[*]mysql> grant all on cacti.* to root;
[*]mysql> grant all privileges on cacti.* to root@localhost
[*]mysql> grant all on cacti.* to cactiuser;
[*]mysql> grant all privileges on cacti.* to cactiuser@localhost identified by 'cactiuser';
[*]mysql> flush privileges;

  cacti配置文件更改,设置连接数据库
#vi/var/www/html/cacti/include/config.php


[*]$database_type = &quot;mysql&quot;;
[*]$database_default = &quot;cacti&quot;;
[*]$database_hostname = &quot;localhost&quot;;
[*]$database_username = &quot;cactiuser&quot;;
[*]$database_password = &quot;cactiuser&quot;;
[*]$database_port = &quot;3306&quot;;
[*]$database_ssl = false;

  注:倘若后面http://IP/cacti形式访问不了cacti,页面空白,需在include/global.php全局设置下定义URL path:


[*]/* built-in snmp support */
[*]$config[&quot;php_snmp_support&quot;] = function_exists(&quot;snmpget&quot;);
[*]后添加:
[*]/* set URL path */
[*]if (! isset($url_path)) {
[*]      $url_path = &quot;/cacti/&quot;;
[*]}
[*]$config['url_path'] = $url_path;
[*]define('URL_PATH', $url_path);

  测试定时收集数据的poller.php文件并将其加入crontab:
crontab -u cactiuser –e


[*]*/5 * * * * /usr/bin/php -f /var/www/html/cacti/poller.php >/dev/null 2>&1

  或先手动执行一下phppoller.php收集数据是否有报错
日志查看:tail –f /var/www/html/cacti/log/cacti.log
  ============
WEB管理界面访问
============
apache默认配置文件,开启httpd服务,访问页面http://IP/cacti
需要输入一些原始的信息:
NETXT-->rrdtool,php,snmpwalk,snmpget的路径,net-snmp等,确认路径信息-->设置原始的用户和密码:admin/admin-->更改admin用户密码-->save-->cacti安装完成
  测试:
cacti服务器上手工获取snmp命令:
snmpwalk -v 2c -c public 192.168.7.31:161 system
snmpwalk -v 版本号 -c 团体号 ip 类别
默认snmp协议udp端口161,tcp端口199(可以不用,关闭)
图形界面的添加管理见附件:cacti使用手册
  =============
cacti插件安装
============
详细cacti安装说明见相应版本的官方手册http://docs.cacti.net/manual:087
插件说明http://docs.cacti.net/plugins
插件下载地址:
cacti-pluginhttp://www.cacti.net/downloads/pia/cacti-plugin-0.8.7h-PA-v3.0.tar.gz   支持插件管理的扩展包
thold   http://docs.cacti.net/_media/plugin:thold-v0.4.9-3.tgz          注:Thold requires the Settings plugin v0.71 to be installed.
settingshttp://docs.cacti.net/_media/plugin:settings-v0.71-1.tgz
monitorhttp://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz
  
tar zxvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
mv cacti-plugin-arch/*/var/www/html/cacti/
cd /var/www/html/cacti/
patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff
mysql -ucactiuser -pcactiuser cacti< pa.sql
注意所有目录权限更改775,属主组cactiuser.apache
安装好cacti-plugin后,需要在web页面登陆cacti,然后点左侧菜单里的user managerment,点击admin账户,然后在下面把plugin managerment权限勾上,这样就在左侧console菜单里多了插件管理选项 plugin management
  把下载到的插件重命名后解压:
tar zxvf settings-v0.71-1.tgz
tar zxvf thold-v0.4.9-3.tgz
tar zxvf monitor-v1.3-1.tgz
然后把三个插件复制到…/cacti/plugin目录下,WEB界面里在plugin management中install和enable这三个插件就可以了。
注意:有些插件默认不显示在页面上,需要在user managerment里将View Thresholds或View minitore选择上。
  查看/var/www/html/cacti/include/config.php,默认插件装好后已添加:


[*]#$cacti_session_name = &quot;Cacti&quot;;
[*]$plugins = array();
[*]$plugins[] = 'thold';
[*]$plugins[] = 'monitor';



附件:http://down.运维网.com/data/2362239

页: [1]
查看完整版本: cacti安装配置使用详结