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

centos 6.4x64安装部署nagios

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-5-26 08:54:23 | 显示全部楼层 |阅读模式
一、nagios概述

    Nagios是插件式的结构,它本身没有任何监控功能,所有的监控都是通过插件进行的,因此其是高度模块化和富于弹性的。Nagios监控的对象可分为两类:主机和服务。主机通常指的是物理主机,如服务器、路由器、工作站和打印机等,这里的主机也可以是虚拟设备,如xen虚拟出的Linux系统;而服务通常指某个特定的功能,如提供http服务的httpd进程等。而为了管理上的方便,主机和服务还可以分别被规划为主机组和服务组等。
    Nagios不监控任何具体数值指标(如操作系统上的进程个数),它仅用四种抽象属性对被监控对象的状态进行描述:OK、WARNING, CRITICAL和UNKNOWN。于是,管理员只需要对某种被监控对象的WARNING和CRITICAL状态的阈值进行关注和定义即可。Nagios通过将WARTING和CRTICAL的阈值传递给插件,并由插件负责某具体对象的监控及结果分析,其输出信息为状态信息(OK,WARNING,CRITICAL或UNKOWN)以及一些附加的详细说明信息。

二、环境
    系统:centos 6.4x64最小化安装

    nagios-server: 192.168.3.71

    nagios-client: 192.168.3.72

三、安装nagios
    Nagios通常由一个主程序(Nagios)、一个插件程序(Nagios-plugins)和四个可选的ADDON(NRPE、NSCA、NSClient++和NDOUtils)组成。Nagios的监控工作都是通过插件实现的,因此,Nagios和Nagios-plugins是服务器端工作所必须的组件。而四个ADDON中,NRPE用来在监控的远程Linux/Unix主机上执行脚本插件以实现对这些主机资源的监控;NSCA用来让被监控的远程Linux/Unix主机主动将监控信息发送给Nagios服务器(这在冗余监控模式中特别要用到);NSClient++是用来监控Windows主机时安装在Windows主机上的组件;而NDOUtils则用来将Nagios的配置信息和各event产生的数据存入数据库,以实现这些数据的快速检索和处理。这四个ADDON(附件)中,NRPE和NSClient++工作于客户端,NDOUtils工作于服务器端,而NSCA则需要同时安装在服务器端和客户端。
    目前,Nagios只能安装在Linux系统主机上,其编译需要用到gcc。同时,如果打算使用web界面的管理工具的话,还需要有apache服务器和GD图形库的支持

    安装nagios依赖关系

1
[iyunv@nagios-server ~]# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server ntp



    同步时间

1
2
3
4
5
6
[iyunv@nagios-server ~]# ntpdate asia.pool.ntp.org
25 May 10:45:35 ntpdate[22419]: step time server 118.67.201.10 offset 140.952903 sec
[iyunv@nagios-server ~]# hwclock -w
[iyunv@nagios-server ~]# crontab -l
MAILTO=""
*/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org



    添加nagios运行需要的用户和组

1
2
[iyunv@nagios-server ~]# groupadd  nagcmd
[iyunv@nagios-server ~]# useradd -G nagcmd nagios



    把apache添加到

1
[iyunv@nagios-server ~]# usermod -a -G nagcmd apache



    下载nagios,并安装

1
2
3
4
5
6
7
8
9
10
[iyunv@nagios-server ~]# wget http://sourceforge.net/projects/ ... 3.1.tar.gz/download
[iyunv@nagios-server ~]# tar xf nagios-3.3.1.tar.gz
[iyunv@nagios-server ~]# cd nagios
[iyunv@nagios-server nagios]# ./configure --with-command-group=nagcmd --enable-event-broker
[iyunv@nagios-server nagios]# make all                   #安装所有主程序
[iyunv@nagios-server nagios]# make install               #安装主程序,CHI和HTML文件
[iyunv@nagios-server nagios]# make install-init          #安装启动脚本
[iyunv@nagios-server nagios]# make install-commandmode   #配置目录权限
[iyunv@nagios-server nagios]# make install-config        #安装示例文件
[iyunv@nagios-server nagios]# make install-webconf       #安装nagios的web站点配置文件



    为nagios配置告警信息的邮件地址

