Install the nagios framework and the nagios framework

Source: Internet
Author: User
Tags stop script

Install the nagios framework and the nagios framework

1. Add CGI support for Perl to Nginx
1. Install the FCGI Module

wget https://search.cpan.org/CPAN/authors/id/F/FL/FLORA/FCGI-0.73.tar.gztarxvzf FCGI-0.73.tar.gztar xvzf FCGI-0.73.tar.gzcd FCGI-0.73perl Makefile.PLmakemake installcd ..

2. Install the FCGI-ProcManager Module

wget https://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.19.tar.gztar xvzf FCGI-ProcManager-0.19.tar.gzcd FCGI-ProcManager-0.19perl Makefile.PLmakemake installcd ..

3. Install IO and IO: ALL Module

wget https://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gztar zxvf IO-1.25.tar.gzcd IO-1.25perl Makefile.PLmakemake installcd ..wget https://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gztar zxvf IO-All-0.41.tar.gzcd IO-All-0.41perl Makefile.PLmakemake installcd ..

Download the Perl script
The purpose of this script is to generate a FastCGI interface of PERL, so that Nginx can process Perl in CGI Mode.

Wget https://www.mike.org.cn/wp-content/uploads/2011/07/perl-fcgi.zip
Un zip perl-fcgi.zip
Cp perl-fcgi.pl/usr/local/webserver/nginx/
Note: We recommend that you place this script in the Nginx installation directory.
Modify script Permissions
Chmod 755/usr/local/webserver/nginx/perl-fcgi.pl
5. Create a CGI startup/Stop script
This SHELL script is only used to facilitate the management of the above Perl script. Www in the script is the running user of nginx. Please adjust it according to your actual situation.
Note: it cannot be executed by the root user (a prompt will be displayed). It must be executed by a user with the same identity as Nginx. Otherwise, Permision Denied may be prompted in the Nginx Log.

#!/bin/bash#set -xdir=/home/fupeng/nginxstop (){ #pkill -f $dir/perl-fcgi.pl kill $(cat $dir/logs/perl-fcgi.pid) rm $dir/logs/perl-fcgi.pid 2>/dev/null rm $dir/logs/perl-fcgi.sock 2>/dev/null echo "stop perl-fcgi done"}start (){ rm $dir/now_start_perl_fcgi.sh 2>/dev/null chown work.work $dir/logs echo "$dir/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock" >>$dir/now_start_perl_fcgi.sh chown work.work $dir/now_start_perl_fcgi.sh chmod u+x $dir/now_start_perl_fcgi.sh sudo -u work $dir/now_start_perl_fcgi.sh echo "start perl-fcgi done"}case $1 in stop) stop ;; start) start ;; restart) stop start ;;esac

Modify SHELL script Permissions
Chmod 755/usr/local/webserver/nginx/start_perl_cgi.sh
Start script
/Usr/local/webserver/nginx/start_perl_cgi.sh start
Under normal circumstances, the perl-fcgi.sock file is generated under/usr/local/webserver/nginx/logs. If not, check the preceding step aggregation.

Ii. Install Nagios
A. Preparations before installation
The installed machine must have a WEB service. This article is installed in the Nginx environment.
Download the main nagios program and related plug-in packages

Wget https://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz (cannot be downloaded, end with nagios-plugins-2.0.3.tar.gz) wget https://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gzwget https://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz

Install the GD library (required for statusmap and trends modules in Nagios)

yum install gd-devel

B. Install Nagios monitoring
1. Create Nagios users and groups
Create a Nagios account

/usr/sbin/useradd -m -s /sbin/nologin nagios

2. Create a user group named nagcmd to execute External commands from the web interface. Add Nagios users and Nginx users to the group.

groupadd nagcmdusermod -a -G nagcmd nagiosusermod -a -G nagcmd work

3. Compile and install Nagios

Tarzxvf nagios-3.2.3.tar.gzcd nagios-3.2.3. /configure -- with-command-group = nagatemakemake allmake installmake install-initmake install-configmake install-commandmode # Run Nagios in Nginx, in this step, you do not need to make install-webconfcd ..

Note:
Make install is used to install main programs, CGI and HTML files
Make install-init is used to generate the init Startup Script
Make install-config is used to install the sample configuration file
Make install-commandmode is used to set the corresponding directory permissions.
Make install-webconf is used to install the Apache configuration file
4. Check whether the verification program is correctly installed
Switch the directory to the installation path, which is/usr/local/nagios. 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.

Note: The directory where the bin-Nagios executable program is located. The nagios file is the main program.
Etc-Nagios configuration file location
The directory where the sbin-Nagios cgi file is located, that is, the directory where the file needed to execute the external command is located.
Share-Nagios webpage file directory
Directory where var-Nagios log files and spid files are located
Var/archives-log archiving directory
Var/rw-used to store external command files

5. Configure NGINX
1) configure the Logon account and password on the Nagios Web Interface

htpasswd -c /usr/local/nagios/etc/nagiospasswd mike

If you do not have htpasswd (provided by the Apache installation package), you can generate encrypted data online.

A) Access https://www.4webhelp.net/us/password.phpto generate encrypted data.
B) Create an encrypted authentication File

Vi/usr/local/nagios/etc/nagiospasswd # Add the generated encrypted data. The user name is before the colon, and the encrypted password is mike: 25JB. R7mXY96o.

Modify the Nagios configuration file to grant new users access permissions.

Vi/usr/local/nagios/etc/cgi. cfg # Add new users to the following items. Multiple users are separated by commas. Authorized_for_system_information = nagiosadmin, region = nagiosadmin, region = nagiosadmin, mikeauthorized_for_all_services = nagiosadmin, region = nagiosadmin, region = nagiosadmin, Handler = nagiosadmin, mike

2) Modify NGINX configuration to support WEB access to Nagios
Method 1: access through https: // ip

The NGINX configuration snippets are as follows:

 server { listen 80; server_name localhost; #access_log logs/host.access.log main; location / { root /usr/local/nagios/share; index index.html index.htm; } location ~ .*\.(cgi|pl)?$ { gzip off; root /usr/local/nagios/sbin; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_pass unix:/home/fupeng/nginx/logs/perl-fcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name; fastcgi_index index.cgi; fastcgi_read_timeout 60; fastcgi_param REMOTE_USER $remote_user; include fastcgi.conf; #auth_basic "Nagios Access"; #auth_basic_user_file /usr/local/nagios/etc/nagiospasswd; } location /nagios { alias /usr/local/nagios/share; #auth_basic "Nagios Access"; #auth_basic_user_file /usr/local/nagios/etc/nagiospasswd; } location ~ \.php$ { root /usr/local/nagios/share; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }} 

Without the fastcgi Parameter definition, Nagios cannot correctly verify your login information. Most articles on the Internet solve Nagios login verification failure in Nginx by Using cgi in Nagios. cfg configuration file (nagios/etc/cgi. cfg), or set a default login user (default_user_name = test). Both methods are insecure.

You can check whether you can access the nagios console in your browser.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.