cacti系列之安装篇 LNMP+cacti+spine (一)
大纲一、cacti简述
二、配置nginx、php、mysql
三、cacti + spine 搭建
一、简述
Cacti基于SNMP采集数据源,通过rrdtool储存数据并绘图呈现给用户。SNMP获取的数据源为.rrd文件,存储在cacti目录下的rra目录。
工作流程如图:
http://s4.运维网.com/wyfs02/M02/80/32/wKiom1c6vJWja0XgAABXDtGTAsA133.png
二、配置nginx、php、mysql(忽略LNMP环境部署过程)
1.配置nginx
#在nginx中加入一个server
$vim /usr/local/nginx/conf/nginx.conf
server {
listen 8888;
access_loglog/access_catic.log main;
location / {
index index.html index.php;
root/usr/local/cacti/;
}
location ~.*\.(php|php5)?${
root /usr/local/cacti/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME /usr/local/cacti/$fastcgi_script_name;
include fastcgi_params;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
}
#添加完成后,测试配置文件语法是否正常
$/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#创建cacti日志文件
$touch /usr/local/nginx/log/access_cacti.log
#更改nginx及子目录的属主属组
$chown -R nginx.nginx /usr/local/nginx/
#启动nginx
$/usr/local/nginx/sbin/nginx
#查看nginx启动的端口
$netstat -ntlp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 29641/nginx
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 29641/nginx 2.配置php:
#更改php.ini时区
$vim /etc/php.ini
date.timezone =Asia/Shanghai
#更改php-fpm的属主属组
$vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
#启动php-fpm并查看其端口状态
$service php-fpm start
Starting php-fpm:
$netstat -ntlp | grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3773/php-fpm
#新建session目录并更改目录属主属组及权限(/etc/php-fpm.d/www.conf中有定义session路径)
$mkdir -p /var/lib/php/session
$chown nginx.nginx /var/lib/php/session
$chmod -R 770 /var/lib/php/session 3.创建并导入cacti数据库及用户密码授权
mysql> create database cacti;
mysql> use cacti;
mysql> \. /usr/local/cacti/cacti.sql
mysql> create user 'cactiuser'@'192.168.%.%' identified by 'cactipasswd';
mysql> grant all on cacti.* to 'cactiuser'@'192.168.%.%' identified by 'cactipasswd';
mysql> flush privileges; 三、cacti+spine搭建
#1.安装snmp
$yum -y install net-snmp net-snmp-utils net-snmp-devel
#更改团体名和ObjectID(团体名可保持默认):
# vim /etc/snmp/snmpd.conf
#修改前一:
com2sec notConfigUserdefault public
#修改后一:
com2sec notConfigUserdefault TEST
#修改前二:
view systemview included .1.3.6.1.2.1.1
#修改后二:
view systemview included .1
#启动snmpd服务:
$service snmpd start
Starting snmpd:
#SNMP数据采集测试:
$snmpnetstat -v 2c -c TEST -Cna -Cp tcp 127.0.0.1
Active Internet (tcp) Connections (including servers)
Proto Local Address Remote Address (state)
tcp *.22 *.* LISTEN
tcp *.80 *.* LISTEN
tcp *.111 *.* LISTEN
tcp *.23177 *.* LISTEN
tcp 127.0.0.1.199 *.* LISTEN
tcp 192.168.6.213.22 192.168.4.95.50605 ESTABLISHED
tcp 192.168.6.213.22 192.168.4.95.55708 ESTABLISHED#2.安装rrdtool:
$yum -y install rrdtool rrdtool-devel#3.安装cacti
$wget http://www.cacti.net/downloads/cacti-0.8.8h.tar.gz
$tar zxvf cacti-0.8.8h.tar.gz -C /usr/local/
$cd /usr/local/
$mv cacti-0.8.8h/ cacti /
$chown -R nginx.nginx cacti/
#修改cacti配置文件:
$vim cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "192.168.6.213";
$database_username = "cactiuser";
$database_password = "cactipasswd";
$database_port = "3306";
$database_ssl = false;#4.安装spine
$wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8h.tar.gz
$tar zxvf cacti-spine-0.8.8h.tar.gz
$./configure --prefix=/usr/local/spine/
$make && make install
$chown -R nginx.nginx /usr/local/spine/
$cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
#修改spine配置文件:
$vim /usr/local/spine/etc/spine.conf
DB_Host 192.168.6.213
DB_Database cacti
DB_User cactiuser
DB_Pass cactipasswd
DB_Port 3306
#测试spine是否安装成功:
$spine/bin/spine -C spine/etc/spine.conf
SPINE: Using spine config file
SPINE: Version 0.8.8h starting
SPINE: Time: 0.1398 s, Threads: 5, Hosts: 2#5.cacti每分钟拉取数据交付rrdtool绘图。
$crontab -unginx -l
*/1 * * * * /usr/bin/php /usr/local/cacti/poller.php &> /dev/null
#获取数据测试:
$su nginx
$php /usr/local/cacti/poller.php --force
OK u:0.00 s:0.01 r:0.11
OK u:0.00 s:0.01 r:0.15
OK u:0.00 s:0.01 r:0.18
OK u:0.00 s:0.01 r:0.23
OK u:0.00 s:0.01 r:0.30
05/17/2016 02:05:57 PM - SYSTEM STATS: Time:0.4624 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5#6.web界面配置篇
#a.打开浏览器,输入cacti服务器IP地址及端口(默认80,无需输入),进入安装界面,如下图,点击Next:http://s5.运维网.com/wyfs02/M00/80/30/wKioL1c6xsST2WcbAACYkHTtRoI115.png
#b.根据实际情况选择安装或升级,我们是全新安装,故选择Nex Install,然后Next:http://s5.运维网.com/wyfs02/M01/80/32/wKiom1c6xhjSMZwwAABbgehC6_c453.png
#c.检查所有路径配置,配置正确会提示OK,用绿色字体标出;一般无需更改,我们直接Finish:http://s3.运维网.com/wyfs02/M01/80/32/wKiom1c6xkGxHxdrAAEC-_NGm0k951.png
#d.提示用户名密码,默认都为admin。输入后点击Login:http://s1.运维网.com/wyfs02/M02/80/30/wKioL1c6x06Du_jhAACkPzaKZMs341.png
#e.此时会提示强制更改密码,输入新密码后Save,即登陆cacti管理界面http://s1.运维网.com/wyfs02/M00/80/32/wKiom1c6xqiz_IeAAAC8zNUupJ8877.png
#f.进入“console-configuration-settings-General“,找到SNMP Defaults,更改SNMP Version
为Version 2;更改SNMP Community为你设置的团体名,默认为public。http://s1.运维网.com/wyfs02/M00/80/30/wKioL1c6x8OBZGrAAAGDIpPmV3s222.png
#g.进入“console-configuration-settings-Pathes“下,找到Alternate Poller Path,在Spine
Poller File Path后填入你安装spine时的路径并保存,正常则会提示"OK:FILE FOUND"http://s5.运维网.com/wyfs02/M01/80/32/wKiom1c6xwOxVolUAAAypGeChF4006.png
#h.进入“console-configuration-settings-Poller”,更改Poller Type为spine(默认为cmd.php),修改Poller Interval、Cron Interval为你设置的任务计划时间并保存。http://s2.运维网.com/wyfs02/M02/80/32/wKiom1c6xyTjeDyZAAEKPrMqbjg699.png
#i.到此,cacti安装已完成。cacti默认有把本机加入监控,可查看图形显示效果。点击管理界面最左上角的“graphs-Default Tree-Host:Localhost":http://s4.运维网.com/wyfs02/M02/80/30/wKioL1c6yEKSpZx4AABip10gZiQ187.png
http://s5.运维网.com/wyfs02/M02/80/32/wKiom1c6x2aDEuxRAAA-uSWai6Y623.png
页:
[1]