自动化运维之Nagios

安装步骤见后文参考文档

问题解决:
错误1
无法正确地读出配置文件中的对象数据!

将所有Nagios相关进程都kill掉,重新启动nagios,应该能解决问题
在这里插入图片描述
以下是所需配置
httpd.conf

#服务目录
ServerRoot "/etc/httpd"
#监听端口
Listen 80
#模板位置以及加载模板
Include conf.modules.d/*.conf
LoadModule php5_module modules/libphp5.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule actions_module modules/mod_actions.so
#用户和组
User nagios
Group nagios
#管理员账户
ServerAdmin root@localhost
ServerName 127.0.0.1:80
#根目录权限
<Directory />
    AllowOverride none
    Require all granted
</Directory>
#主页目录权限
DocumentRoot "/var/www/html"
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
#主页文件类型
<IfModule dir_module>
    DirectoryIndex index.html index.php
    AddType application/x-httpd-php .php
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
#日志管理
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>
#此配置默认
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
#
<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>
#默认字符集
AddDefaultCharset UTF-8
#
<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
#nagios配置
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/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
	Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
	AuthType Basic
	Options ExecCGI
	AllowOverride None
	Order allow,deny
	Allow from all
	AuthName "nagios Access"
	AuthUserFile /usr/local/nagios/etc/htpasswd
	Require valid-user
</Directory>

cgi.cfg


main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios
show_context_help=0
use_pending_states=1
use_authentication=0
use_ssl_authentication=0
default_user_name=ixdba
authorized_for_system_information=nagiosadmin,ixdba
authorized_for_configuration_information=nagiosadmin,ixdba
authorized_for_system_commands=nagiosadmin,ixdba
authorized_for_all_services=nagiosadmin,ixdba
authorized_for_all_hosts=nagiosadmin,ixdba
authorized_for_all_service_commands=nagiosadmin,ixdba
authorized_for_all_host_commands=nagiosadmin.ixdba
statusmap_background_image=zytianbk.png
default_statusmap_layout=0
default_statuswrl_layout=4
ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
refresh_rate=90
escape_html_tags=1
action_url_target=_blank
notes_url_target=_blank
lock_author_names=1
ttf_file=/usr/local/nagios/sbin/simhei.ttf
statusmap_mod=0

nagios.cfg

log_file=/usr/local/nagios/var/nagios.log
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
object_cache_file=/usr/local/nagios/var/objects.cache
precached_object_file=/usr/local/nagios/var/objects.precache
resource_file=/usr/local/nagios/etc/resource.cfg
status_file=/usr/local/nagios/var/status.dat
status_update_interval=10
nagios_user=nagios
nagios_group=nagios
check_external_commands=1
command_check_interval=-1
command_file=/usr/local/nagios/var/rw/nagios.cmd
external_command_buffer_slots=4096
lock_file=/usr/local/nagios/var/nagios.lock
temp_file=/usr/local/nagios/var/nagios.tmp
temp_path=/tmp
event_broker_options=-1
log_rotation_method=d
log_archive_path=/usr/local/nagios/var/archives
use_syslog=0
log_notifications=0
log_service_retries=0
log_host_retries=0
log_event_handlers=0
log_initial_states=0
log_external_commands=1
log_passive_checks=1
service_inter_check_delay_method=s
max_service_check_spread=60
service_interleave_factor=s
host_inter_check_delay_method=s
max_host_check_spread=30
max_concurrent_checks=0
check_result_reaper_frequency=10
max_check_result_reaper_time=30
check_result_path=/usr/local/nagios/var/spool/checkresults
max_check_result_file_age=3600
cached_host_check_horizon=15
cached_service_check_horizon=15
enable_predictive_host_dependency_checks=1
enable_predictive_service_dependency_checks=1
soft_state_dependencies=0
time_change_threshold=900
auto_reschedule_checks=0
auto_rescheduling_interval=30
auto_rescheduling_window=180
sleep_time=2
service_check_timeout=60
host_check_timeout=30
event_handler_timeout=30
notification_timeout=30
ocsp_timeout=5
perfdata_timeout=5
retain_state_information=1
state_retention_file=/usr/local/nagios/var/retention.dat
retention_update_interval=60
use_retained_program_state=1
use_retained_scheduling_info=1
retained_host_attribute_mask=0
retained_service_attribute_mask=0
retained_process_host_attribute_mask=0
retained_process_service_attribute_mask=0
retained_contact_host_attribute_mask=0
retained_contact_service_attribute_mask=0
interval_length=60
check_for_updates=1
bare_update_check=0use_aggressive_host_checking=0
execute_service_checks=1
accept_passive_service_checks=1
execute_host_checks=1
accept_passive_host_checks=1
enable_notifications=1
enable_event_handlers=1
process_performance_data=1
service_perfdata_file=/usr/local/nagios/var/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPER
DATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata
obsess_over_services=0
obsess_over_hosts=0
translate_passive_host_checks=0
passive_host_checks_are_soft=0
check_for_orphaned_services=1
check_for_orphaned_hosts=1
check_service_freshness=1
service_freshness_check_interval=60
check_host_freshness=0
host_freshness_check_interval=60
additional_freshness_latency=15
enable_flap_detection=1
low_service_flap_threshold=5.0
high_service_flap_threshold=20.0
low_host_flap_threshold=5.0
high_host_flap_threshold=20.0
date_format=iso8601
p1_file=/usr/local/nagios/bin/p1.pl
enable_embedded_perl=1
use_embedded_perl_implicitly=1
illegal_object_name_chars=`~!$%^&*|'"<>?,()=
illegal_macro_output_chars=`~$&|'"<>
use_regexp_matching=0
use_true_regexp_matching=0
admin_email=nagios@localhost
admin_pager=pagenagios@localhost
daemon_dumps_core=0
use_large_installation_tweaks=0
enable_environment_macros=1
debug_level=0
debug_verbosity=1
debug_file=/usr/local/nagios/var/nagios.debug
max_debug_file_size=1000000

hosts.cfg

define host{
	use linux-server
	host_name web
	alias ixdba-web
	address 148.70.139.103
}
define hostgroup{
	hostgroup_name linuxsystem
	alias 	sa servers
	members	web
}

services.cfg

define service {
	use	local-service
	host_name	web
	service_description	PING
	check_command	check_ping!100.0,20%!200.0,60%
}
define service {
	use	local-service
	host_name web
	service_description SSH
	check_command	check_ssh
}
define service {
	use	local-service
	host_name web
	service_description http
	check_command	check_http
}

错误2
无权查看任何主机的信息…请检查HTTP服务器关于该CGI的访问权限设置
解决办法:

vi /usr/local/nagios/etc/cgi.cfg


use_authentication=0

然后重启nagios服务


/etc/init.d/nagios restart 

还有另外一种可能:

配置文件中的hostname称service_description使用了中文导致的。

记住:hostname和service_description 都最好不要使用中文哦
在这里插入图片描述
错误3:
Nagios监控HTTP服务时,出现“HTTP WARNING: HTTP/1.1 403 Forbidden - 5237 bytes in 0.008 second response time ”。

# /usr/local/nagios/libexec/check_http  -I 127.0.0.1

check_http 是检测“/var/www/html/index.html”。当没有这个文件,就会有warn警告。

创建一个主页文件

echo "123" >> /var/www/html/index.html

重启apache和nagios,过2分钟后,warn警告会消失。

 /etc/init.d/nagios restart
 /etc/init.d/httpd restart
参考文档

https://www.cnblogs.com/daynote/p/8819001.html#auto_id_20
https://blog.csdn.net/qq_26614295/article/details/75006660

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值