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

linux 5.4 nagios监控搭建

[复制链接]

尚未签到

发表于 2019-1-13 14:31:33 | 显示全部楼层 |阅读模式
nagios监控服务器   10.1.7.110
linux客户端服      10.1.7.120
windows客户端      10.1.7.119
1创建nagios组和账号
root@nagios ~]# useradd -m nagios
[root@nagios ~]# groupadd nagcmd
[root@nagios ~]# groupadd nagcmd
[root@nagios ~]# usermod -a -G nagcmd nagios
[root@nagios ~]# usermod -a -G nagcmd apache

2编译安装
[root@nagios ~]# tar xvf nagios-3.2.0.tar.gz
[root@nagios ~]# cd nagios-3.2.0
[root@nagios nagios-3.2.0]# less Makefile
[root@nagios nagios-3.2.0]# ./configure --with-command-group=nagcmd\ --with-nagios-user=nagios\ --with-nagios-group=nagios
[root@nagios nagios-3.2.0]# make all
[root@nagios nagios-3.2.0]# make install
[root@nagios nagios-3.2.0]# make install-init
[root@nagios nagios-3.2.0]# make install-config
[root@nagios nagios-3.2.0]# make install-commandmode
[root@nagios nagios-3.2.0]# make install-webconf

3为nagios设置web验证密码
root@nagios nagios-3.2.0]# htpasswd -c usr/local/nagios/etc/htpasswd.users nagiosadmin

5设置nagios的开机启动
root@nagios ~]# chkconfig --add nagios
[root@nagios ~]# chkconfig nagios on

6修改selinux
[root@nagios nagios-3.2.0]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= disable:


二  安装nagios的插件 nagios-plugin

[root@nagios ~]# tar xvf nagios-plugins-1.4.14.tar.gz
[root@nagios ~]# cd nagios-plugins-1.4.14
[root@nagios nagios-plugins-1.4.14]# ./configure --prefix=/usr/local/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios
[root@nagios nagios-plugins-1.4.14]# make && make install

检查主机是佛存在
[root@nagios ~]# cd /usr/local/nagios/etc/
[root@nagios etc]# ls -l
总计 76
-rw-rw-r-- 1 nagios nagios 11408 05-18 16:46 cgi.cfg
-rw-r--r-- 1 root   root      26 05-18 19:16 htpasswd.users
-rw-rw-r-- 1 nagios nagios 44020 05-18 18:53 nagios.cfg
-rw-r--r-- 1 nagios nagios  7207 05-18 19:33 nrpe.cfg
drwxrwxr-x 2 nagios nagios  4096 05-18 20:06 objects
-rw-rw---- 1 nagios nagios  1340 05-18 16:46 resource.cfg
[root@nagios etc]#

2主配置文件nagios。cfg配置
[root@nagios etc]# vim 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/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg  //注释掉此行

3主机定义文件配置
define host{
        host_name Nagios-server
        alias Nagios server
        address 10.1.7.110
        check_command check-host-alive
        check_interval 5
        retry_interval 1
        max_check_attempts 5
        check_period 24x7
        process_perf_data 0
        retain_nonstatus_information 0
        contact_groups sagroup
        notification_interval 30
        notification_period 24x7
        notification_options d,u,r
}


define host{
        host_name client-server
        alias client server
        address 10.1.7.120
        check_command check-host-alive
        check_interval 5
        retry_interval 1
        max_check_attempts 5
        check_period 24x7
        process_perf_data 0
        retain_nonstatus_information 0
        contact_groups sagroup
        notification_interval 30
        notification_period 24x7
        notification_options d,u,r
}

3主机组定义文件配置
[root@nagios etc]# vim objects/hostgroups.cfg
define hostgroup {
        hostgroup_name Sysem-Admin
        alias system Admin
        members Nagios-server,client-server,windows-server
}
~
4服务定义文件配置
[root@nagios etc]# vim objects/services.cfg

