首页 > 代码库 > Nagios安装说明
Nagios安装说明
*****Nagios安装思路*****详情参照55DAY*****
一、Nagios服务端安装
1、安装所需依赖关系包
2、添加Nagios所需用户及组
3、编译安装Nagios及创建登陆Nagios WEB程序用户
4、Nagios-plugin(插件)
5、配置服务自启动
二、基于NRPE配置Nagios监控Win主机
1、被监控端
安装:NSClient++-0.3.9-x64
2、监控端
1.测试与被监控端连通性
2.监控端定义命令、定义主机、定义服务
3.将定义好的模板加入到nagios.cfg文件中
4.重启服务
三、基于NRPE监控Linux主机
1、被监控端:
1.添加用户
2.安装插件nagios-plugins-1.4.15
3.安装NRPE
4.配置NRPE配置文件
#vi /usr/local/nagios/etc/nrpe.cfg
5.定义nrpe启动脚本且增加权限
6.添加自启动
7.启动服务
2、配置监控端:
1.安装NRPE
安装完成后,生成check_nrpe,使用此插件进行测试被监控主机
2.定义命令
3.定义主机和服务
4.将定义好的linhost.cfg配置文件的路径添加至/usr/localhost/etc/nagios.cfg中
5.测试配置文件 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
6.重启服务
7.网页检查hosts监控状况
******另关于基于NRPE监控windows主机,另行查询网上资料******
一、安装配置Nagios
1、解决安装Nagios的依赖关系:
# 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
# usermod -a -G nagcmd apache
3、编译安装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
# vi /usr/local/nagios/etc/objects/contacts.cfg
emailnagios@localhost #这个是默认设置
# make install-webconf
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# service httpd restart
4、编译、安装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
# make install
5、配置并启动Nagios
#vi /usr/local/nagios/etc/nagios.cfg
# chkconfig --add nagios
# chkconfig nagios on
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# service nagios start
6、配置selinux
#getenforce
#setenforce 0
7、通过web界面查看nagios:
http://your_nagios_IP/nagios
登录时需要指定前面设定的web认证帐号和密码。
二、配置文件
Nagios的主配置文件
/usr/local/nagios/etc/nagios.cfg
Nagios模板配置目录
/usr/local/nagios/etc/objects
调用check命令目录/usr/local/nagios/libexec
三、基于NSClinet++ 监控远程Win主机
1、安装配置被监控端
安装NSClient++-0.3.9-x64
2、进行测试是否连通
#cd /usr/local/nagios/libexec
#./check_nt -H 192.168.1.119 -v UPTIME -p 12489
如有密码则:#./check_nt -H 192.168.1.119 -v UPTIME -p 12489 -s luoxj,123
3、监控端进行配置
&&&定义commands.cfg-------------------定义命令
#cd /usr/local/nagios/etc/objects/
#vi commands.cfg
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
}
&&&定义主机及服务
#vi windows.cfg
define host{
use windows-server
host_name winhost
alias My Windows Host
address 192.168.1.119
}
define service{ use generic-service host_name winhost service_description NSClient++ Version check_command check_nt!CLIENTVERSION }定义服务可根据实际情况进行变更名称可使用vim中替换进行:.,$s@winserver@winhost@g
&&&启用定义的文件,增加定义文件路径
#vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
&&&进行测试,以确定配置文件没有问题
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -d
#service nagios restart
四、基于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=172.16.100.11
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=172.16.100.1
command_timeout=60
connection_timeout=300
debug=0
&&&&&&&&定义监控对象命令&&&&&&&&&
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_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
5)启动NRPE
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
为了便于NRPE服务的启动,可以将如下内容定义为/etc/init.d/nrped脚本:
#vi /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
#chmod +x /etc/init.d/nrped
#service nrped start
#netstat -tnlp ##检查nrpe端口5666是否启用
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17282/nrpe
#service iptables stop
#setenforce 0
6)配置允许远程主机监控的对象
在被监控端,可以通过NRPE监控的服务或资源需要通过nrpe.conf文件使用命令进行定义,定义命令的语法格式为:command[<command_name>]=<command_to_execute>。比如:
command[check_rootdisk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_swap]=/usr/local/nagios/libexec/check_disk -w 40% -c 20%
command[check_sensors]=/usr/local/nagios/libexec/check_sensors
command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 20
command[check_load]=/usr/local/nagios/libexec/check_load -w 10,8,5 -c 20,18,15
command[check_zombies]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_all_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
2、配置监控端
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
安装完成后,/usr/local/nagios/libexec/check_nrpe就会生成此插件,可测试客户端工作正常于否
#cd /usr/local/nagios/libexec/
#./check_nrpe -H 192.168.1.124
NRPE v2.12
2)定义如何监控远程主机及服务:
通过NRPE监控远程Linux主机要使用chech_nrpe插件进行,其语法格式如下:
check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]
定义监控远程Linux主机的命令:
#vi /usr/local/nagios/etc/objects/commands.cfg 添加nrpe命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
************建立模板文件******************
#cd /usr/local/nagios/etc/objects/
#vim linhost.cfg 或是 #cp localhost.cfg linhost.cfg
***定义远程Linux主机:
define host{
use linux-server
host_name linhost
alias my Linux Host
address 192.168.1.124
}
如主机组不需要则注释,添加服务可参照被监控端/usr/local/nagios/etc/nrpe.cfg中的command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 进行详细配置服务 ***定义远程Linux服务:也可以在后加参数进行设定监控
define service{
use generic-service host_name linhost service_description check_users check_command check_nrpe!check_users }# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined abovedefine service{ use generic-service host_name linhost service_description load check_command check_nrpe!check_load }# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined abovedefine service{ use generic-service host_name linhost service_description sda1 check_command check_nrpe!check_sda1 }# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined abovedefine service{ use generic-service host_name linhost service_description Zombie check_command check_nrpe!check_zombie_procs }define service{ use generic-service host_name linhost service_description Total procs check_command check_nrpe!check_total_procs }3)将设定好的linhost.cfg文件添加至/usr/local/nagios/etc/nagios.cfg中#vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/linhost.cfg
4)进行测试配置文件 # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg5)重启服务#service nagios restart
本文出自 “Linux-Study” 博客,请务必保留此出处http://luoxj100.blog.51cto.com/6853880/1887396
Nagios安装说明