nagios3.2.0搭建过程
很久没有更新博客了,记录下我在生产环境下安装nagios3.2.0,
创新互联-专业网站定制、快速模板网站建设、高性价比德州网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式德州网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖德州地区。费用合理售后完善,十载实体公司更值得信赖。
一、nagios 的安装
1.1 基础支持套件
1)gcc glibc glibc-common gd gd-devel xinetd openssl-devel
# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
2)部署lamp环境 yum install httpd MySQL mysql-server php php-mysql -y ,或源码安装
1.2 创建nagios用户和用户组
# /usr/sbin/useradd -m nagios
# /usr/sbin/useradd apache -M -s /sbin/nologin
# /usr/sbin/groupadd nagcmd
# /usr/sbin/usermod -a -G nagcmd nagios
# /usr/sbin/usermod -a -G nagcmd apache
1.3 编译安装nagios
# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.0/nagios-3.2.0.tar.gz/download
# tar zxvf nagios-3.2.0.tar.gz
# cd nagioss-3.2.0
# ./configure --prefix=/usr/local/nagios --with-group=nagios --with-user=nagios --with-command-group=nagcmd
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
验证程序是否被正确安装
切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var 这五个目录,
1.4 设置开机自起
# chkconfig --add nagios
# chkconfig nagios on
1.5 安装nagios插件
# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
# tar zxvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
# make && make install
1.6 创建apache目录验证文件
# htpasswd -c /usr/local/nagios/etc/htpasswd nagios
1.7 给nagios用户开权限,让他能够查看信息
# vim /usr/local/nagios/etc/cgi.cfg 在所有的nagiosadmin后面添加nagios用,隔开
:%s/nagiosadmin/nagiosadmin\,nagios/g
到这里nagios 的安装也就基本完成了,启动apache,你可以通过web来访问了
1.8 定义监控项 在/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 0.0.0.0
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
}
1.9 检查错误
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
二、监控远程主机nrpe插件的安装(被监控主机上的)
2.1 解决perl编译问题与时间同步
# echo "export LC_ALL=C">>/etc/profile
# source /etc/profile
# /usr/sbin/ntpdate pool.ntp.org
# uptime
2.2 安装Nagios所需要的基础软件包
# yum install gcc glibc glibc-common gd gd-devdel openssl-devel -y
2.3 建立nagios用户
# useradd nagios
2.4 安装插件
# tar zxvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
# make && make install
2.5 安装NRPE
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
# tar zxvf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure
# make all
# make install-plugin #监控机需要安装check_nrpe 这个插件,被监控机并不需要,
# make install-daemon
# make install-daemon-config
# make install-xinetd
2.6 在被监控机上开启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,保证他可以连接进来!
}
2.7 编辑/etc/services 文件,增加NRPE服务
# vim /etc/services
nrpe 5666/tcp
# service xinetd restart
2.8 查看NRPE是否启动与测试
# netstat -an |grep 5666
# /usr/local/nagios/libexec/check_nrpe -H 192.168.18.188
NRPE v2.12 返回当前NRPE的版本 也就是在本地用check_nrpe连接nrpe daemon是正常的。
注:为了后面工作的顺利进行,注意本地防火墙要打开5666能让外部的监控机访问。
# iptables -I INPUT -p tcp --dport 5666 -j ACCEPT
2.9 查看NRPE的监控命令
# vim /usr/local/nagios/etc/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
通过以上字段来定义命令,以及接收命令后执行的插件。
重启nagios服务
分享题目:nagios3.2.0搭建过程
文章路径:http://myzitong.com/article/jeisoc.html