nagios core安装
准备:
yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel
1.Create Account Information
创建nagios用户,并设置密码:
/usr/sbin/useradd -m nagios
passwd nagios
创建nagcmd用户组,并把用户nagios和apache添加到该组:
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
2.下载nagios和plugins
cd /usr/local/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
3.编译、安装nagios
cd /usr/local/src
tar zxzf nagios-3.4.1tar.gz
cd nagios-3.4.1
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
到这里先别启动nagios,还有许多配置需要更改。
4.Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample
files should work fine for getting started with Nagios. You’ll need to make just one change before you
proceed...
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email
address associated with the nagiosadmin contact definition to the address you’d like to use for receiving
alerts.
修改需要接受告警日志的email地址:
vi /usr/local/nagios/etc/objects/contacts.cfg
5.Configure the Web Interface
make install-webconf
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you
assign to this account - you’ll need it later.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache to make the new settings take effect.
service httpd restart
chkconfig httpd on
6.编译、安装“nagios plugins”
cd /usr/local/src
tar xzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
注:如果在执行configure的时候卡在如下位置:
checking where the gettext function comes from... libc
configure: See http://nagiosplugins.org/faq/compile/configure_appears_to_hang if this next part takes a long time
checking for redhat spopen problem...
可以在configure的时候加上“--enable-redhat-pthread-workaround”参数。
7.启动nagios
chkconfig --add nagios
chkconfig nagios on
Verify the sample Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, start Nagios.
service nagios start
8.selinux设置(selinux若已关闭,可忽略)
See if SELinux is in Enforcing mode.
getenforce
Put SELinux into Permissive mode.
setenforce 0
To make this change permanent, you’ll have to modify the settings in /etc/selinux/config and reboot.
Instead of disabling SELinux or setting it to permissive mode, you can use the following command to
run the CGIs under SELinux enforcing/targeted mode:
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
9.登陆web界面:
用户名/密码:naigiosadmin/nagiosadmin
nagios客户端配置:
1.创建nagios用户:
/usr/sbin/useradd nagios
passwd nagios
2.安装nagios插件:
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.6.tar.gz
cd /usr/local/src
tar -zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec
3.安装NRPE服务:
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
cd /usr/local/src
tar -zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
4.编辑配置文件:/etc/init.d/nrpe、/etc/services、
Edit the /etc/xinetd.d/nrpe file and add the IP address of the monitoring server to the only_from directive.
user = oracle
only_from = 10.128.64.X <nagios_ip_address>
Add the following entry for the NRPE daemon to the /etc/services file.
nrpe 5666/tcp # NRPE
Restart the xinetd service.
service xinetd restart
检查端口是否存在:
netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
注:
1.配置完成后提示:CHECK_NRPE: Error - Could not complete SSL handshake.
修改配置check_oracle脚本。将$ORACLE_HOME及$PATH手动加入,避免出现问题:
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
ORACLE_HOME=/opt/oracle/product/10.2.0
PATH=$PATH:$ORACLE_HOME/bin
2.Cannot determine ORACLE_HOME for sid orcl
在下列位置添加“ORACLE_HOME”
ORACLE_HOME=/opt/oracle/product/10.2.0
# Hunt down a reasonable ORACLE_HOME
if [ -z "$ORACLE_HOME" ] ; then
# Adjust to taste
for oratab in /var/opt/oracle/oratab /etc/oratab
do
[ ! -f $oratab ] && continue
ORACLE_HOME=`IFS=:
while read SID ORACLE_HOME junk;
do
if [ "$SID" = "$2" -o "$SID" = "*" ] ; then
echo $ORACLE_HOME;
exit;
fi;
done < $oratab`
[ -n "$ORACLE_HOME" ] && break
done
fi
scp /usr/local/src/*.tar.gz 10.1X.64.X:/usr/local/src/
scp /usr/local/nagios/etc/nrpe.cfg 10.1X9.64.X:/usr/local/nagios/etc/
监控主机配置:
1.安装nrpe插件(Install the check_nrpe plugin):
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
tar -zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
2.验证与远程主机的nrpe进程的联系(Test communication with the NRPE daemon):
[root@ncljcsev-bak-10 nrpe-2.13]# /usr/local/nagios/libexec/check_nrpe -H 10.1X.64.X
NRPE v2.13
3.创建命令定义(Create a command definition):
vi /usr/local/nagios/etc/objects/commands.cfg
添加如下:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
4.创建主机和服务定义(Create host and service definitions):
在“/usr/local/nagios/etc/objects”目录下创建一个“xxxxx.cfg”配置文件,定义监控的内容。
例如:
新建:cq.cfg
[root@ncljcsev-bak-10 objects]# cat /usr/local/nagios/etc/objects/cq.cfg
define host {
use linux-server
host_name CQLJC-SEV-006
alias Oracle 10g
address 10.1X.64.X
}
define service {
use generic-service
host_name CQLJC-SEV-006
service_description TNS Check
check_command check_nrpe!check_oracle_tns
}
define service {
use generic-service
host_name CQLJC-SEV-006
service_description DB Check
check_command check_nrpe!check_oracle_db
}
define service {
use generic-service
host_name CQLJC-SEV-006
service_description Login Check
check_command check_nrpe!check_oracle_login
}
define service {
use generic-service
host_name CQLJC-SEV-006
service_description Cache Check
check_command check_nrpe!check_oracle_cache
}
define service {
use generic-service
host_name CQLJC-SEV-006
service_description Tablespace Check
check_command check_nrpe!check_oracle_tablespace
}
define hostgroup{
hostgroup_name LJC-big
alias Big-Province
members ah-db1
}
[root@ncljcsev-bak-10 objects]#
修改配置文件:
vim /usr/local/nagios/etc/nagios.cfg
添加:
cfg_file=/usr/local/nagios/etc/objects/yn.cfg
5.重启nagios:
Verify your Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #校验配置的正确性
If there are errors, fix them. If everything is fine, restart Nagios.
service nagios restart #重启nagios