1
2
3
4
5
6
7
#编辑文件前,先备份
[iyunv@nagios-server nagios]# cp /usr/local/nagios/etc/objects/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg.$(date +%F).bak

#邮箱地址修改成自己要设置的地址
[iyunv@nagios-server nagios]# sed -i 's#nagios@localhost#lyao@weyee.com#' /usr/local/nagios/etc/objects/contacts.cfg
[iyunv@nagios-server nagios]# grep lyao@weyee.com  /usr/local/nagios/etc/objects/contacts.cfg
        email                           lyao@weyee.com   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******



    创建一个登陆验证的用户和密码

1
2
#这里设置密码weyee2014
[iyunv@nagios-server nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin



    关闭iptables和启动httpd

1
2
[iyunv@nagios-server nagios]# service iptables stop
[iyunv@nagios-server nagios]# service httpd start



    安装nagios-plugins
1
2
3
4
5
6
#下载nagios-plugins
[iyunv@nagios-server ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
[iyunv@nagios-server ~]# tar xf nagios-plugins-2.0.3.tar.gz
[iyunv@nagios-server ~]# cd nagios-plugins-2.0.3
[iyunv@nagios-server nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[iyunv@nagios-server nagios-plugins-2.0.3]# make && make install



    配置nagios启动级别

1
2
3
4
5
6
7
8
9
10
11
#将nagios添加到开机自启动
[iyunv@nagios-server ~]# chkconfig --add nagios
[iyunv@nagios-server ~]# chkconfig nagios on

#检查配置文件
[iyunv@nagios-server ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[iyunv@nagios-server ~]# service nagios start
Starting nagios: done.
[iyunv@nagios-server ~]# ps aux |grep nagios
nagios   45840  0.0  0.1  28048  1396 ?        Ssl  11:25   0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
root     45852  0.0  0.0 103248   832 pts/0    S+   11:25   0:00 grep nagios



    访问http://192.168.3.71/nagios,用户名和密码是上文中设置的nagiosadmin:weyee2014
wKiom1VilvjQa-lYAAZTSwYNjbg238.jpg
四、安装NRPE
    NRPE需要nagios-pluin的支持

1
2
3
4
5
6
7
8
[iyunv@nagios-server ~]# wget http://sourceforge.net/projects/ ... .15.tar.gz/download
[iyunv@nagios-server ~]# tar xf nrpe-2.15.tar.gz
[iyunv@nagios-server ~]# cd nrpe-2.15
[iyunv@nagios-server nrpe-2.15]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[iyunv@nagios-server nrpe-2.15]# make all
[iyunv@nagios-server nrpe-2.15]# make install-plugin
[iyunv@nagios-server nrpe-2.15]# make install-daemon
[iyunv@nagios-server nrpe-2.15]# make install-daemon-config



    配置NRPE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#编辑NRPE的配置文件
[iyunv@nagios-server ~]# egrep -v "^$|^#" /usr/local/nagios/etc/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
server_address=192.168.3.71        #修改这里
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.3.0/24       #修改这里
  
dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
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



    启动NRPE

1
2
3
[iyunv@nagios-server ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[iyunv@nagios-server ~]# netstat -anpt |grep 5666
tcp        0      0 192.168.3.71:5666           0.0.0.0:*                   LISTEN      48946/nrpe



    编写NRPCE的启动脚本,将脚本放到/etc/init.d路径下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[iyunv@nagios-server ~]# cat /etc/init.d/nrped
#!/bin/bash
# chkconfig: 2345 88 12
# description: NRPE DAEMON

NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg

case "$1" in
    start)
        echo -n "Starting NRPE daemon..."
        $NRPE -c $NRPECONF -d
        echo " done."
        ;;
    stop)
        echo -n "Stopping NRPE daemon..."
        pkill -u nagios nrpe
        echo " done."
    ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart"
        ;;
esac
exit 0
#赋予脚本权限,并测试
[iyunv@nagios-server ~]# chmod +x /etc/init.d/nrped
[iyunv@nagios-server ~]# chkconfig --add nrped
[iyunv@nagios-server ~]# chkconfig nrped on
[iyunv@nagios-server ~]# service nrped stop
Stopping NRPE daemon... done.
[iyunv@nagios-server ~]# netstat -anpt |grep nrpe
[iyunv@nagios-server ~]# pidof nrpe
#重新启动nrpe
[iyunv@nagios-server ~]# service nrped start
Starting NRPE daemon... done.
[iyunv@nagios-server ~]# netstat -anpt |grep nrpe
tcp        0      0 192.168.3.71:5666           0.0.0.0:*                   LISTEN      49019/nrpe         
[iyunv@nagios-server ~]# pidof nrpe
49019
[iyunv@nagios-server ~]# ps aux |grep nrpe |grep -v grep
nagios   49019  0.0  0.1  39240  1312 ?        Ss   11:53   0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d



五、在客户端安装NRPE
    在nagios-client上安装NRPE,需要先安装nagios-plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@nagios-client ~]# yum install ntpdate gcc*  openssl openssl-devel -y
[iyunv@nagios-client ~]# ntpdate asia.pool.ntp.org
25 May 13:52:18 ntpdate[22302]: step time server 212.26.18.41 offset 2955.354923 sec
[iyunv@nagios-client ~]# hwclock -w
[iyunv@nagios-client ~]# crontab -l
MIALTO=""
*/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org
[iyunv@nagios-client ~]# useradd -s /sbin/nologin nagios
[iyunv@nagios-client ~]#  wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
[iyunv@nagios-client ~]# tar xf nagios-plugins-2.0.3.tar.gz
[iyunv@nagios-client ~]# cd nagios-plugins-2.0.3
[iyunv@nagios-client nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[iyunv@nagios-client nagios-plugins-2.0.3]# make all
[iyunv@nagios-client nagios-plugins-2.0.3]# make install



    安装NRPE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[iyunv@nagios-client ~]# wget http://sourceforge.net/projects/ ... .15.tar.gz/download
[iyunv@nagios-client nrpe-2.15]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[iyunv@nagios-client nrpe-2.15]# make all
[iyunv@nagios-client nrpe-2.15]# make install-plugin
[iyunv@nagios-client nrpe-2.15]# make install-daemon
[iyunv@nagios-client nrpe-2.15]# make install-daemon-config
#修改配置文件
[iyunv@nagios-client nrpe-2.15]# egrep -v "^#|^$" /usr/local/nagios/etc/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
server_address=192.168.3.72            #监控本机哪个IP
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.3.71             #允许哪个IP对本机进行监控
#编写nrpe启动脚本
[iyunv@nagios-client ~]# cat /etc/init.d/nrped
#!/bin/bash
# chkconfig: 2345 88 12
# description: NRPE DAEMON

NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg

case "$1" in
    start)
        echo -n "Starting NRPE daemon..."
        $NRPE -c $NRPECONF -d
        echo " done."
        ;;
    stop)
        echo -n "Stopping NRPE daemon..."
        pkill -u nagios nrpe
        echo " done."
    ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart"
        ;;
esac
exit 0
[iyunv@nagios-client ~]# chmod +x /etc/init.d/nrped
[iyunv@nagios-client ~]# chkconfig --add nrped
[iyunv@nagios-client ~]# chkconfig nrped on
[iyunv@nagios-client ~]# service nrped start
Starting NRPE daemon... done.
[iyunv@nagios-client ~]# netstat -anpt |grep nrpe
tcp        0      0 192.168.3.72:5666           0.0.0.0:*                   LISTEN      46882/nrpe



    到此nagios和客户端的安装已完成

运维网声明 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-70748-1-1.html 上篇帖子: nagios监控实例 下篇帖子: nagios+pnp4nagios+rrdtool报警阈值问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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