环境为centos+LNMP
——————为PHP增加snmp模块——————
使用php -m #查看是否安装了snmp 模块,也可以使用php探针查看
如果没有安装,使用无需重新编译PHP的方法安装:
cd /root/lnmp0.7/php-5.2.17/ext/snmp #php源码中自带,初次编译安装是可使用with-snmp安装
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
编辑/usr/local/php/etc/php.ini 添加:extension = "snmp.so"
重启php-fpm或apache
/etc/init.d/php-fpm restart
/etc/init.d/httpd -k restart
再执行一下:ldconfig ,重新加载一些链接库。
如果编译失败(configure: error: snmp.h not found. Check your SNMP installation.)
运行:yum install net-snmp net-snmp-devel
——————cacti还需安装rrdtool用来保存数据及绘图形的工具——————
官网:http://oss.oetiker.ch/rrdtool/pub/?M=D
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz
gunzip -c rrdtool-1.4.7.tar.gz | tar xf -
cd rrdtool-1.4.7
./configure --prefix=$INSTALL_DIR && make && make install #默认安装目录为:/opt/rrdtool-1.4.7/bin/rrdtool
避便编译安装是产生依赖错误,安装以下依赖组件:
yum install cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel
——————下载安装cacti插件版——————
官网:http://www.cacti.net/index.php
cd /home/wwwroot
wget http://www.cacti.net/downloads/cacti-0.8.7i-PIA-3.1.zip
tar zxvf cacti-0.8.7i-PIA-3.1.zip
mv cacti-0.8.7i-PIA-3.1 cacti
cd /home/wwwroot/cacti
mysqladmin --user=root create cacti -p #输入mysql的root密码后建立名为cacti的数据库
mysql cacti < cacti.sql -p #导入cacti目录的模板数据库
shell> mysql --user=root mysql -p #登录mysql
mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'somepassword'; #新建用户并赋予权限
mysql> flush privileges;
Edit include/config.php and specify the database type, name, host, user and password for your Cacti configuration.
#编辑include目录下的config.php编辑相应项目
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cacti";
Set the appropriate permissions on cacti's directories for graph/log generation. You should execute these commands from inside cacti's directory to change the permissions.#正确设置目录权限
shell> chown -R www rra/ log/
增加入一个计划任务,使得 cacti 每五分钟生成一个监控图表。
crontab -e
#加入如下内容。注意poller.php的路径
*/5 * * * * /usr/bin/php /home/wwwroot/cacti-0.8.7i/poller.php > /dev/null 2>&1
访问:http://ip/cacti 访问进行安装,初始账号密码为admin:admin。
——————监控本机设置——————
vi /etc/snmp/snmp.conf
#将下边这行中的default
com2secnotConfigUser default public
#改为127.0.0.1
com2secnotConfigUser 127.0.0.1 public
#将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
#改为all
access notConfigGroup "" any noauth exact all none none
#将下边这行的注释“#”号去掉
#view all included .1 80
#重启snmpd服务
service snmpd restart
——————监控其它机器——————
#在被监控的linux主机上安装net-snmp
yum install net-snmp
vi /etc/snmp/snmpd.conf
#更改以下部分
#将下边这行中的default
com2secnotConfigUser default public
#改为10.0.0.52(cacti)服务器的地址)
com2secnotConfigUser 10.0.0.52 public
#将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
#改为all
access notConfigGroup "" any noauth exact all none none
#将下边这行的注释“#”号去掉
#view all included .1 80
service snmpd restart
注:CentOS自带了SNMP,只不过默认没有开启服务
设置SNMP开机自动启动
成功配置完毕,建议将SNMP设置为开机自动启动(或取消)。
(1)设置开机自动启动,在SSH中输入以下命令
chkconfig snmpd on
(2)关闭开机自动启动,在SSH中输入以下命令
chkconfig snmpd off
——————使用最新V3验证方式——————
添加v3验证方式
LinuxVPS学习者建议您使用v3这种最新的验证方式。早期的Linux发行版中默认的SNMP可能不支持v3,需要自己手工编译其它支持v3的SNMP(如Net-SNMP 5以上版本,CentOS 5.5测试通过。)
同样,在snmpd.conf中添加以下内容
rouser kwxgd auth
createUser kwxgd MD5 mypassword
第一行“rouser”用于设定只读帐号的类型,“kwxgd”设定用户名,“auth”指明连接时需要验证。
第二行的意思是创建一个名为“kwxgd”的用户,密码为“mypassword”,并用MD5进行加密传输。
注意,创建用户的密码要8个字节以上,否则设置会失败。而且一旦snmpd启动后,出于安全考虑,以上两行配置会被snmpd自动删除,但它会将这些配置以密文的形式记录在其它文件中,重启snmpd不需要再次重复添加以上内容,除非你希望创建新的用户(或覆盖帐户,如修改帐户密码密码)。
——————使用iptable进一步增强安全性——————
SNMP代理程序默认监控在udp161端口,为你的iptables增加以下规则:
iptables -A INPUT -i eth0 -p udp -s 60.195.249.83 --dport 161 -j ACCEPT
iptables -A INPUT -i eth0 -p udp -s 60.195.252.107 --dport 161 -j ACCEPT
iptables -A INPUT -i eth0 -p udp -s 60.195.252.110 --dport 161 -j ACCEPT以上设置中假设服务器外网网卡是eth0,你可以根据实际情况来修改。
这样一来,只有监控宝的专用监控器可以发送UDP数据包到你的服务器的161端口,与SNMP代理程序进行通信。
——————安装插件增强功能——————
官方插件地址:http://docs.cacti.net/plugins
安装:wget http://docs.cacti.net/_media/plugin:settings-v0.71-1.tgz #这里以settings为例,配合插件thold可以起到邮件警告的作用
mv plugin:settings-v0.71-1.tgz settings-v0.71-1.tgz
tar zxvf settings-v0.71-1.tgz
mv settings /home/wwwroot/cacti/plugins
回到网页界面:
user manager —admin—Realm Permissions 激活Plugin Management 保存(save)
左侧setting一栏里即多出Plugin Management 一栏,进入后可以安装激活之前复制到插件目录的插件
参考:
Cacti Manual Installing Under Unix
https://bbs.zephyrxt.com/thread-9412-1-1.html
rrdbuild - Instructions for building RRDtool
https://bbs.zephyrxt.com/thread-9413-1-1.html
CentOS+Cacti安装配置
https://bbs.zephyrxt.com/thread-9415-1-1.html
Cacti安装配置文档(安装插件)
https://bbs.zephyrxt.com/thread-9414-1-1.html
configure错误列表供参考
https://bbs.zephyrxt.com/thread-9416-1-1.html
手动安装 ImageMagick
https://bbs.zephyrxt.com/thread-6191-1-1.html
CentOS开启自带SNMP实现服务器性能监控(iptable设置)
https://bbs.zephyrxt.com/thread-6465-1-1.html
用php+snmp实现服务器监控程序
https://bbs.zephyrxt.com/thread-9411-1-1.html