下载安装nagios:
wget
wget
#创建帐号及组
# 创建帐号
/usr/sbin/useradd -m nagios
passwd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd www
安装nagios:
tar xzf nagios-3.0.5.tar.gz
cd nagios-3.0.5
./configure --with-command-group=nagcmd --with-gd-lib=/usr/local/libgd/lib/ --with-gd-inc=/usr/local/libgd/include/
make all
# 使用make install来安装主程序,CGI和HTML文件
make install
# 使用make install-init在/etc/rc.d/init.d安装启动脚本
make install-init
# 使用make install-cofig来安装示例配置文件,安装的路径是/usr/local/nagios/etc.
make install-config
# 使用make install-commandmode来配置目录权限
make install-commandmode
#########################
nagios目录功能的简要说明:
bin Nagios执行程序所在目录,nagios文件即为主程序
etc Nagios配置文件位置
sbin Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
Share Nagios网页文件所在的目录
var Nagios日志文件、spid 等文件所在的目录
var/archives 日志归档目录
var/rw 用来存放外部命令文件
###########################
## nginx web服务器配置:
----------------------------------------------------------
server {
listen 192.168.0.220;
server_name 192.168.0.220;
access_log /var/log/nginx/nagios/nagios_access_log combined;
error_log /var/log/nginx/nagios/nagios_error_log notice;
location /nagios {
alias /opt/nagios/share;
auth_basic "Restricted";
auth_basic_user_file /opt/nagios/etc/htpasswd.user;
}
location ~ \.cgi$ {
root /opt/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_index index.cgi;
auth_basic "Restricted";
auth_basic_user_file /opt/nagios/etc/htpasswd.user;
fastcgi_pass unix:/var/run/fcgi/nagios.sock;
fastcgi_param SCRIPT_FILENAME /opt/nagios/sbin$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param REQUEST_URI $request_uri;
#fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param HTTP_ACCEPT_ENCODING gzip,deflate;
fastcgi_param HTTP_ACCEPT_LANGUAGE zh-cn;
#include conf/fastcgi_params;
}
}
----------------------------------------------------------
##per.cgi启动nginx.sock,所使用到的perl-cgi.pl源代码只能放到附件中
----------------------------------------------------------
## start up script,get the /var/run/fcgi/nagios.sock
## Note: the nagios.sock must be web.web
----------------------------------------------------------
#!/bin/bash
## start_nginx_cgi.sh: start nginx cgi mode
## ljzhou, 2007.08.20
PERL="/usr/bin/perl"
NGINX_CGI_FILE="/opt/nagios/bin/perl-cgi.pl"
#bg_num=`jobs -l |grep "NGINX_CGI_FILE"`
#PID=`ps aux|grep "perl-cgi"|cut -c10-14|xargs kill -9`
PID=`ps aux|grep 'perl-cgi'|cut -c10-14|sed -n "1P"`
echo $PID
sockfiles="/var/run/fcgi/nagios.sock"
kill -9 $PID
$PERL $NGINX_CGI_FILE &
sleep 3
`chown web.web $sockfiles`
# EOF: start_nginx_cgi.sh
----------------------------------------------------------
配置apache web服务器:
将现面行加入apache配置文件的alias模块
----------------------------------------------------------
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
Alias /nagios "/usr/local/nagios/share"
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
----------------------------------------------------------
# 创建密码目录验证文件
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: (输入密码)
Re-type new password: (再输入一次密码)
Adding password for user nagiosadmin
# 配置nagios配置文件
vi /usr/local/nagios/etc/objects/contacts.cfg
# 将里面的email地址改为自己的email地址。
安装Nagios插件
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
##启动Nagios
# 配置机器启动时自动启动Nagios
chkconfig --add nagios
chkconfig nagios on
# 检查Nagios配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# 启Nnagios
service nagios start
8.安装nrpe插件,用来监控Linux机器
tar xzvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
# 在Nagios服务器端只要安装nrpe监控插件就行
make install-plugin
在/usr/local/nagios/etc/objects/commands.cfg中定义check_nrpe命令
vi /usr/local/nagios/etc/objects/commands.cfg
########################################################################
#
# 2008.11.18 add by Stone
# NRPE COMMAND
#
########################################################################
# 'check_nrpe ' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
# 修改nrpe配置文件,允许Nagios监控服务器(192.168.0.19)监控
vi nrpe.cfg
# 多台机器用逗号隔开
allowed_hosts=127.0.0.1,192.168.0.19
# 以独立守护进程启动nrpe,也可以使用xinetd启动nrpe,具体清查看nrpe官方文档。
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# 开机自动启动nrpe
vi /etc/rc.d/rc.local
# 加入下面行
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# 检查nrpe是否安装正常
[root@wiki etc]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12
# 返回nrpe版本说明安装没问题。
# 查看启动端口
[root@wiki ~]# netstat -tunlp
参考:
%C7%E1%C7%E1%B5%E3%B5%E3/blog/item/b1a1d7070fcc6fcb7b8947a2.html
commond:http://blog.sina.com.cn/s/blog_4a149b640100c1ws.html
阅读(1402) | 评论(0) | 转发(0) |