很久没有更新博客了,记录下我在生产环境下安装nagios3.2.0,
一、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

