最近有需求又搞了下nagios记录下备忘,采用快速安装lamp方式
创新互联公司专注于靖远网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供靖远营销型网站建设,靖远网站制作、靖远网页设计、靖远网站官网定制、微信小程序定制开发服务,打造靖远网络公司原创品牌,更为您提供靖远网站排名全网营销落地服务。
1、快速安装lamp
yum groupinstall "Web Server"
yum groupinstall "MySQL Database"
yum install php-mysql
2、安装nagios
tar -xjvf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --with-nagios-user=nagios --with-nagios-group=nagios
make all && make install
make install-init && make install-commandmode
make install-config
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
3、修改/etc/httpd/conf/httpd.conf
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
Alias /nagios /usr/local/nagios/share
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
重启httpd: service httpd restart
4、插件及客户端安装
#!/bin/sh
set -x
#if [ -d /usr/local/nagios ]; then
# rm -rf /usr/local/nagios*
#fi
if [ -d /usr/local/nrpe ]; then
rm -rf /usr/local/nrpe*
fi
useradd nagios
yum -y install xinetd
wget -c http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.14/nagios-plugins-1.4.14.tar.gz/download
tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios --enable-redhat-pthread-workaround
make && make install
chown -R nagios.nagios /usr/local/nagios
cd ../
wget -c http://cdnetworks-kr-1.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --prefix=/usr/local/nagios --enable-command-args
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
cd /etc/xinetd.d/
sed -i 's/127.0.0.1/127.0.0.1 192.168.120.7/g' nrpe
echo "nrpe 5666/tcp # nrpe" >> /etc/services
service xinetd restart
6、添加配置文件在nagios.cfg中
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
注释#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
7、定义hosts.cfg文件
# Define a host for the local machine
define host{
use standard-server
host_name localhost-220
alias localhost
address 127.0.0.1
define host{
use standard-server
host_name DB
alias 192.168.120.3
address 192.168.120.3
}
8、定义模版文件templates.cfg
define service{
name service-all
use generic-service
contact_groups admingroup
register 0
}
define service{
name generic-service
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 1
check_freshness 0
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
failure_prediction_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 3
retry_check_interval 1
contact_groups admingroup
notification_options w,c,r
notification_interval 0
notification_period 24x7
register 0
}
define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24x7 ; Send host notifications at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
define host{
name standard-server
use generic-host
check_period 24x7
check_interval 3
retry_interval 1
max_check_attempts 5
check_command check-host-alive
notification_period 24x7
notification_interval 0
notification_options d,u,r
contact_groups admingroup
}
9、定义时间文件
# 24x7 monitor
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}
# workhours monitor
define timeperiod{
timeperiod_name workhours
alias Normal Work Hours
monday 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09:00-17:00
}
# custom monitor time
define timeperiod{
timeperiod_name smsworkhours
alias no sleep time
sunday 08:30-23:00
monday 07:00-23:00
tuesday 07:00-23:00
wednesday 07:00-23:00
thursday 07:00-23:00
friday 07:00-23:00
saturday 08:30-23:00
}
10、定义服务配置文件
define service {
use service-all
host_name localhost-220
service_description check-http
check_command check_http
}
define service {
use service-all
host_name localhost-220
service_description check-disk
check_command check_nrpe!check_disk
}
define service {
use service-all
host_name localhost-220
service_description check-alive
check_command check-host-alive
}
define service {
use service-all
host_name localhost-220
service_description check-load
check_command check_nrpe!check_load
11、错误处理总结
①#如果提示“Whoops! Error: Could not read object configuration data! ”,这是因为没有启动nagios后台进程,执行以下命令
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg 或者service nagios restart
②It appears as though you do not have permission to view information for any of the services you requested…
解决:打开cgi.cfg配置文件,里面有个参数:
use_authentication=1
为了保障系统的安全性,nagios设置了这个参数,默认为1,改为0即可
分享题目:nagios监控系统的快速部署
标题URL:
http://cdxtjz.com/article/iidggc.html