(一)Cacti
*** 需要先安装Apache + MySQL + PHP(php-snmp)
(1)安装Net-SNMP
# yum -y install net-snmp
# cp -p /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.org
# vi /etc/snmp/snmpd.conf
引用
# sec.name source community
#com2sec notConfigUser default public ←注释掉
com2sec local localhost private ←
com2sec mynetwork 192.168.21.0/24 public ←
# groupName securityModel securityName
#group notConfigGroup v1c notConfigUser ←注释掉
#group notConfigGroup v2c notConfigUser ←注释掉
group MyROGroup v1 local ←
group MyROGroup v2c local ←
group MyROGroup v1 mynetwork ←
group MyROGroup v2c mynetwork ←
# Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
#view systemview included .1.3.6.1.2.1.1 ←注释掉
#view systemview included .1.3.6.1.2.1.25.1.1 ←注释掉
view all included .1 80 ←
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
#access notConfigGroup "" any noauth exact systemview none none ←注释掉
access MyROGroup "" any noauth exact all none none ←
access MyRWGroup "" any noauth exact all all none ←
# Check the / partition and make sure it contains at least 10 megs.
#disk / 10000
disk / 10000 ←
# /etc/init.d/snmpd start
(2)安装RRDtool & cacti
# vi /etc/yum.repos.d/CentOS-Base.repo
引用
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://ftp.riken.jp/Linux/dag/redhat/el$releasever/en/$basearch/dag/
gpgcheck=1
enabled=0
# wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
# rpm --import RPM-GPG-KEY.dag.txt
# yum -y install --enablerepo=dag rrdtool
# yum -y install --enablerepo=dag cacti
(3)设置
创建数据库
# mysql -u root -p
引用
mysql> create database cacti;
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'your-password-here';
mysql> FLUSH privileges;
mysql> quit;
# rpm -ql cacti | grep cacti.sql
/usr/share/doc/cacti-0.8.8b/cacti.sql
# mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql
设置cacti
# vi /etc/cacti/db.php
引用
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "your-password-here";
$database_port = "3306";
$database_ssl = false;
设置Apache
# vi /etc/httpd/conf.d/cacti.conf
引用
Alias /cacti/ /var/www/cacti/
<Directory /var/www/cacti/>
DirectoryIndex index.php
Options -Indexes
AllowOverride all
order deny,allow
deny from all
allow from 127.0.0.1
allow from 192.168.1.0/24 ←
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc on
php_flag track_vars on
</Directory>
# /etc/init.d/httpd restart
设置自动收集数据
# vi /etc/cron.d/cacti
引用
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
(4)确认
http://<youripaddress>/cacti/
第一次需要按照向导设置。
(二)Nagios
# yum -y install gd-devel
# useradd -d /usr/local/nagios/ -M nagios
安装Nagios
# cd /usr/local/src
# wget http://jaist.dl.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz -O nagios-4.0.8.tar.gz
# tar zxvf nagios-4.0.8.tar.gz
# cd nagios-4.0.8
# ./configure && make all && make fullinstall && make install-config
安装插件
# cd /usr/local/src
# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
# tar zxvf nagios-plugins-2.0.3.tar.gz
# cd nagios-plugins-2.0.3
# ./configure && make && make install
# cp contrib/check_mem.pl /usr/local/nagios/libexec/
# vi /usr/local/nagios/libexec/check_mem.pl
引用
$command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`;
↓
$command_line = `free | head -3 | tail -1 | awk '{print \$3,\$4}'`; ←
# chmod +x /usr/local/nagios/libexec/check_mem.pl
设置Nagios
# vi /usr/local/nagios/etc/nagios.cfg
引用
cfg_dir=/usr/local/nagios/etc/servers ←去掉注释
date_format=iso8601 ←日期格式:YYYY-MM-DD HH:MM:SS
# vi /usr/local/nagios/etc/cgi.cfg
引用
ttf_file=/usr/local/nagios/etc/font/font.ttf ←去掉注释
# mkdir /usr/local/nagios/etc/servers
# vi /usr/local/nagios/etc/objects/contacts.cfg
引用
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email <email> ←管理员邮件地址
}
# vi /usr/local/nagios/etc/objects/localhost.cfg
引用
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 1 ←
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 1 ←
}
# vi /usr/local/nagios/etc/objects/commands.cfg
# usermod -G nagios apache
# vi /etc/httpd/conf.d/nagios.conf
# /etc/rc.d/init.d/httpd reload
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# /etc/rc.d/init.d/nagios start