來看下 兩者區(qū)別
站在用戶的角度思考問題,與客戶深入溝通,找到上街網(wǎng)站設(shè)計(jì)與上街網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋上街地區(qū)。
Cacti:在監(jiān)控方面繪圖比較不錯(cuò),在流量與圖型展現(xiàn)比較存在優(yōu)勢(shì)
Nagios:在故障分析比較不錯(cuò),報(bào)警機(jī)制相對(duì)來說比較好,報(bào)警機(jī)制:郵箱、短信等,而且也比Cacti靈活;同時(shí)適用監(jiān)控大量服務(wù)器以及服務(wù)器上面大批服務(wù)狀態(tài)是否正常,重點(diǎn)不在圖形化,而在狀態(tài)故障的監(jiān)控
1.安裝相關(guān)的軟件包
[root@Wangqi Desktop]# yum -y install httpd php gcc glibc glibc-common gd gd-devel libpng libjpeg zlib
2.創(chuàng)建相關(guān)的用戶和組
[root@Wangqi LoadBalancer]# useradd -s /sbin/nologin nagios
[root@Wangqi LoadBalancer]# groupadd nagcmd
[root@Wangqi LoadBalancer]# usermod -G nagcmd nagios
[root@Wangqi LoadBalancer]# usermod -G nagcmd apache
3.安裝、編譯nagios
[root@Wangqi Desktop]# tar zxvf nagios-3.2.1.tar.gz -C /usr/src/
[root@Wangqi Desktop]# cd /usr/src/nagios-3.2.1/
[root@Wangqi nagios-3.2.1]# ./configure --with-command-group=nagcmd
[root@Wangqi nagios-3.2.1]# make all
[root@Wangqi nagios-3.2.1]# make install
[root@Wangqi nagios-3.2.1]# make install-init
[root@Wangqi nagios-3.2.1]# make install-config
[root@Wangqi nagios-3.2.1]# make install-commandmode
[root@Wangqi nagios-3.2.1]# make install-webconf
注釋:
make install-init是向/etc/rc.d/init.d中安裝啟動(dòng)腳本
make install-commandmode是將額外的命令文件修改好恰當(dāng)?shù)臋?quán)限
make install-config是向/usr/local/nagios/etc目錄下寫入示例配置文件
[root@Wangqi nagios-3.2.1]# cd /usr/local/nagios/
[root@Wangqi nagios]# ls
bin測(cè)試命令目錄
etc 配置文件目錄
libexec 插件目錄
sbin cgj腳本目錄
share nagios網(wǎng)頁文件目錄
var nagios運(yùn)行總會(huì)產(chǎn)生的數(shù)據(jù)
[root@Wangqi nagios]# ls etc/
cgi.cfg cgi程序配置文件
nagios.cfg nagios服務(wù)主配置文件
resource.cfg 定義nagios變量文件
[root@Wangqi nagios]# ls etc/objects/
commands.cfg 定義監(jiān)控命令配置文件
localhost.cfg 定義監(jiān)控本機(jī)對(duì)象配置文件
timeperiods.cfg 監(jiān)控時(shí)間模板文件
contacts.cfg 指定報(bào)警郵件發(fā)送郵箱
templates.cfg 監(jiān)控方式模板文件
4.安裝插件
[root@Wangqi Desktop]# tar -zxvf nagios-plugins-1.4.14.tar.gz
[root@Wangqi Desktop]# cd nagios-plugins-1.4.14
[root@Wangqi nagios-plugins-1.4.14]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
[root@Wangqi nagios-plugins-1.4.14]# make && make install
插件使用:
[root@Wangqi libexec]# ./check_http --help
[root@Wangqi libexec]# ./check_http -H localhost -p 80
[root@Wangqi libexec]# ./check_ftp -H localhost -p 21
[root@Wangqi libexec]# ./check_ping -H 127.0.0.1 -w 5,10% -c 10,20% -p 10 -t 20
[root@Wangqi libexec]# htpasswd -cm /usr/local/nagios/etc/htpasswd.users nagiosadmin
5.通過Firefox訪問nagios
[root@Wangqi libexec]# firefox &
http://192.168.2.3/nagios
user:nagiosadmin
password:123456
6.nagios監(jiān)控本身
配置步驟
定義監(jiān)控命令->commands.cfg
定義監(jiān)控對(duì)象->localhost.cfg
加載監(jiān)控對(duì)象配置文件->nagios.cfg
配置登陸頁面認(rèn)證用戶->nagios.conf
啟動(dòng)nagios服務(wù)
啟動(dòng)HTTP服務(wù)
登陸監(jiān)控頁面
(1)定義監(jiān)控命令
[root@Wangqi nagios]# vim etc/objects/commands.cfg
# 'check_nfs' command definition
define command{
command_name check_nfs
command_line $UWangqi$/check_tcp -H $HOSTADDRESS$ $ARG1$
}
[root@Wangqi nagios]# vim etc/objects/localhost.cfg
define service{
use local-service ; Name of service template to use
host_name localhost
service_description NFS
check_command check_nfs!2049
notifications_enabled 0
}
[root@Wangqi nagios]# ./bin/nagios -v /usr/local/nagios/etc/nagios.cfg //檢查文件
[root@Wangqi nagios]# service nagios restart
7.配置監(jiān)控遠(yuǎn)程主機(jī)
被監(jiān)控端(1)安裝監(jiān)控插件
[root@Wangqi Desktop]# useradd nagios
[root@Wangqi Desktop]# groupadd nagcmd
[root@Wangqi Desktop]# usermod -aG nagcmd nagios
安裝插件
[root@Wangqi nagios-plugins-1.4.14]# tar zxvf nagios-plugins-1.4.14.tar.gz -C /usr/src/
[root@Wangqi nagios-plugins-1.4.14]# cd /usr/src/nagios-plugins-1.4.14/
[root@Wangqi nagios-plugins-1.4.14]# yum -y install gcc gcc-c++
[root@Wangqi nagios-plugins-1.4.14]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
[root@Wangqi nagios-plugins-1.4.14]# make && make install
[root@Wangqi nagios-plugins-1.4.14]# cd /usr/local/nagios/
安裝NRPE
[root@Wangqi Desktop]# tar zxvf nrpe-2.12.tar.gz
[root@Wangqi Desktop]# cd nrpe-2.12
[root@Wangqi nrpe-2.12]# yum -y install openssl-devel
[root@Wangqi nrpe-2.12]# ./configure && make && make install
[root@Wangqi nrpe-2.12]# make install-plugin
[root@Wangqi nrpe-2.12]# make install-daemon
[root@Wangqi nrpe-2.12]# make install-daemon-config
[root@Wangqi nrpe-2.12]# make install-xinetd
[root@Wangqi etc]# vim nrpe.cfg
command[check_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /root
command[check_boot]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /boot
[root@Wangqi etc]# vim /etc/xinetd.d/nrpe
only_from = 127.0.0.1 192.168.2.3
[root@Wangqi etc]# vim /etc/services
nrpe 5666/tcp #nrpe
[root@Wangqi nrpe-2.12]# yum -y install xinetd //6.5需要安裝
[root@Wangqi nrpe-2.12]# netstat -anptul | grep :5666
tcp 0 0 :::5666 :::* LISTEN 51819/xinetd
[root@Wangqi nrpe-2.12]# cd /usr/local/nagios/
[root@Wangqi libexec]# ./check_nrpe -H localhost
NRPE v2.12
監(jiān)控端(1)
安裝nrpe
[root@Wangqi Desktop]# tar zxvf nrpe-2.12.tar.gz
[root@Wangqi Desktop]# cd nrpe-2.12
[root@Wangqi nrpe-2.12]# yum -y install openssl-devel
[root@Wangqi nrpe-2.12]# ./configure && make && make install
[root@Wangqi nrpe-2.12]# make install-plugin
[root@Wangqi libexec]# ./check_nrpe -H 192.168.2.4
NRPE v2.12
(2)定義命令
[root@Wangqi nagios]# vim etc/objects/commands.cfg
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $UWangqi$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
[root@Wangqi etc]# vim objects/ser2.cfg
define service{
use local-service ; Name of service template to use
host_name Wangqi.tarena.com
service_description Boot Partition
check_command check_nrpe!check_boot
}
define service{
use local-service ; Name of service template to use
host_name Wangqi.tarena.com
service_description Root Partition
check_command check_nrpe!check_root
}
[root@Wangqi etc]# /usr/local/nagios/bin/nagios -v nagios.cfg
[root@Wangqi etc]# service nagios restart
[root@Wangqi libexec]# firefox &
http://192.168.2.3/nagios
六、安裝cacti
1.安裝相關(guān)軟件包
[root@Wangqi etc]# yum -y install php-MySQL php-ldap php-xml net-snmp-utils mysql mysql-server net-snmp crond rrdtool lm_sensors
rrdtool在RHEL5的光盤中不提供,需要用源碼包
yum install -y gcc gcc-c++ libart_lgpl-devel zlib-devel libpng-devel freetype-devel
[root@Wangqi etc]# service httpd start
[root@Wangqi etc]# service mysqld start
2.安裝cacti
[root@Wangqi Desktop]# tar zxvf cacti-0.8.7g.tar.gz
[root@Wangqi Desktop]# cp -rp cacti-0.8.7g /var/www/html/cacti
[root@Wangqi html]# useradd cactiuser
[root@Wangqi html]# chown -R cactiuser.cactiuser ./cacti/rra
[root@Wangqi html]# chown -R cactiuser.cactiuser ./cacti/rra/ cacti/log/
[root@Wangqi html]# mysql -uroot -p
mysql> create database cactidb default character set utf8;
mysql> show databases;
mysql> grant all on cactidb.* to 'cactiuser'@'localhost' identified by 'cacti';
[root@Wangqi cacti]# mysql -ucactiuser -pcacti cactidb < cacti.sql
[root@Wangqi cacti]# vim include/config.php
3.登陸web界面
HTTP://192.168.2.3/cacti
4.被監(jiān)控端
[root@Wangqi etc]# vim /etc/snmp/snmpd.conf
com2sec notConfigUser 192.168.20.1 public
access那一行的systemview改成all
view all included .1取消注釋
[root@Wangqi etc]# service snmpd restart
5.監(jiān)控端
在web頁上點(diǎn)擊devices,刪除原有的localhost,點(diǎn)擊右側(cè)的add
添加新的主機(jī)。HOST template用ucd/net snmp host
Associated Data Queries添加以下的數(shù)據(jù)
SNMP - Get Mounted Partitions
SNMP - Get Processor Information
SNMP - Interface Statistics
保存save后,找到頁面最上面的Create Graphs for this Host
把主機(jī)加入到圖形樹中
點(diǎn)擊左側(cè)的graph tree->default tree->點(diǎn)擊右側(cè)的add
tree item type選擇host,然后點(diǎn)擊create
產(chǎn)生數(shù)據(jù)
[root@localhost ~]# su - cactiuser
[runct@localhost ~]$ php /var/www/html/cacti/poller.php
[runct@localhost ~]$ crontab -e
*/1 * * * * /usr/bin/php /var/www/html/cacti/poller.php &> /dev/null
[runct@localhost ~]$ exit
[root@localhost ~]# service crond start
隔幾分鐘后,再點(diǎn)擊web頁的graph按鈕就可以看到圖形了
[root@Wangqi cacti]# service snmpd start
6.安裝插件框架
[root@Wangqi cacti]# tar zxvf cacti-plugin-0.8.7g-PA-v2.9.tar.gz
[root@Wangqi cacti]# mv cacti-plugin-arch /var/www/html/cacti/
[root@Wangqi cacti]# cd /var/www/html/cacti/
[root@Wangqi cacti]# patch -p1 -N < cacti-plugin-arch/cacti-plugin-0.8.7g-PA-v2.9.diff
[root@Wangqi cacti]# mysql -ucactiuser -pcacti cactidb < cacti-plugin-arch/pa.sql
[root@Wangqi cacti]# vim include/global.php
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cacti";
$database_port = "3306";
[root@Wangqi cacti]# vim include/config.php
$url_path = "/cacti/";
WEB頁面中左側(cè)的用戶管理(user management)->admin用戶的權(quán)限(下面的Plugin Management)加入PA
7.插件安裝
[root@Wangqi Desktop]# tar zxvf settings-v0.71-1.tgz
[root@Wangqi Desktop]# tar zxvf monitor-v1.3-1.tgz
[root@Wangqi Desktop]# tar zxvf thold-v0.4.9-3.tgz
[root@Wangqi Desktop]# mv settings monitor thold /var/www/html/cacti/plugins
七、整合cacti+nagios
1、cacti在監(jiān)控服務(wù)器資源、繪圖方面比nagios有優(yōu)勢(shì),但是nagios在監(jiān)控服務(wù)、報(bào)警方面是cacti無法替代的。無法僅使用其中一款軟件達(dá)到所有的要求。cacti可以安裝多款插件,其中Nagios Plugin for Cacti(NPC)可以將nagios的功能以插件的方式在cacti中顯示出來。
2、nagios本身的插件是二進(jìn)制可執(zhí)行文件,運(yùn)維工程師不具備高級(jí)程序語言的編程能力,因此插件改用SHELL腳本實(shí)現(xiàn)。
整合cacti和nagios是利用了cacti的一個(gè)插件nagios for cacti,它的原理是將nagios的數(shù)據(jù)通過ndo2db導(dǎo)入到mysql數(shù)據(jù)庫(cacti的庫中),然后cacti讀取數(shù)據(jù)庫信息將nagios的結(jié)果展示出來。
1.安裝ndoutils
首先需要安裝ndoutils以將nagios的數(shù)據(jù)能導(dǎo)入到mysql數(shù)據(jù)庫中
[root@localhost cacti]# yum -y install mysql-devel
[root@Wangqi ndoutils-1.4b9]# tar zxvf ndoutils-1.4b9.tar.gz -C /usr/src/
[root@Wangqi ndoutils-1.4b9]# cd /usr/src/ndoutils-1.4b9/
[root@Wangqi ndoutils-1.4b9]# ./configure --prefix=/usr/local/nagios LDFLAGS=-L/usr/lib --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
[root@Wangqi ndoutils-1.4b9]# make && make install
2.導(dǎo)入數(shù)據(jù)庫
[root@Wangqi ndoutils-1.4b9]# cd db/
[root@Wangqi db]# ./installdb -u cactiuser -p cacti -h localhost -d cactidb
3.配置文件
[root@Wangqi db]# cd ..
[root@Wangqi ndoutils-1.4b9]# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
[root@Wangqi ndoutils-1.4b9]# vim /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
process_performance_data=1
[root@Wangqi ndoutils-1.4b9]# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
[root@Wangqi ndoutils-1.4b9]# grep -v -E '(^$| *#)' /usr/local/nagios/etc/ndomod.cfg
instance_name=default
output_type=tcpsocket
output=127.0.0.1
tcp_port=5668
use_ssl=0
output_buffer_items=5000
buffer_file=/usr/local/nagios/var/ndomod.tmp
file_rotation_interval=14400
file_rotation_timeout=60
reconnect_interval=15
reconnect_warning_interval=15
data_processing_options=-1
config_output_options=2
[root@Wangqi ndoutils-1.4b9]# vim /usr/local/nagios/etc/ndomod.cfg
[root@Wangqi ndoutils-1.4b9]# grep -v -E '(^$| *#)' /usr/local/nagios/etc/ndo2db.cfg
lock_file=/usr/local/nagios/var/ndo2db.lock
ndo2db_user=nagios
ndo2db_group=nagios
socket_type=tcp
socket_name=/usr/local/nagios/var/ndo.sock
tcp_port=5668
use_ssl=0
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cactidb
db_prefix=npc_
db_user=cactiuser
db_pass=cacti
max_timedevents_age=1440
max_systemcommands_age=10080
max_servicechecks_age=10080
max_hostchecks_age=10080
max_eventhandlers_age=44640
max_externalcommands_age=44640
debug_level=1
debug_verbosity=1
debug_file=/usr/local/nagios/var/ndo2db.debug
max_debug_file_size=1000000
[root@Wangqi ndoutils-1.4b9]# vim /usr/local/nagios/etc/ndo2db.cfg
二、安裝json
npc展示部分用到j(luò)son,需要在php中安裝php-json的支持
1、安裝php的準(zhǔn)備環(huán)境
[root@localhostnpc]# yum install -y php-devel
2、安裝json
[root@localhostnpc]# tarxvjf php-json-ext-1.2.1.tar.bz2 -C /usr/src/
[root@localhost php-json-ext-1.2.1]# phpize
[root@localhost php-json-ext-1.2.1]# ./configure && make && make install
3、啟用json擴(kuò)展
[root@localhost php-json-ext-1.2.1]# vim /etc/php.d/json.ini
extension=php_json.so
[root@localhost php-json-ext-1.2.1]# ln -s /usr/lib64/php/modules/json.so /usr/lib64/php/modules/php_json.so
三、安裝npc插件
1、安裝
[root@localhostnpc]# tar xvzf npc-2.0.4.tar.gz
[root@localhostnpc]# mvnpc /var/www/html/cacti/plugins
2、在WEB頁中啟用插件
3、配置插件
4、注意修改權(quán)限
[root@localhostnpc]# cd /usr/local/nagios/etc
[root@localhostetc]# chmod 644 ndo2db.cfg
[root@localhostetc]# chmod 644 ndomod.cfg
[root@localhostetc]# chownnagios.nagiosndomod.cfg ndo2db.cfg
5、啟動(dòng)服務(wù)
[root@localhostnpc]# servicemysqld restart
[root@localhostnpc]# servicehttpd restart
[root@localhostnpc]# /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
[root@localhostnpc]# netstat -tlnp | grep :5668
tcp 0 0 0.0.0.0:5668 0.0.0.0:* LISTEN 19273/ndo2db
[root@localhostnpc]# servicenagios restart
6、結(jié)果如下
7.我們來 排錯(cuò)
Nagios中沒有數(shù)據(jù),查看/var/log/messages的報(bào)錯(cuò)信息,發(fā)現(xiàn)是mysql的問題:
Aug 14 16:01:18 localhost ndo2db: mysql_error: 'Unknown column 'long_output' in 'field list''
所以執(zhí)行以下操作:
mysql -uroot -p
mysql> use cactidb;
mysql>ALTER TABLEnpc_eventhandlersADDlong_output TEXT NOT NULL DEFAULT '' AFTER output;
mysql> ALTER TABLE npc_hostchecks ADD loing_output TEXT NOT NULL DEFAULT '' AFTER output;
mysql> ALTER TABLE npc_hoststatus ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
mysql> ALTER TABLE npc_notifications ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
mysql> ALTER TABLE npc_servicechecks ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
mysql> ALTER TABLE npc_servicestatus ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
mysql> ALTER TABLE npc_statehistory ADD long_out TEXT NOT NULL DEFAULT '' AFTER output;
mysql> ALTER TABLE npc_systemcommands ADD long_output TEXT NOT NULL DEFAULT '' AFTER output;
修復(fù)后的截圖如下: