一、基础环境配置
- 系统 centos 6.5 x64
- lnmp 配置参考 使用一键安装即可
- yum安装
yum install gcc rrdtool net-snmp-devel net-snmp net-snmp-utils net-snmp-devel
二、配置snmp
- 配置文件(/etc/snmp/snmpd.conf)
syslocation CN
syscontact no
com2sec notConfigUser localhost public
com2sec notConfigUser 127.0.0.1 public
extend .1.3.6.1.4.1.2312.100 tcpCurrStat /etc/snmp/get_tcp_state
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access notConfigGroup "" any noauth exact all none none
view all included .1 80
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
proc mountd
proc ntalkd 4
proc sendmail 10 1
exec echotest /bin/echo hello world
disk / 10000
load 12 14 14
view all included .1 80
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
- 监控tcp连接状态脚本(/etc/snmp/gettcpstate)
#!/bin/sh
tmp="/dev/shm/.tcpstat-tmp"
netstat -ant|awk '/^tcp/ {print $6}' > $tmp
for state in 'ESTABLISHED' 'CLOSE_WAIT' 'TIME_WAIT' 'SYN_SENT' 'SYN_RCVD' 'LAST_ACK' 'FIN_WAIT2' 'FIN_WAIT1'
do
echo "$(cat $tmp|grep $state|wc -l)"
done
启动snmp并设置开机自启动
chkconfig snmpd on & service snmpd start
查看是否启动并测试
netstat -an |grep 161
snmpwalk -v 2c -c public localhost system 查看系统信息
三、安装配置cacti
下载最新版本(http://www.cacti.net/downloads/)
安装cacti主程序
tar xzf cacti-0.8.8d.tar.gz && mv cacti-0.8.8d /data/www/cacti/
创建cacti数据库并导入SQL
mysql -uroot –p #输入你的密码进入数据库
create database cacti; #创建数据库
grant all on cacti.* to cacti@'localhost' identified by "123456"; #创建用户并授权
flush privileges; #刷新权限
exit
mysql -uroot –p cacti < /data/www/cacti/cacti.sql #导入数据库
修改cacti/目录权限
chown www.www -R /data/www/cacti
修改Cacti配置文件config.php
vim /data/www/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;
添加rrdtool计划任务
crontab -e -u www
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
nginx 配置虚拟主机 (/usr/local/nginx/conf/vhosts/cacti.imdst.com)
server
{
listen 80;
server_name cacti.imdst.com;
index index.php index.htm index.html;
root /data/www/cacti;
location ~ .*\.(php|php5)?$
{
# fastcgi_pass 127.0.0.1:9000; # 注意检查自己配置的fpm模式
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 15d;
}
location ~ .*\.(js|css)?$
{
expires 1d;
}
}
- 重启nginx,初始化安装cacti
service nginx reload
or/usr/local/nginx/sbin/nginx -s reload
http://cacti.imdst.com/install/
- 点Next进入下一步
- 再Next下一步
- 全部为绿色无异常再进入下一步
- 点Next进入下一步
- 结束后登陆
- 初始密码为 admin admin
- 第一次登陆要修改密码
- 初始密码为 admin admin
到此为止cacti安装完成,默认添加了本机的监控,查看Graphs页是否生成图形