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

Nagios 编译安装配置

[复制链接]

尚未签到

发表于 2019-1-13 10:32:01 | 显示全部楼层 |阅读模式
安装配置Nagios
监控端
1、安装前的准备工作
(1)解决安装Nagios的依赖关系:
Nagios基本组件的运行依赖于httpd、gcc和gd。可以通过以下命令来检查nagios所依赖的rpm包是否已经完全安装:
# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server
(2)添加nagios运行所需要的用户和组:
# groupadd  nagcmd
# useradd -G nagcmd nagios
# passwd nagios
把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:
# usermod -a -G nagcmd apache
2、编译安装nagios:
# tar zxf nagios-3.3.1.tar.gz
# cd nagios-3.3.1
# ./configure –with-command-group=nagcmd –enable-event-broker
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
在httpd的配置文件目录(conf.d)中创建Nagios的Web程序配置文件:
# make install-webconf
创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用:
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
以上过程配置结束以后需要重新启动httpd:
# service httpd restart
3、编译、安装nagios-plugins
nagios的所有监控工作都是通过插件完成的,因此,在启动nagios之前还需要为其安装官方提供的插件。
# tar zxf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# make
# make install
4、配置并启动Nagios
(1)把nagios添加为系统服务并将之加入到自动启动服务队列:
# chkconfig –add nagios
# chkconfig nagios on
(2)检查其主配置文件的语法是否正确:
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
(3)如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了:
# service nagios start
(4)通过web界面查看nagios:
http://your_nagios_IP/nagios

被监控端(基于NRPE监控远程Linux主机)
1、安装配置被监控端
1)先添加nagios用户
# useradd -s /sbin/nologin nagios
2)NRPE依赖于nagios-plugins,因此,需要先安装之
# tar zxf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# make all
# make instal
3)安装NRPE
# tar -zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12.tar.gz
# ./configure –with-nrpe-user=nagios \
–with-nrpe-group=nagios \
–with-nagios-user=nagios \
–with-nagios-group=nagios \
–enable-command-args \
–enable-ssl
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
4)配置NRPE
# vim /usr/local/nagios/etc/nrpe.conf
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_address=192.168.210.12
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.210.11
command_timeout=60
connection_timeout=300
debug=0
5)启动NRPE
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
为了便于NRPE服务的启动,可以将如下内容定义为/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

6)配置允许远程主机监控的对象
在被监控端,可以通过NRPE监控的服务或资源需要通过nrpe.conf文件使用命令进行定义:
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_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3
command[check_swap]=/usr/local/nagios/libexec/check_disk -w 40% -c 20% -p /dev/shm
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
command[check_diskdisk]=/usr/local/nagios/libexec/check_diskdisk.sh
配置监控端
1)安装NRPE
# tar -zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12.tar.gz
# ./configure –with-nrpe-user=nagios \
–with-nrpe-group=nagios \
–with-nagios-user=nagios \
–with-nagios-group=nagios \
–enable-command-args \
–enable-ssl
# make all
# make install-plugin
2)定义如何监控远程主机及服务:
nagios.cfg主配置文件加一行:cfg_file=/usr/local/nagios/etc/objects/192.168.210.12.cfg
192.168.210.12.cfg内容如下:
define host{
use                     linux-server
host_name           192.168.210.12
alias                       0.12
address                 192.168.210.12
}

define service{
use                     generic-service
host_name               192.168.210.12
service_description     check_ping
check_command           check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}

define service{
use                     generic-service
host_name               192.168.210.12
service_description     check_ssh
check_command           check_ssh
max_check_attempts      5
normal_check_interval 1
notification_interval           60
}

define service{
use                     generic-service
host_name               192.168.210.12
service_description     check_http
check_command           check_http
max_check_attempts      5
normal_check_interval 1
contact_groups         common
notifications_enabled  1
notification_period   24×7
notification_options   w,u,c,r
}
define service{
use     generic-service
host_name       192.168.210.12
service_description     check_load
check_command           check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
}
define service{
use     generic-service
host_name       192.168.210.12
service_description     check_disk_sda1
check_command           check_nrpe!check_sda1
max_check_attempts 5
normal_check_interval 1
}
  





运维网声明 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-662653-1-1.html 上篇帖子: nagios4.1.1 服务端及监控端部署(二)之pnp4nagios 配置出图 下篇帖子: 一个监控磁盘的nagios脚本
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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