With the increasing availability and Stability of linux servers, enterprises have increasingly strict requirements on online services. Therefore, special monitoring systems are required to monitor the normal operation of services, if any problem occurs, send an email and send an alarm to the linux SA. Most of our nagios and cacti monitoring systems are built based on apache. Today we will talk about a new platform to build the nginx platform's nagios monitoring!
I. system running environment
Server System Version: Centos 5.3x64
Nginx version: nginx-0.8.54
Nagios version: nagios-3.2.3
Ii. download the required package
# All source code packages required for installation: download from the site integration: (the following package address has expired. Please download the corresponding package from the official website)
Http://blog.mgcrazy.com/download/nginx-0.8.54.tar.gz
Http://blog.mgcrazy.com/download/pcre-8.01.tar.gz
Http://blog.mgcrazy.com/download/nagios/FCGI-0.67.tar.gz
Http://blog.mgcrazy.com/download/nagios/FCGI-ProcManager-0.18.tar.gz
Http://blog.mgcrazy.com/download/nagios/nagios-3.2.3.tar.gz
Http://blog.mgcrazy.com/download/nagios/nagios-plugins-1.4.13.tar.gz
Http://blog.mgcrazy.com/download/nagios/nrpe-2.8.1.tar.gz
# Nginx installation see: http://blog.mgcrazy.com /? P = 792 [install nginx]
After nginx is installed.
3. Officially install nagios
# Create a nagios user and group and add www to the nagios Management Group:
Useradd nagios & groupadd nagcmd & usermod-g nagcmd nagios & usermod-g nagcmd www
Cd/usr/scr & tar xzf nagios-3.2.3.tar.gz & cd nagios-3.2.3
./Configure -- with-command-group = nagcmd -- prefix =/usr/local/nagios & make all
Make install & make install-init & make install-config & make install-commandmode
# Nagios installation is complete!
Verify that the program is correctly installed. Switch the directory to the installation path (/usr/local/nagios) to check whether the five directories including etc, bin, sbin, share, and var exist, if yes, it indicates that the program has been correctly installed to the system. Next, compile and install the nagios plug-in nagios-plugins.
Cd/usr/src & tar zxvf nagios-plugins-1.4.13.tar.gz & cd nagios-plugins-1.4.13
./Configure -- prefix =/usr/local/nagios -- with-nagios-user = nagios -- with-nagios-group = nagios
Make & make install
# Plug-ins have been installed!
# Ls/usr/local/nagios/libexec: The installed plug-in file is displayed, that is, all the plug-ins are installed in the libexec directory.
4. Create a nagiosadmin user
# Use the WEB interface for logging on to Nagios.
# Write down your logon password. you will use it later.
Here we need to use the htpasswd of apche to execute the following command on an apache machine.
/Usr/local/apache2/bin/htpasswd-c/usr/local/nagios/etc/htpasswd nagiosadmin
Enter the same password twice.
Chkconfig-add nagios
# Add to service, and set chkconfig nagios-level 35 on to start upon startup.
# Disable selinux and iptables, or change the iptables policy to access nagios
# Start nagios
/Etc/init. d/nagios start
5. Install Perl FCGI
# Install php refer to http://chinaapp.sinaapp.com/thread-627-1-1.html
# Installing FCGI
Cd/usr/src & tar-zxvf FCGI-0.67.tar.gz & cd FCGI-0.67 & perl Makefile. PL
Make & make install
# Install FCGI-ProcManager:
Cd ../& tar-xzxf FCGI-ProcManager-0.18.tar.gz & cd FCGI-ProcManager-0.18
Perl Makefile. PL & make install
# The installation is complete.
Mkdir-p/usr/local/nagios/share/nagios
Ln-s/usr/local/nagios/share/images/usr/local/nagios/share/nagios/images
Ln-s/usr/local/nagios/share/stylesheets/usr/local/nagios/share/nagios/stylesheets
# Avoid Image Display failures.
Next, configure the cgi script and nginx configuration file:
New file under cd/usr/local/nagios/bin/and write the following content to vi perl-cgi.pl
#! /Usr/bin/perl
Use FCGI;
# Perl-MCPAN-e 'Install fcgi'
Use Socket;
# This keeps the program alive or something after exec 'ing perl scripts
END ()
{
}
BEGIN ()
{
}
* CORE: GLOBAL: exit
=
Sub
{
Die
"Fakeexit \ nrc =". shift (). "\ n ";
};
Eval
Q {exit };
If
($ @)
{
Exit
Unless
$ @
= ~
/^ Fakeexit /;
}
;
& Main;
Sub main {
# $ Socket = FCGI: OpenSocket (": 3461", 10); # use IP sockets
$ Socket
= FCGI: OpenSocket (
"/Var/run/nagios. sock ",
10
);
# Use UNIX sockets-user running this script must have w access to the 'nginx' folder !!
$ Request
= FCGI: Request (
\ * STDIN,
\ * STDOUT,
\ * STDERR,
\ % ENV,
$ Socket
);
If
($ Request)
{Request_loop ()};
FCGI: CloseSocket (
$ Socket
);
}
Sub request_loop {
While (
$ Request-> Accept ()
> =
0
)
{
# Processing any STDIN input from WebServer (for CGI-GET actions)
$ Env
=
$ Request-> GetEnvironment ();
$ Stdin_passthrough
= ";
$ Req_len
=
0
+
$ ENV {CONTENT_LENGTH };
If
($ ENV {REQUEST_METHOD}
Eq
'Get '){
$ Stdin_passthrough
. =
$ ENV {'query _ string '};
}
# Running the cgi app
If
(
(-X $ ENV {SCRIPT_FILENAME })
&&
# Can I execute this?
(-S
$ ENV {SCRIPT_FILENAME })
&&
# Is this file empty?
(-R $ ENV {SCRIPT_FILENAME })
# Can I read this file?
){
# Http://perldoc.perl.org/perlipc.html#Safe-Pipe-Opens
Open
$ Cgi_app,
'-| ',
$ ENV {SCRIPT_FILENAME },
$ Stdin_passthrough
Or
Print ("Content-type: text/plain \ r \ n ");
Print
"Error: CGI app returned no output-Executing $ ENV {SCRIPT_FILENAME} failed! \ N ";
If
($ Cgi_app)
{Print
<$ Cgi_app>;
Close
$ Cgi_app ;}
}
Else
{
Print ("Content-type: text/plain \ r \ n ");
Print
"Error: No such CGI app-$ req_len-$ ENV {CONTENT_LENGTH}-$ ENV {REQUEST_METHOD}-$ ENV {SCRIPT_FILENAME} may not exist or is not executable by this process. \ n ";
}
}
}
# Set the permission chmod + x perl-cgi.pl!
The following is my nginx. conf file server content
Server
{
Listen 80;
Server_name 192.168.2.79;
Root/usr/local/nagios/share;
Index. php;
Auth_basic "You Name ";
Auth_basic_user_file/usr/local/nagios/etc/htpasswd;
Log_format nagios '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent' $ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
Access_log/usr/local/nginx/nagios. log nagios;
Location ~ . * \. (Php | php5 )? $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi. conf;
}
Location ~ \. Cgi $ {
Root/usr/local/nagios/sbin;
Rewrite ^/nagios/cgi-bin/(. *) \. cgi/$ 1.cgi break;
Fastcgi_index index. cgi;
Fastcgi_pass unix:/var/run/nagios. sock;
Fastcgi_param SCRIPT_FILENAME/usr/local/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 REMOTE_USER $ remote_user;
# There is no red sentence by default. If not, an error will be reported on the nagios page later. The specific error is shown later.
# 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;
}
The content of the fcgi. conf file is as follows:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
The above code can integrate fastcGI in nginx into fcgi. conf.
Start nginx and check that port fastcGI 9000 is available. Start screen./perl-cgi.pl>/dev/null in the background
Ctrl + a + d Exit screen
Then chmod 777/var/run/nagios. sock; and restart service nagios restart
6. After installation is complete, access:
Access http: // 192.168.2.79 directly. The logon window is displayed. Enter the username nagiosadmin and password. The default monitoring localhost of nagios is displayed! The page is as follows: Click Detail service to close the alarm, and no error is reported:
Since then, the nginx + nagios environment has been set up! The rest is the configuration of the specific monitoring client! This article will be provided later!
The environment in this article has been tested, and many series of problems, such as 403, 502, and 504, were encountered during the setup. Only when you have done one thing can you feel that you have learned a lot. The following error is reported:
# It seems that you have chosen to not use the authentication functionality of the CGIs.
I don't want to be personally responsible for what may happen as a result of allowing
Unauthorized users to issue commands to Nagios, so you'll have to disable this safeguard if you
Are really stubborn and want to invite trouble.
# It appears as though you do not have permission to view information for any of the hosts you requested...
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
And check the authorization options in your CGI configuration file
See modify: http://hi.baidu.com/shengit/blog/item/b21b770965c6e8de62d986c0.html
References
http://bbs.linuxtone.org/thread-4441-1-1.html
http://bbs.linuxtone.org/thread-7404-1-1.html
http://www.comeonsa.com/
This article from the "Wu guangke-Focus on automated O & M" blog, please be sure to keep this source http://wgkgood.blog.51cto.com/1192594/523150