[root@server1 nagios]# 1 安装yum install gd-devel -y
[root@server1 nagios]# 2 部署lamp环境yum install httpd mysql mysql-server php php-mysql gcc gcc-c++ -y
[root@server1 nagios]# 3 安装主程序nagios
[root@server1 nagios]# tar fvxz nagios.tar.gz
[root@server1 nagios]# ./configure --prefix=/usr/local/nagios
[root@server1 nagios]# useradd nagios
[root@server1 nagios]# make all
[root@server1 nagios]# make install
make install
     - This installs the main program, CGIs, and HTML files

make install-init
     - This installs the init script in /et c/rc.d/init.d

make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

make install-webconf
     - This installs the Apache config file for the Nagios
       web interface

vim /etc/httpd/conf/httpd.conf
User nagios
Group nagios

重新启动apache
service httpd restart
                                                                                                                                     service nagios start
生成用户
[root@server1 nagios-3.2.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosm
New password: 
Re-type new password: 
Adding password for user nagios

给nagios用户开权限,让他能够查看信息!
[root@server1 nagios-3.2.0]# vim /usr/local/nagios/etc/cgi.cfg 
在所有的nagiosadmin后面添加nagios

本机为什么是down的状态???

监控分析控制台   ---------------主程序
                插件
               --------------被监控主机
nagios报错 无权查看任何主机的信息  解决方法

解决办法:

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

将use_authentication的值改为0.

use_authentication=0

然后重启nagios服务

service nagios restart

[root@server1 libexec]# pwd
/usr/local/nagios/libexec
[root@server1 libexec]# ls
[root@server1 libexec]# 
插件目录下什么没有有阿!

安装插件
[root@server1 nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios/ -
可选的选项--with-gnutls --with-openssl --enable-extra-opts --enable-perl-modules

make

make install

怎样监控的更多!

[root@server1 etc]# pwd
/usr/local/nagios/etc
[root@server1 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/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

通过上面的语句来调用那些配置文件
[root@server1 objects]# pwd
/usr/local/nagios/etc/objects

时间timeperiods.cfg
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
        }

插件commands.cfg
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
        }

监控谁localhost.cfg
define host {
        host_name       fudong
        alias           test
        address         192.168.18.50
        check_command   check-host-alive
        notification_options    d,u,r
        check_interval  1
        max_check_attempts      2
        contact_groups  admins
        notification_interval   10
        notification_period     24x7
}

联系人contacts.cfg

define contact {
        contact_name  kyo
        alias           kyo
        host_notification_period        24x7
        host_notification_options       d,u,r
        service_notification_period     24x7
        service_notification_options    w,u,c,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email   root@163.com
#通过飞信机器人发信报警!
}

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin,kyo
        }

检查错误
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

定义服务
define service {
        host_name       fudong
        service_description     apache
        check_period    24x7
        normal_check_interval   2
        retry_check_interval    1
        max_check_attempts      5 
        notification_period     24x7
        notification_options    w,u,c,r
        check_command   check_http

}

关于插件的返回状态
[root@server1 objects]# echo $?
2
[root@server1 objects]# /usr/local/nagios/libexec/check_http -I 192.168.18.50
HTTP OK HTTP/1.1 200 OK - 43306 bytes in 0.026 seconds |time=0.026288s;;;0.000000 size=43306B;;;0
[root@server1 objects]# echo $?
0
[root@server1 objects]# /usr/local/nagios/libexec/check_http -I 192.168.18.50 -u /a.html -s hello
HTTP WARNING: HTTP/1.1 404 Not Found
[root@server1 objects]# echo $?
1

0 成功  1 警告  2 严重错误  3 未知 
自己编写插件!!!!!!!!!!!!!!!!
#!/bin/bash

curl -I http://192.168.18.155 &> /dev/null