define service{
        host_name Nagios-server
        service_description check-host-alive
        check_period 24x7
        max_check_attempts 4
        normal_check_interval 3
        retry_check_interval 2
        contact_groups sagroup
        notification_interval 10
        notification_period 24x7
        notification_options w,c,u,r
        check_command check-host-alive
}

define service{
        host_name client-server
        service_description check-host-alive
        check_period 24x7
        max_check_attempts 4
        normal_check_interval 3
        retry_check_interval 2
        contact_groups sagroup
        notification_interval 10
        notification_period 24x7
        notification_options w,c,u,r
        check_command check-host-alive
}

5联系人定义文件配置


[root@nagios etc]# vim objects/contacts.cfg

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        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
        host_notification_commands notify-host-by-email
        email                           472730846@qq.com

6联系组定义文件配置
[root@nagios etc]# vim objects/contactgroups.cfg

define contactgroup {
       contactgroup_name sagroup
       alias system administrator group
       members nagiosadmin
}
7修改目录所有者

~
[root@nagios etc]# chown -R nagios.nagios objects/

8检查配置文件是否正却
[root@nagios etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0

9启动nagios服务
[root@nagios etc]# etc/init.d/httpd restart
[root@nagios etc]# /etc/init.d/nagios start

10 测试功能
http://10.1.7.110/nagios/ 输入 nagiosadmin 密码 accp


三 使用nagios监控linux客户端
1  nagios监控服务器的配置
[root@nagios ~]# tar zxvf nrpe-2.12.tar.gz
[root@nagios ~]# cd nrpe-2.12
[root@nagios nrpe-2.12]# ./configure && make all
[root@nagios nrpe-2.12]# make install-plugin
[root@nagios nrpe-2.12]# make install-daemon
[root@nagios nrpe-2.12]# make install-daemon-config
[root@nagios nrpe-2.12]# make install-xinetd



2 配置
[root@nagios nrpe-2.12]# vim /etc/xinetd.d/nrpe


        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 127.0.0.1,10.1.7.120,10.1.7.119

3 添加端口
[root@nagios nrpe-2.12]# vim /etc/services
nrpe            5666/tcp                          #nrpe
4 重新启动 xinetd服务
[root@nagios nrpe-2.12]# /etc/init.d/xinetd restart
[root@nagios nrpe-2.12]# netstat -na | grep 5666

以上步骤要到客户机上做 1--4
5修改配置文件commands.cfg加入对nrpe的支持
[root@nagios ~]# vim /usr/local/nagios/etc/objects/commands.cfg

#nrpe set
define command {
        command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $ HOSTADDRESS$ -c $ ARG1$
}

检查nrpe命令那些可用
[root@nagios ~]# cat /usr/local/nagios/etc/nrpe.cfg

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

7 使用命令监控客户端
[root@nagios ~]# vim /usr/local/nagios/etc/objects/services.cfg

define service{
        host_name Nagios-server
        service_description check-users
        check_period 24x7
        max_check_attempts 4
        normal_check_interval 3
        retry_check_interval 2
        contact_groups sagroup
        notification_interval 10
        notification_period 24x7
        notification_options w,c,u,r
        check_command check-nrpe!check_users
}

define service{
        host_name Nagios-server
        service_description check-load
        check_period 24x7
        max_check_attempts 4
        normal_check_interval 3
        retry_check_interval 2
        contact_groups sagroup
        notification_interval 10
        notification_period 24x7
        notification_options w,c,u,r
        check_command check-nrpe!check_load
}

define service{
        host_name Nagios-server
        service_description check-total-procs
        check_period 24x7
        max_check_attempts 4
        normal_check_interval 3
        retry_check_interval 2
        contact_groups sagroup
        notification_interval 10
        notification_period 24x7
        notification_options w,c,u,r
        check_command check-total_procs
}

  





运维网声明 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-662819-1-1.html 上篇帖子: centos6.5 nagios 下篇帖子: nagios监控失败报错It appears as though you do not have..
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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