NAGIOS+CACTI服务器安装
Nagios服务端安装
============================
1.解决perl插件编译安装问题
echo 'export LC_ALL=C' >> /etc/profile
source /etc/profile
echo $LC_ALL
2.安装必须软件
yum -y install gcc glibc glibc-common gd gd-devel httpd php* mysql*
3.添加nagios和httpd用户
/usr/sbin/useradd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
groups nagios
groups apache
4.启动lamp服务
vim /etc/httpd/conf/httpd.conf +402
/etc/init.d/httpd start
chkconfig httpd --level 3 on
vim /etc/httpd/conf/httpd.conf +276
#注意修改ServerName 127.0.0.1:80避免apache启动报错
5.编译安装nagios
cd /soft
wget http://soft.local.com/nagios-3.5.1.tar.gz
tar zxf nagios-3.5.1.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
6.安装nagios的web配置文件和建立登录用户
cd /soft/nagios
make install-webconf
#在nagios的软件解压目录里面执行
7.修改nagios的登录密码
htpasswd -cb /usr/local/nagios/etc/htpasswd.users yjb007 123456
8.启用sendmail服务
yum -y install sendmail
/etc/init.d/sendmail start
chkconfig sendmail --level 3 on
9.安装nagios服务端插件
yum -y install perl-CPAN
cd /soft
wget http://soft.local.com/nagios-plugins-1.4.16.tar.gz
tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make
make install
10.开机启动nagios
chkconfig --level 3 nagios on
11.检查nagios的配置文件语法
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios checkconfig
vim /etc/init.d/nagios +177
12.启动nagios
/etc/init.d/nagios start
ps -ef | grep nagios
13.服务端安装nrpe,因为nagios是主动查询报警
cd /soft
wget http://soft.local.com/nrpe-2.12.tar.gz
tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
ll /usr/local/nagios/libexec/check_nrpe
14.配置nagios.cfg
-------------------------------------
vim /usr/local/nagios/etc/nagios.cfg +34
cfg_dir=/usr/local/nagios/etc/objects/services
#目录下面的.cfg文件全部生效
#注释掉所有cfg_file=
15.修改vim ../cgi.cfg
sed -i s#nagiosadmin#yjb007#g /usr/local/nagios/etc/cgi.cfg
16.重载nagios
/etc/init.d/nagios reload
17.Nagios出图配置:PNP出图 -服务器端
---------------------------------------------
yum -y install zlib zlib-devel freetype freetype-devel gd gd-devel cairo pango
cd /soft
wget http://soft.local.com/libart_lgpl-2.3.17.tar.gz
tar zxf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
./configure
make
make install
/bin/cp -r /usr/local/include/libart-2.0/ /usr/include/
cd /soft
wget http://soft.local.com/rrdtool-1.2.14.tar.gz
tar zxf rrdtool-1.2.14.tar.gz
cd rrdtool-1.2.14
./configure --prefix=/usr/local/rrdtool --disable-python --disable-tcl
make
make install
ll /usr/local/rrdtool/bin/
cd /soft
wget http://soft.local.com/pnp-0.4.14.tar.gz
tar zxf pnp-0.4.14.tar.gz
cd pnp-0.4.14
./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata=/usr/local/nagios/share/perfdata
make all
make install
make install-config
make install-init
#检测安装成功与否,出图数据脚本,安装完毕
ll /usr/local/nagios/libexec/process_perfdata.pl
18.配置nagios出图配置
--------------------------------------------
vim /usr/local/nagios/etc/nagios.cfg +831
process_performance_data=1
#修改成1,存储监控数据
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
#将这两行取消注释
19.图形界面地址
http://192.168.1.18/nagios/pnp/index.php
CACTI安装配置
----------------------------------------------------------
客户端安装snmp
1.yum -y install net-snmp*
ll /etc/snmp/snmpd.conf
2.默认配置文件
cat >/etc/snmp/snmpd.conf <<EOF
com2sec local localhost public
com2sec mynetwork 10.0.0.0/24 public
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation etiantian.org
syscontact Me <[email protected]>
proc mountd
proc ntalkd 4
proc sendmail 10 1
proc httpd 10 1
exec echotest /bin/echo hello world
exec disk_used_shell /bin/sh /root/current_disk_used.sh
exec httpd_proc /bin/sh /root/current_httpd_proc.sh
disk / 10000
disk /boot 10000
load 12 14 14
EOF
##cat >/etc/snmp/snmpd.conf <<EOF是先”cat >/etc/snmp/snmpd.conf“清空
##然后/etc/snmp/snmpd.conf <<EOF追加
3./etc/init.d/snmpd start
#启动snmp,TCP:161
服务器端的安装
1.安装libart_lgpl-2.3.17.tar.gz
unzip cacti_tools.tar.gz
tar zxf cacti_tools.tar.gz
cd cacti_tools
tar zxf libart_lgpl-2.3.17.tar.gz
./configure
make
make install
/bin/cp -r /usr/local/include/libart-2.0 /usr/include/
2.安装rrdtool
tar zxvf cgilib-0.5.tar.gz
cd cgilib-0.5
make
cp libcgi.a /usr/local/lib
cp cgi.h /usr/include
yum -y install pango-devel* cairo-devel* gcc glibc glibc-common cairo pango zlib zlib-devel freetype \
freetype-devel gd gd-devel libart_lgpl-devel
cd /root/cacti_tools/rrdtool-1.2.30
./configure
make
make install
ln -s /usr/local/rrdtool-1.2.30/bin/rrdtool /usr/local/bin/rrdtool
4.安装配置一些必要软件
yum -y install mysql* httpd* php*
#若报错,则加参数--skip-broken
vim /etc/httpd/conf/httpd.conf +276
vim /etc/httpd/conf/httpd.conf +402
egrep "127.0.0.1|index.php" /etc/httpd/conf/httpd.conf
#修改httpd的默认配置文件,增加主机解析和默认首页index.php
echo -e "<?php \nphpinfo();\n?>" > /var/www/html/index.php
#建立php测试文件
5.启动数据库
/etc/init.d/mysqld start
6.建立cacti用的数据库账号
mysql> grant all on cacti.* to cactiuser@localhost identified by "cactiuser";
mysql> flush privileges;
mysql> create database cacti;
mysql> select user,host from mysql.user;
##CACTI软件的配置密码默认是cactiuser
7.安装CACTI
cd /root/cacti_tools/cacti-0.8.8a
tar zxf cacti-0.8.8a.tar.gz
cd cacti-0.8.8a
mysql cacti < cacti.sql
#将 cacti.sql 恢复到数据库了, cacti.sql 在cacti安装里带的
8.修改cacti连接数据库的配置文件,26-32行
[root@C05 cacti-0.8.8a]# vim include/config.php +26
9.授权apache对CACTI目录下的log/ rra/有权限
chown -R apache log/ rra/
10.将cacti的整个目录拷贝到网站目录下
/bin/mv ../cacti-0.8.8a /var/www/html/cacti
ll /var/www/html/cacti/
cd /var/www/html/cacti/
chown -R apache.apache /var/www/html/cacti
11.测试定时收集数据poller.php工作正常并加入到定时任务
setenforce 0
chmod 755 /var/www/html/cacti/poller.php
/usr/sbin/ntpdate pool.ntp.org
/usr/bin/php /var/www/html/cacti/poller.php
echo "*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1" >> /var/spool/cron/root
crontab -l
12.web页面开始配置cacti
http://192.168.1.15/cacti
#注意RRDTOOl版本和snmp版本
默认用户名和密码是admin/admin
13.配置
---------------------
|-- cacti_graph_template_snmp_get_netstat_connection_oldboytrainning.xml
|-- get_netstat_tcp_oldboytrainning.pl
----------------------
#一个脚本应该包括两个文件
#XML脚本通过perl调用.pl脚本
perl get_netstat_tcp_oldboytrainning.pl 192.168.1.16 2c public 161 500
#手动测试看能否出数据
#导入模板