if [ $? -eq 0 ]; then
        ( curl -I http://192.168.18.155 | grep 'HTTP/1.1 200' ) &> /dev/null
        if [ $? -eq 0 ];then
                echo "OK!"
                exit 0
        else
                echo "warning!"
                exit 1
        fi
else
        echo "down!"
        exit 2
fi

自定义命令
define command {
        command_name    check_url
        command_line    $USER1$/check_http -I $HOSTADDRESS$ -u $ARG1$ -s $ARG2$
}

使用新定义的命令

define service {
        host_name       fudong
        service_description     apache
        check_period    24x7
        normal_check_interval   2
        retry_check_interval    1
        max_check_attempts      5
        notification_period     24x7
        notification_options    w,u,c,r
#       check_command   check_http
        check_command   check_url!/index.html!hello

}

########################################################################
check_mysql
vim /usr/local/nagios/libexec/check_mysql
#!/bin/bash
#check_mysql status
IP=$1

mysql -u test -h $IP -p123 -e 'show databases;' &> /dev/null

if [ $? -eq 0 ]; then
        echo "mysql OK!"
        exit 0;
else
        echo "mysql err!"                                                                                                                                          
        exit 2;
fi

vim /usr/local/nagios/etc/objects/commands.cfg
define command{
        command_name check_mysql
        command_line $USER1$/check_mysql $ARG1$
}

vim /usr/local/nagios/etc/objects/localhost.cfg
define service {
        host_name       mail.vfast.com
        service_description     mysql
        check_period    24x7
        normal_check_interval   2
        retry_check_interval    1
        max_check_attempts      2
        notification_period     24x7
        notification_options    w,u,c,r
        check_command   check_mysql!192.168.18.69
}

service nagios restart

###################################################################################

yum install expect -y

define command{
        command_name    notify-host-by-sms
        command_line    /usr/local/nagios/libexec/nagios-mail "$(/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n")"  smtp.163.com  Y29vbHdhbmdjaG9uZ0AxNjMuY29t  UVE4MTBXQU5HODIwMCFA  coolwangchong@163.com $CONTACTEMAIL$  "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"
        }

如果遇到host条目一会有,一会消失的问题,可以killall nagios 再重新启动nagios!

监控远程主机的系统信息
被监控主机
安装nrpe的server端
tar fvxz nrpe*.tar.gz
./configure --prefix=/usr/local/nagios
useradd nagios
make

make install-daemon

make install-daemon-config

make install-xinetd

安装插件2
make install (这步不是必须的!)
把插件拷贝给监控主机nagios
scp /usr/local/nagios/libexec/check_nrpe   root@监控主机的ip:/usr/local/nagios/libexec

在被监控主机开启nrpe服务
vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe

{
        flags           = REUSE
        socket_type     = stream    
        port            = 5666    
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 192.168.18.254  #监控主机的ip,保证他可以连接进来!
}

vim /etc/services 
nrpe 5666/tcp

service xinetd restart

[root@server1 objects]# /usr/local/nagios/libexec/check_nrpe -H 192.168.18.188
NRPE v2.12

#注意关闭防火墙!

在被监控主机安装插件

vim nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_u]=/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

通过以上字段来定义命令,以及接收命令后执行的插件

如果想不明白

定义服务,来检测一下
define host {
        host_name       zcg
        alias           nrpe-server
        address         192.168.18.188
        check_command   check-host-alive
        notification_options    d,u,r
        check_interval  1
        max_check_attempts      2
        contact_groups  admins
        notification_interval   10
        notification_period     24x7
}

define service {
        host_name       zcg
        service_description     nrpe
        check_period    24x7
        normal_check_interval   2
        retry_check_interval    1
        max_check_attempts      5
        notification_period     24x7
        notification_options    w,u,c,r
        check_command   check_nrpe!check_users
#这里定义的check_nrpe需要在command.cfg里面定义
}
别忘了,先定义好zcg这台主机!!

