LNMP+Cacti+Nagios+ndo2+Npc

Cacti 多用于圖形監(jiān)測系統(tǒng)性能 負載等      
Nagios 多用于報警

專注于為中小企業(yè)提供網(wǎng)站制作、成都網(wǎng)站設(shè)計服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)平壩免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。

Cacti: 是一套基于PHP,MySQL,SNMP及RRDTool開發(fā)的網(wǎng)絡(luò)流量監(jiān)測圖形分析工具.        
Nagios:是一款開源的免費網(wǎng)絡(luò)監(jiān)視工具,能有效監(jiān)控Windows、Linux和Unix的主機狀態(tài),在系統(tǒng)或服務(wù)狀態(tài)異常時發(fā)出郵件或短信報警第一時間通知網(wǎng)站運維人員,在狀態(tài)恢復(fù)后發(fā)出正常的郵件或短信通知.        
Npc: 是一個cacti的插件.用于講 Cacti和Nagios整合.

注意如下幾點      
1.Cacti 需要 LNMP 或者 LAMP 作為平臺        
2.Nagios 需要web服務(wù)器支持cgi        
3.Cacti 是通過 net-snmp 來采集數(shù)據(jù)的. 客戶機需要安裝net-snmp

4.本文不過多的介紹配置文件和軟件使用方法 只標注管簡單 多去學(xué)習(xí)才能更好的掌握各種知識

本文以 Centos 5.4 作為平臺來搭建      
   LNMP 環(huán)境如下        
   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

先來幾張圖,把關(guān)鍵位置標注出來. 從正文開始 大篇幅安裝步驟 不單獨出圖

下面的幾個圖 只是關(guān)鍵點

LNMP+Cacti+Nagios+ndo2+Npc

New Graphs:新建圖形      
Graph Management:圖形管理        
Data Sources:數(shù)據(jù)源        
Devices:添加主機活設(shè)備在這        
Plugin Management:插件管理        
System Utilities: 如果不出圖 點這個菜單 把 view xxxx cache 都點一次 清理下緩存

LNMP+Cacti+Nagios+ndo2+Npc

幾個設(shè)置的時候要注意的地方

LNMP+Cacti+Nagios+ndo2+Npc

cacti 優(yōu)化參考

所有參數(shù) 不可全抄 要根據(jù)實際情況修改

LNMP+Cacti+Nagios+ndo2+Npc

npc 插件設(shè)置
LNMP+Cacti+Nagios+ndo2+Npc

##################################################      
#################  安裝正文  #####################        
##################################################        
# 安裝cacti需要的包        
yum install -y gd gd-devel xinetd libart_lgpl

# 建立nagios用戶 用于維護nagios      
/usr/sbin/useradd nagios        
#passwd nagios

# 建立nagioscmd組 用于執(zhí)行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) 手工安裝        
# 首先去官方網(wǎng)站 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 地址,以將報警郵件發(fā)到你的郵箱

設(shè)置登陸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 配置文件關(guān)鍵部位代碼      
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

# 修改數(shù)據(jù)庫信息      
vi include/config.php

# 修改php配置文件,修改時區(qū)      
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      
# 沒分鐘采集一次數(shù)據(jù) 使用root采集. 一個比較操蛋的問題. 就是東西太多 多環(huán)境生成會出問題 權(quán)限設(shè)置又很麻煩 不如這么來最實惠了.        
*/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/*

# 使用二進制文件來進行數(shù)據(jù)采集 效率較高      
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

# 如果繪圖出現(xiàn)亂碼 上傳一個中文字體即可      
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 </soft/mysql-5.5.27/include/mysql.h>        
#include </soft/mysql-5.5.27/include/errmsg.h>

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 數(shù)據(jù)庫進行刷庫      
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進行插件設(shè)置

ndo2db 內(nèi)核錯誤解釋      
# 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} = <value>' with the value(s) determined        
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
網(wǎng)址分享:http://bm7419.com/article38/ipdcpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、全網(wǎng)營銷推廣、網(wǎng)站改版、營銷型網(wǎng)站建設(shè)、外貿(mào)建站、小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)