设为首页 收藏本站
查看: 1404|回复: 0

nagios 监控笔记(二)

[复制链接]

尚未签到

发表于 2019-1-17 09:13:50 | 显示全部楼层 |阅读模式
nagios 监控笔记(二)
四、nagios服务端配置与启动
        1)、文件说明
nagios.cfg                    #nagios主配置文件
cgi.cfg                          #cgi配置文件
commands.cfg            #命令配置文件
contacts.cfg               #联系人配置文件
resource.cfg               #定义插件路径文件
templates.cfg、timeperiods.cfg 组,监控时间段等配置文件
linux.cfg                      #用户自定义文件,监控linux主机,定义主机配置文件
windows.cfg              #用户自定义文件,监控windows主机,定义主机配置文件
l-services.cfg             #用户自定义文件,定义linux主机服务配置文件
w-services.cfg          #用户自定义文件,定义windows主机服务配置文件

2)、cgi.cfg文件配置
root@nagios#cd /usr/local/nagios/etc
vi    cgi.cfg                #以下是需要修改的地方
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   

#修改为0,不然监控访问的时候会出现以下提示
It appears as though you do not have permission to view information for any of the hosts you requested...
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
and check the authorization options in your CGI configuration file.



3)、配置nagios.cfg文件
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


# wb config
cfg_dir=/usr/local/nagios/etc/linux   
#配置linux主机加载自定义文件的目录(下面包括linux.cfg、l-services.cfg文件)
cfg_dir=/usr/local/nagios/etc/windows #配置win主机加载自定义文件的 目录(包括windows.cfg、w-services.cfg)



4)、配置commands.cfg命令配置文件
define command{
                command_name check_nrpe
                command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
                }

define command{
        command_name check_mysql_health  #定义mysql监控命令        command_line $USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$
        }
define command{
        command_name notify-service-by-sms #定义飞信监控命令        command_line /usr/local/tools/install/fetion --mobile=159230***** --pwd=2255*** --to=$CONTACTPAGER$ --msg-gb="$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ on $TIME$ result is $SERVICEOUTPUT$" $CONTACTPAGER$
}
notify-host-by-email、notify-service-by-email这二项是定义mail报警的命令,默认文件有这二项



5)、配置contacts.cfg联系人配置文件
define contact{
     contact_name                          nagiosadmin

     use                                        generic-contact
     alias                                       Nagios Admin
     service_notification_period          24x7
     host_notification_period              24x7
     service_notification_options     w,u,c,r
     host_notification_options            d,u,r
     service_notification_commands     notify-service-by-email,notify-service-by-sms
     host_notification_commands            notify-host-by-email
     email                              
test@test.com,test@163.com  
     pager                                           1592304****
                }

#email  定义联系人报警mail地址
#pager 定义联系人报警手机号码
#notify-service-by-email、notify-service-by-sms、notify-host-by-email、要与commands.cfg命令配置文件里的相对应


6)、linux.cfg主机配置文件
#====================linux server=====================
define host{
                use                          generic-host                        
                host_name                cvs-1.11
                alias                         cvs-server
                address                     192.168.1.11
                check_command          check-host-alive
                max_check_attempts             10
                check_period                        24x7
                notification_interval               20
                notification_period                 24x7
                notification_options                d,r
                contact_groups    admins
               
name                         cvs-1.11 #定义名字
                }
define host{
                use                             generic-host   

                host_name                   web-1.72
                alias                            web-server
                address                        192.168.1.72
                use                              cvs-1.11 #调用cvs-1.11的配置
                }



7)、windows.cfg配置文件
##############windows host################
define host{
                use                           generic-host   
                host_name                 windows-1.8
                alias                          win-server
                address                      192.168.1.8
                check_command          check-host-alive
                max_check_attempts             10
                check_period                        24x7
                notification_interval               20
                notification_period                 24x7
                notification_options                d,r
                contact_groups    admins
               
name                          windows-1.8 #定义名字
                }
define host{
                use                  generic-host  

                host_name        windows-1.71
                alias                 web-server
                address            192.168.1.71
                use                  windows-1.8 #调用windows-1.8配置文件
                }



8)、l-services.cfg定义服务配置文件
define service{
                use                                 generic-service
                host_name                       cvs-1.11 #与l-linux.cfg主机服务的名字相对应
                service_description              HTTP    status
                is_volatile                            0  #类似声音警告功能关闭
                check_period                       24x7
#监控期限为24X7
                max_check_attempts              3  
#最大检测3次
                normal_check_interval             1  
#每一分钟检测一次
                retry_check_interval               1  #间隔1分钟检测
                contact_groups                       admins #监控组
                notification_options                  w,u,c,r
# w,u,c,r 发生这四种情况时,进行通告
                notification_interval                  5 # 通告间隔
                notification_period                    24x7 #检测时间段
                check_command                       check_http
                }