定义命令
define command {
        command_name    check_nrpe
        command_line    /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

重启nagios服务!

转载于:https://blog.51cto.com/sxlfxx/1380822

nagios监控安装及设置案例相关推荐

  1. 3dmax:3dmax三维VR渲染设置之摄像机设置案例应用之自由摄影打造动画效果之图文教程

    3dmax:3dmax三维VR渲染设置之摄像机设置案例应用之自由摄影打造动画效果之图文教程 目录 自由摄影打造动画效果之图文教程

  2. 【GlobalMapper精品教程】039:GM面状数据符号化设置案例教程

    GM面状数据符号化设置案例教程. 文章目录 一.使用基于分类或自定义样式的默认样式 二.对所有要素使用相同样式 三.基于属性/名称值应用样式 四.随机指定颜色给要素 一.使用基于分类或自定义样式的默认 ...

  3. 3dmax:3dmax三维VR渲染设置之摄像机设置案例应用之利用3dmax Vary制作全景渲染图的图文教程

    3dmax:3dmax三维VR渲染设置之摄像机设置案例应用之利用3dmax Vary制作全景渲染图的图文教程 目录 利用3dmax Vary制作全景渲染图的图文教程 (1).新建一个摄像机 (2).全 ...

  4. nagios监控安装

    #以前做的笔记,现在自己都看不懂了,日后用再研究吧. 一.Nagios服务端安装: 基础支持套件: #rpm -q gcc glibc glibc-common gd gd-devel xinetd ...

  5. nagios 整合 ganglia 设置邮件、短信报警

    要学的东西还有很多呢,慢慢来~! 环境: 操作系统:ubuntu 10.10 软件:ganglia-monitor 3.1.7-1,gmetad 3.7.1-1,nagios 3.2.1-2 步骤: ...

  6. nagios监控安装配置文档+139邮箱报警

    Linux+apache+mysql+php+nagios监控服务搭建 参考了很多文档总结出来的一个比较完整的nagios服务的搭建: nagios是一款开源监控软件,运行在LINUX/UNIX平台, ...

  7. Proface触摸屏按钮互锁、弹出窗口、密码设置、报警设置案例

    1. 按钮互锁 2. 弹出窗口设置 3. 密码设置:通用设置安全 4. 报警设置:通用设置报警设置,可选择不同的块触发报警,用于区分重报警和轻报警 最后向大家推荐一个PLC和自动化相关技术的学习平 ...

  8. H3C ER3200双WAN口设置案例图解

    方法一: 1.启用DHCP,设置好地址池(方便客户端获取到同网段IP,启用后,客户端还会是默认的192.168.1.0网段) 2.设置LAN信息,完成后,PC会与路由失去连接,重新启用网卡,即可再次登 ...

  9. 【QGIS入门实战精品教程】7.1:QGIS面状数据符号化设置案例教程

    本文讲解QGIS空间数据符号化设置. 文章目录 一.符号化模式详解 1. 单一色彩 2. 字段分类 3. 渐进 4. 基于规则 5. 翻转多边形 6. 2.5维 二.样式文件的保存与使用 1. 保存样 ...

最新文章

  1. android开发岗_android应用开发
  2. kubesphere发布应用到应用商店完整步骤
  3. SAP云平台上的ABAP编程环境能做哪些事情
  4. 标题、段落标签(HTML)
  5. python3.8.5-Python 3.8.5下载
  6. vivado和modelsim联合仿真实现分频器——2的n次方分频
  7. 190306每日一句
  8. Atitit 互操作之道 接口之道 attilax著
  9. Java中的各种数据类型的转换
  10. [转载]视频格式介绍
  11. 每秒50W笔交易,阿里双十一,架构如何优化到极致!
  12. 【JS从入门到精通】09-数组
  13. MYSQL 列转行方法
  14. MySql查询某一天的数据
  15. 实训周实验(eNSP安装+简单使用+实验项目)总结
  16. 软考中级软件设计师 2009-2022年真题
  17. 第一节 花的结构和类型
  18. 程序员学完深入理解计算机系统,深入理解计算机系统9个重点笔记
  19. 中国核电项目工程师圆满完成友勤2018年第七期P6软件培训课程。
  20. 「微信同声传译」小程序插件:快速实现语音转文字、文本翻译、语音合成等能力...

热门文章

  1. python简单例子lof_Python的净值数据接口调用示例分享
  2. php fpm子进程数配置,php-fpm进程管理方式以及子进程数量配置原则详解
  3. android 代码功能测试,Android触屏测试实例代码
  4. 在线HTML网页小窗口复制不了,教你一招:解决某些网页不能复制的文字的N种方法!...
  5. Spring mvc 参数类型转换
  6. win与Linux的防火墙配置
  7. go数据结构与算法| 稀疏数组
  8. c++ eos智能合约开发_hyperledger fabric 开发第一个智能合约
  9. 央采数据库集采:甲骨文、微软、腾讯、阿里等 21 家中标
  10. VMware产品演示网站