LNMP+Cacti+Nagios+ndo2+Npc
Cacti 多用于图形监测系统性能 负载等
Nagios 多用于报警
专注于为中小企业提供网站制作、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业平坝免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
Cacti: 是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.
Nagios:是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知.
Npc: 是一个cacti的插件.用于讲 Cacti和Nagios整合.
注意如下几点
1.Cacti 需要 LNMP 或者 LAMP 作为平台
2.Nagios 需要web服务器支持cgi
3.Cacti 是通过 net-snmp 来采集数据的. 客户机需要安装net-snmp
4.本文不过多的介绍配置文件和软件使用方法 只标注管简单 多去学习才能更好的掌握各种知识
本文以 Centos 5.4 作为平台来搭建
LNMP 环境如下
mysql 5.5.27
php 5.4.6
nginx1.2.3
Lnmp 安装方法:
http://wangshuai1987.blog.51cto.com/3080273/1294909
让nginx支持cgi 的方法
http://wangshuai1987.blog.51cto.com/3080273/1341415
##############################################################################
注意,此处只标记. 不要使用该部分命令. 是为了整理看着清爽.具体安装步骤,着重参考安装正文
Cacti版本:cacti-0.8.8a.tar.gz
Nagios版本:nagios-3.4.1.tar.gz
nagios-plugins-1.4.16.tar.gz
需要安装的软件包
Nagios:
yum install -y gd gd-devel xinetd libart_lgpl
Cacti:
yum -y install libart_lgpl-devel libpng-devel freetype-devel libart_lgpl-devel fonts-chinese cairo-devel pango-devel
先来几张图,把关键位置标注出来. 从正文开始 大篇幅安装步骤 不单独出图
下面的几个图 只是关键点
New Graphs:新建图形
Graph Management:图形管理
Data Sources:数据源
Devices:添加主机活设备在这
Plugin Management:插件管理
System Utilities: 如果不出图 点这个菜单 把 view xxxx cache 都点一次 清理下缓存
几个设置的时候要注意的地方
cacti 优化参考
所有参数 不可全抄 要根据实际情况修改
##################################################
################# 安装正文 #####################
##################################################
# 安装cacti需要的包
yum install -y gd gd-devel xinetd libart_lgpl
# 建立nagios用户 用于维护nagios
/usr/sbin/useradd nagios
#passwd nagios
# 建立nagioscmd组 用于执行cgi程序 和其他nagios程序
/usr/sbin/groupadd nagcmd
# 将nagios用户加到nagcmd组
/usr/sbin/usermod -a -G nagcmd nagios
# 将web用户加到nagcmd组
/usr/sbin/usermod -a -G nagcmd web
# 将www用户加到nagcmd组
/usr/sbin/usermod -a -G nagcmd www
# 将nagios用户加到www组
/usr/sbin/usermod -a -G www nagios
# 下载需要的软件包
# 官方下载页面 软件 和 插件
# http://www.nagios.org/download/core/thanks/
# http://www.nagios.org/download/plugins/
# 下载软件和插件包
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
# 解压
tar zxf nagios-3.4.1.tar.gz
tar zxf nagios-plugins-1.4.16.tar.gz
# 开始进行便已安装
cd nagios
./configure --prefix=/soft/nagios-3.4.1 --with-command-group=nagcmd
make all && make install && make install-init && make install-config && make install-commandmode
cd ../
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /soft/nagios-3.4.1/var/rw
chmod g+s /soft/nagios-3.4.1/var/rw
cd nagios-plugins-1.4.16
./configure --prefix=/soft/nagios-3.4.1 --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
cd ../
###########
如果报错:
make: *** No rule to make target `/usr/lib64/perl5/CORE/config.h', needed by `Makefile'. Stop.
yum install -y perl-devel.x86_64
# nagios 是由perl编写的.所以 需要如下perl模块
# 提供两种安装方式. 推荐手动安装
A)通过CPAN 来安装
#perl -MCPAN -e shell
cpan> install Net::SNMP
###########
B) 手工安装
# 首先去官方网站 http://www.cpan.org 下载以下几个模块
Crypt::DES
Digest::MD5
Digest::SHA1
Digest::HMAC
Net::SNMP
wget http://search.cpan.org/CPAN/authors/id/D/DP/DPARIS/Crypt-DES-2.05.tar.gz
wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-MD5-2.52.tar.gz
wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-SHA1-2.13.tar.gz
wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-HMAC-1.03.tar.gz
wget http://search.cpan.org/CPAN/authors/id/D/DT/DTOWN/Net-SNMP-v6.0.1.tar.gz
tar zxf Crypt-DES-2.05.tar.gz
tar zxf Digest-MD5-2.52.tar.gz
tar zxf Digest-SHA1-2.13.tar.gz
tar zxf Digest-HMAC-1.03.tar.gz
tar zxf Net-SNMP-v6.0.1.tar.gz
cd Crypt-DES-2.05
perl Makefile.PL
make install
cd ../
cd Digest-MD5-2.52
perl Makefile.PL
make install
cd ../
cd Digest-SHA1-2.13
perl Makefile.PL
make install
cd ../
cd Digest-HMAC-1.03
perl Makefile.PL
make install
cd ../
cd Net-SNMP-v6.0.1
perl Makefile.PL
make install
cd ../
# 插件位置
/soft/nagios-3.4.1/libexec
--------------------------------------
vi /soft/nagios-3.4.1/etc/cgi.cfg
#找到这几行,后面添加 erbin用户,可以自己定义用户,使用“,”隔开
#authorized_for_system_information=nagiosadmin,test
#authorized_for_configuration_information=nagiosadmin,test
#authorized_for_system_commands=nagiosadmin,test
#authorized_for_all_services=nagiosadmin,test
#authorized_for_all_hosts=nagiosadmin,test
#authorized_for_all_service_commands=nagiosadmin,test
#authorized_for_all_host_commands=nagiosadmin,test
use_authentication=0
vi /soft/nagios-3.4.1/etc/objects/contacts.cfg
vi /soft/nagios-3.4.1/etc/cgi.cfg
url_html_path=/nagios
vi /soft/nagios-3.4.1/etc/nagios.cfg
cfg_dir=/soft/nagios-3.4.1/etc/servers
cfg_file=/soft/nagios-3.4.1/etc/objects/hostgroups.cfg
mkdir -p /soft/nagios-3.4.1/etc/servers
cd /soft/nagios-3.4.1/etc/servers
vi /soft/nagios-3.4.1/etc/objects/hostgroups.cfg
define hostgroup {
hostgroup_name sa-servers
alias sa servers
members localhost,192.168.2.215 #用逗号间隔多个主机
}
修改nagiosadmin 这行其中的邮件地址为你的email 地址,以将报警邮件发到你的邮箱
设置登陆web 界面时HTTP 验证的账号密码
http://www.4webhelp.net/us/password.php
test:44ofpQvlFOgvs
vi /soft/nagios-3.4.1/etc/nagiospasswd
---------------------------------------
# 检测配置文件是否有错
/soft/nagios-3.4.1/bin/nagios -v /soft/nagios-3.4.1/etc/nagios.cfg
# 开启 nagios
/soft/nagios-3.4.1/bin/nagios -d /soft/nagios-3.4.1/etc/nagios.cfg
mkdir -p /wwwroot/web/
cp -r /soft/nagios-3.4.1/share/ /wwwroot/web/nagios
########## nginx 配置文件关键部位代码
server_name 192.168.2.215;
index index.html index.htm index.php;
root /wwwroot/web;
auth_basic "Nagios Access";
auth_basic_user_file /soft/nagios-3.2.1/etc/nagiospasswd;
location ~ .*\.(cgi|pl|perl)?$
{
gzip off;
root /soft/nagios-3.2.1/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_pass 127.0.0.1:8999;
fastcgi_param SCRIPT_FILENAME /soft/nagios-3.2.1/sbin$fastcgi_script_name;
fastcgi_index index.cgi;
fastcgi_read_timeout 60;
fastcgi_param REMOTE_USER $remote_user;
include fcgi.conf;
auth_basic "Nagios Access";
auth_basic_user_file /soft/nagios-3.2.1/etc/nagiospasswd;
}
########################### 开始安装cacti
cacti
yum -y install libart_lgpl-devel libpng-devel freetype-devel libart_lgpl-devel fonts-chinese cairo-devel pango-devel
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.3.tar.gz
tar zxf rrdtool-1.4.3.tar.gz
cd rrdtool-1.4.3
# 让rrdtool 支持中文
sed -i 's/setlocale(LC_NUMERIC, "C")/setlocale(LC_ALL, "zh_CN.UTF-8")/g' src/rrd_graph.c
sed -i 's/setlocale(LC_NUMERIC, old_locale)/setlocale(LC_ALL, old_locale)/g' src/rrd_graph.c
./configure --prefix=/soft/rrdtool-1.4.3
make && make install
cd ../
# 将 /soft/rrdtool-1.4.3/lib 加入到 /etc/ld.so.conf
ldconfig
wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
tar zxf cacti-0.8.8a.tar.gz
cp -r cacti-0.8.8a /wwwroot/web/cacti
cd /wwwroot/web/cacti
mysql -uroot -p
mysql>drop database cacti;
mysql>create database cacti;
mysql>use cacti;
mysql>source cacti.sql;
mysql>grant all privileges on cacti.* to cacti@localhost identified by "cacti";
mysql>grant all privileges on cacti.* to cactiuser@localhost identified by "cactiuser";
mysql>flush privileges;
mysql>exit
# 修改数据库信息
vi include/config.php
# 修改php配置文件,修改时区
vi /soft/php-5.4.6/etc/php.ini
safe_mode = Off
date.timezone = "PRC"
# 保存退出 并重启
wget http://sourceforge.net/projects/net-snmp/files/net-snmp/5.6.1.1/net-snmp-5.6.1.1.tar.gz/download
tar zxf net-snmp-5.6.1.1.tar.gz
cd net-snmp-5.6.1.1
# 编译第一步 版本是2
./configure --prefix=/soft/net-snmp-5.6.1.1 --enable-developer
make && make install
echo /soft/net-snmp-5.6.1.1/lib > /etc/ld.so.conf
ldconfig
cd ../
crontab -e
# 没分钟采集一次数据 使用root采集. 一个比较操蛋的问题. 就是东西太多 多环境生成会出问题 权限设置又很麻烦 不如这么来最实惠了.
*/1 * * * * root /soft/php-5.4.6/bin/php /wwwroot/web/cacti/poller.php > /dev/null 2>&1 && /bin/chown www:www * /wwwroot/web/cacti/rra/*
# 使用二进制文件来进行数据采集 效率较高
wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8a.tar.gz
tar zxf cacti-spine-0.8.8a.tar.gz
cd cacti-spine-0.8.8a
./configure --prefix=/soft/cacti-spine-0.8.8a --with-mysql=/soft/mysql-5.5.27/ --with-snmp=/soft/net-snmp-5.6.1.1/
make && make install
cd /soft/cacti-spine-0.8.8a/etc/
mv spine.conf.dist spine.conf
vi /soft/cacti-spine-0.8.8a/etc/spine.conf
# 安装完成 之后
http://ip/cacti/install
/soft/rrdtool-1.4.3/bin/rrdtool
/soft/php-5.4.6/bin/php
/soft/net-snmp-5.6.1.1/binsnmpwalk
/soft/net-snmp-5.6.1.1/binsnmpget
/soft/net-snmp-5.6.1.1/bin/snmpbulkwalk
/soft/net-snmp-5.6.1.1/bin/snmpgetnext
/soft/cacti-spine-0.8.8a/bin/spine
用户名 密码 均为admin
# 如果绘图出现乱码 上传一个中文字体即可
cp simsun.ttc /usr/share/fonts
fc-cache -f -v
# 整合cacit和nagios
wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz/download
tar zxf ndoutils-1.5.2.tar.gz
cd ndoutils-1.5.2
ldconfig
./configure --prefix=/soft/ndoutils-1.5.2 --with-mysql=/soft/mysql-5.5.27/ --with-ndo2db-user=nagios --with-ndo2db-group=nagios
# include/config.h 修改261 262行
#include
#include
make
make install
需要安装dbi 和 dbd
-----------------------------------------
wget http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/Test-Simple-0.98.tar.gz
wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.622.tar.gz
wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.022.tar.gz
tar zxf Test-Simple-0.98.tar.gz
tar zxf DBI-1.622.tar.gz
tar zxf DBD-mysql-4.022.tar.gz
cd Test-Simple-0.98
perl Makefile.PL
make
make install
cd ../
cd DBI-1.622
perl Makefile.PL
make
make install
cd ../
cd DBD-mysql-4.022
perl Makefile.PL
make
make install
cd ../
----------------------------------------------
cd db
./installdb -ucactiuser -pcactiuser -hlocalhost -d cacti
-------
cp ../config/ndomod.cfg-sample /soft/nagios-3.4.1/etc/ndomod.cfg
vi /soft/nagios-3.4.1/etc/nagios.cfg
check_external_commands=1
command_check_interval=-1
event_broker_options=-1
broker_module=/soft/nagios-3.4.1/bin/ndomod-3x.o config_file=/soft/nagios-3.4.1/etc/ndomod.cfg
process_performance_data=1
--------
cd /root/ndoutils-1.5.2/src
cp ndomod-3x.o ndo2db-3x log2ndo file2sock /soft/nagios-3.4.1/bin/
cd ../config
cp ndo2db.cfg-sample /soft/nagios-3.4.1/etc/ndo2db.cfg
/soft/ndoutils-1.5.2/bin/ndo2db -c /soft/nagios-3.4.1/etc/ndo2db.cfg
mkdir -p /soft/ndoutils-1.5.2/var/
# selinux
# http://wiki.centos.org/TipsAndTricks/SelinuxBooleans
# http://selinuxproject.org/page/NB_AL
chcon -R -t httpd_sys_content_t /soft/nagios-3.4.1/sbin/
chcon -R -t httpd_sys_content_t /soft/nagios-3.4.1/share/
# 安装npc 让nagios在cacti显示
tar zxf npc-2.0.4.tar.gz
cp -r npc /wwwroot/web/cacti/plugins/
chown www:www -R /wwwroot/web/
# 解决npc不出图的问题 进mysql cacti 数据库进行刷库
ALTER TABLE npc_eventhandlers ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
ALTER TABLE npc_hostchecks ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
ALTER TABLE npc_hoststatus ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
ALTER TABLE npc_notifications ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
ALTER TABLE npc_servicechecks ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
ALTER TABLE npc_servicestatus ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
ALTER TABLE npc_statehistory ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
ALTER TABLE npc_systemcommands ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
# 进入到软件目录
chown nagios:nagios -R nagios-3.4.1/ ndoutils-1.5.2/
# 进入web进行插件设置
ndo2db 内核错误解释
# cat /proc/sys/kernel/msgmnb
65536
# cat /proc/sys/kernel/msgmax
65536
# cat /proc/sys/kernel/msgmni
1985
# echo 131072 > /proc/sys/kernel/msgmnb
and
# vi /etc/sysctl.conf
and adjust the appropriate value(s).
Why did I do it:
Because of repeating error messages in /var/log/messages:
360viewpoint ndo2db: Warning: Retrying message send. This can occur because you have too few messages allowed or too few total bytes allowed in message queues. You are currently using 64 of 1985 messages and 65536 of 65536 bytes in the queue. See README for kernel tuning options.
How did I know how to do this
Read the NDO-Utils README file:
************************
TUNING KERNEL PARAMETERS
************************
NDOUTILS uses a single message queue to communicate between the broker
module and the NDO2DB daemon. Depending on the operating system, there
may be parameters that need to be tuned in order for this communication
to work correctly. The discussion below applies specifically to Linux,
but may apply generally to other Unices as well.
There are three Linux kernel parameters that determine the resources
provided to the messaging subsystem:
* kernel.msgmax is the maximum size of a single message in a
message queue
* kernel.msgmni is the maximum number of messages allowed in any
one message queue
* kernel.msgmnb is the total number of bytes allow in all messages
in any one message queue
To see the current values for any of these parameters, cat
/proc/sys/kernel/msg{max|mni|mnb}.
In order for NDOUTILS to work at all, kernel.msgmax must be greater than
the size of the queue_msg struct (currently 1026 bytes). Most Linux
distributions set kernel.msgmax to a default of 65536.
If there are insufficient resources for sending messages between the
broker and the daemon, you will see an entry similar to the following
in your logs. (This is logged via the syslog facility, using the level
LOG_ERR and the default facility.)
ndo2db: Warning: Retrying message send. This can occur because
you have too few messages allowed or too few total bytes
allowed in message queues. You are currently using 16 of 16
mesages and 65536 of 65536 bytes in the queue. See README for
kernel tuning options.
If you see this entry, the message will likely eventually be sent,
but retrying uses system resources, and there is the possibility that
more messages will queued than can be handled, causing the broker
module to stall.
If you are close to or have exceeded the number of messages, you may
need to increase kernel.msgmni. If you are close to or have exceeded
the number of bytes in the queue, you may need to increase
kernel.msgmnb. In some cases you may need to increase both.
A conservative approach would be to double the necessary value, stop
and restart both the NDO2DB daemon and Nagios Core, and watch for any
further messages. Note that if NDO2DB is started after Nagios Core,
you may see the warning above as the broker module first attempts to
flush its backlog of messages.
To increase a value, echo the value to /proc/sys/kernel/msgmni or
/proc/sys/kernel/msgmnb as appropriate.
For example, to increase the number of messages allowed in the queue
to 32, use the command 'echo 32 > /proc/sys/kernel/msgmni' (without
the quotes).
Once you have determine the correct parameters, you can make them
permanent by editing /etc/sysctl.conf. Add or update the line of
the form 'kernel.msg{mni|mnb} =
above. The next time the system is booted, the values of the
parameters in /etc/sysctl.conf will be loaded.
网站题目:LNMP+Cacti+Nagios+ndo2+Npc
URL网址:http://cdiso.cn/article/ipdcpp.html