check_command监控命令有
check-host-alive、check_nrpe!check_disk1、check_nrpe!check_load、check_nrpe!check_total_procs、check_nrpe!check_swap等
9)、w-services.cfg配置文件
define service{
                use                                  generic-service
                host_name                        windows-1.8
                service_description         NSClient++ Version
                is_volatile                                 0
                check_period                             24x7
                max_check_attempts                  3
                normal_check_interval                 1
                retry_check_interval                   1
                contact_groups                          admins
                notification_options                     w,u,c,r
                notification_interval                     5
                notification_period                       24x7
                check_command             check_nt!CLIENTVERSION
                }

define service{
        use                        generic-service
        host_name               windows-1.8
        service_description     E:\ Drive Space
        is_volatile                     0
        check_period                 24x7
        max_check_attempts       3
        normal_check_interval      1
        retry_check_interval        1
        contact_groups               admins
        notification_options          w,u,c,r
        notification_interval           5
        notification_period             24x7
        check_command         
check_nt!USEDDISKSPACE!-l e -w 80 -c 90
        }

# 如果要监控c 盘,check_nt!USEDDISKSPACE!-l c -w 80 -c 90  这里的c表示是c盘





check_command命令有
check_nt!UPTIME、check_nt!MEMUSE!-w 80 -c 90、(-w 80 -c 90)为当内存使用到80%为warning警告,内存使用到90%为critical紧急,check_nt!USEDDISKSPACE!-l c -w 80 -c 90、check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe等。
10)、linux 客户端的安装配置与启动
    tar zxvf nrpe-2.8.1.tar.gz
    cd nrpe-2.8.1
   ./configure –prefix=/usr/local/nrpe
    make
    make install


10.1)、添加nagios用户组,并设置权限
root@client#useradd nagios -s /sbin/nologin
chown -R nagios.nagios /usr/local/nrpe


10.2)、需要把nagios监控服务器里的/usr/local/nagios/libexec下面的5个文件cp到 /usr/local/nrpe/libexec目录下
cp /usr/local/nrpe/libexec/check_nrpe     /usr/local/nagios/libexec
cp /usr/local/nagios/libexec/check_disk    /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_load    /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_ping    /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_procs   /usr/local/nrpe/libexec




10.3)、配置nrpe.cfg文件
mkdir /usr/local/nrpe/etc 创建目录
复制nrpe解压目录下的nrpe.cfg文件以 /usr/local/nrpe/etc目录下
cp /root/nrpe/nrpe.cfg /usr/local/nrpe/etc

修改nrpe.cfg文件
server_port=5666                #端口
server_address=192.168.1.56
#服务器IP
allowed_hosts=127.0.0.1,192.168.1.56 #充许nagios服务器IP访问


10.4)启动nrpe服务
      10.4.1)、以独立守护进程启动nrpe服务
/usr/local/nrpe/bin/nrpe –c /usr/local/nrpe/etc/nrpe.cfg -d

     10.4.2)、检测nrpe服务是否正常启动
[root@nagios nrpe]# netstat -nltp | grep nrpe
tcp   0  0 192.168.1.56:5666   0.0.0.0:*       LISTEN   2233/nrpe


能查看到5666这端口,说明nrpe启动正常
11)、配置windows主机的nrpe服务
修改c:\Program Files\NSClient++\NSC.ini文件
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
CheckWMI.dll

#把前面的;分给去掉
allowed_hosts=127.0.0.1/32,192.168.1.56 #添加nagios监控服务器的IP,充许nagios服务器访问


打开nsclient++ 服务,选择属性---登陆---本地系统账户---(选择)充许服务与桌面交互,重启nsclient++服务
net stop nsclient
net start nsclient



五、启动nagios监控服务器
1)、检查配置
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Checking misc settings...
Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check



2)、启动nagios服务
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

/etc/init.d/nagios restart #重新启动nagios服务
3)、nagios监控页面如下 http://localhost/nagios

-----------------------------------------------------------------------------------------------------------------------



附件:http://down.运维网.com/data/2352401


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-664232-1-1.html 上篇帖子: nagios 监控笔记(一) 下篇帖子: nagios 监控笔记(三)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表