标签:cacti 安装 lnmp nginx+cacti spine php mysql snmp
大纲
一、cacti简述
二、配置nginx、php、mysql
三、cacti + spine 搭建
一、简述
Cacti基于SNMP采集数据源,通过rrdtool储存数据并绘图呈现给用户。SNMP获取的数据源为.rrd文件,存储在cacti目录下的rra目录。
工作流程如图:
二、配置nginx、php、mysql(忽略LNMP环境部署过程)
1.配置nginx
#在nginx中加入一个server [root@jpushoa_6.213 cacti-spine-0.8.8h]$vim /usr/local/nginx/conf/nginx.conf server { listen 8888; access_log log/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_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/cacti/$fastcgi_script_name; include fastcgi_params; } location = /favicon.ico { log_not_found off; access_log off; } } #添加完成后,测试配置文件语法是否正常 [root@jpushoa_6.213 cacti-spine-0.8.8h]$/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日志文件 [root@jpushoa_6.213 cacti-spine-0.8.8h]$touch /usr/local/nginx/log/access_cacti.log #更改nginx及子目录的属主属组 [root@jpushoa_6.213 cacti-spine-0.8.8h]$chown -R nginx.nginx /usr/local/nginx/ #启动nginx [root@jpushoa_6.213 cacti-spine-0.8.8h]$/usr/local/nginx/sbin/nginx #查看nginx启动的端口 [root@jpushoa_6.213 cacti-spine-0.8.8h]$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时区 [root@jpushoa_6.213 cacti-spine-0.8.8h]$vim /etc/php.ini date.timezone =Asia/Shanghai #更改php-fpm的属主属组 [root@jpushoa_6.213 conf]$vim /etc/php-fpm.d/www.conf user = nginx group = nginx #启动php-fpm并查看其端口状态 [root@jpushoa_6.213 conf]$service php-fpm start Starting php-fpm: [ OK ] [root@jpushoa_6.213 conf]$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路径) [root@jpushoa_6.213 local]$mkdir -p /var/lib/php/session [root@jpushoa_6.213 local]$chown nginx.nginx /var/lib/php/session [root@jpushoa_6.213 local]$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 [root@jpushoa_6.213 ~]$yum -y install net-snmp net-snmp-utils net-snmp-devel #更改团体名和ObjectID(团体名可保持默认): [root@cacti ~]# vim /etc/snmp/snmpd.conf #修改前一: com2sec notConfigUser default public #修改后一: com2sec notConfigUser default TEST #修改前二: view systemview included .1.3.6.1.2.1.1 #修改后二: view systemview included .1 #启动snmpd服务: [root@jpushoa_6.213 ~]$service snmpd start Starting snmpd: [ OK ] #SNMP数据采集测试: [root@jpushoa_6.213 ~]$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: [root@jpushoa_6.213 ~]$yum -y install rrdtool rrdtool-devel
#3.安装cacti [root@jpushoa_6.213 data]$wget http://www.cacti.net/downloads/cacti-0.8.8h.tar.gz [root@jpushoa_6.213 ~]$tar zxvf cacti-0.8.8h.tar.gz -C /usr/local/ [root@jpushoa_6.213 ~]$cd /usr/local/ [root@jpushoa_6.213 local]$mv cacti-0.8.8h/ cacti / [root@jpushoa_6.213 local]$chown -R nginx.nginx cacti/ #修改cacti配置文件: [root@jpushoa_6.213 local]$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 [root@jpushoa_6.213]$wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8h.tar.gz [root@jpushoa_6.213 ~]$tar zxvf cacti-spine-0.8.8h.tar.gz [root@jpushoa_6.213 cacti-spine-0.8.8h]$./configure --prefix=/usr/local/spine/ [root@jpushoa_6.213 cacti-spine-0.8.8h]$make && make install [root@jpushoa_6.213 cacti-spine-0.8.8h]$chown -R nginx.nginx /usr/local/spine/ [root@jpushoa_6.213 cacti-spine-0.8.8h]$cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf #修改spine配置文件: [root@jpushoa_6.213 cacti-spine-0.8.8h]$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是否安装成功: [root@jpushoa_6.213 local]$spine/bin/spine -C spine/etc/spine.conf SPINE: Using spine config file [spine/etc/spine.conf] SPINE: Version 0.8.8h starting SPINE: Time: 0.1398 s, Threads: 5, Hosts: 2
#5.cacti每分钟拉取数据交付rrdtool绘图。 [root@jpushoa_6.213 local]$crontab -unginx -l */1 * * * * /usr/bin/php /usr/local/cacti/poller.php &> /dev/null #获取数据测试: [root@jpushoa_6.213 ~]$su nginx [nginx@jpushoa_6.213 root]$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:
#b.根据实际情况选择安装或升级,我们是全新安装,故选择Nex Install,然后Next:
#c.检查所有路径配置,配置正确会提示OK,用绿色字体标出;一般无需更改,我们直接Finish:
#d.提示用户名密码,默认都为admin。输入后点击Login:
#e.此时会提示强制更改密码,输入新密码后Save,即登陆cacti管理界面
#f.进入“console-configuration-settings-General“,找到SNMP Defaults,更改SNMP Version 为Version 2;更改SNMP Community为你设置的团体名,默认为public。
#g.进入“console-configuration-settings-Pathes“下,找到Alternate Poller Path,在Spine Poller File Path后填入你安装spine时的路径并保存,正常则会提示"OK:FILE FOUND"
#h.进入“console-configuration-settings-Poller”,更改Poller Type为spine(默认为cmd.php),修改Poller Interval、Cron Interval为你设置的任务计划时间并保存。
#i.到此,cacti安装已完成。cacti默认有把本机加入监控,可查看图形显示效果。点击管理界面最左上角的“graphs-Default Tree-Host:Localhost":
本文出自 “吾言” 博客,请务必保留此出处http://wuyanc.blog.51cto.com/11569260/1774350
cacti系列之安装篇 LNMP+cacti+spine (一)
标签:cacti 安装 lnmp nginx+cacti spine php mysql snmp
原文地址:http://wuyanc.blog.51cto.com/11569260/1774350