환경 구축 부터 설정 까지

14028 단어 학습 체험
환경 구축 부터 설정 까지
    nagios 는 오픈 소스 무료 시스템 모니터링 도구, 홈 페이지 주소 입 니 다.http://www.nagios.org/    마감 2011 - 07 - 27    nagios 의 최신 버 전 은 3. x 입 니 다. c 언어 를 기반 으로 작성 되 었 고 phop 과 cgi 기반 웹 관리 인터페이스 를 제공 합 니 다.    
환경 구축
    nagios 는 웹 용기 + phop 의 운영 환경 이 필요 합 니 다. 현재 회사 에서 nginx 를 웹 용기 로 통일 적 으로 사용 하기 때문에 여기 서 nginx + phop 을 선택 하 였 습 니 다.    nginx 홈 페이지 주소    http://nginx.org/    php 홈 페이지 주소    http://www.php.net/        nagios 의 웹 인터페이스 에 대해 사용자 에 따라 해당 하 는 접근 권한 을 설정 해 야 한다 면 apache 를 설치 해 야 합 니 다. 다른 용도 없 이 htpassword 로 계 정 정 정 보 를 만 드 는 것 입 니 다.    apache 홈 페이지 주소    http://httpd.apache.org/        제 가 준비 한 jar 가방 은 다음 과 같 습 니 다. 그 중에서 spawn - fcgi 는 nginx 에서 phop 으로 재 설정 하 는 데 사 용 됩 니 다.        lighttpd-1.4.28.tar.gz        nginx-1.0.5.tar.gz        php-5.3.6.tar.gz        spawn-fcgi-1.6.2.tar.gz            설치 nginx   
tar nginx-1.0.5.tar.gz
cd nginx-1.0.5/
./configure    --prefix=/usr/local/nginx
make && make install

       주의 -- prefix 는 지정 한 소프트웨어 의 설치 경로 로 개인 상황 에 따라 스스로 수정 할 수 있 습 니 다.    php 를 설치 하기 전에 장 연의 이 블 로 그 를 참고 하 는 것 이 좋 습 니 다.http://blog.s135.com/post/297/ 대응 하 는 그래 픽 과 xml 등 lib 를 설치 합 니 다. 물론 잠시 후에 설치 해도 됩 니 다.    
   
tar zxvf php-5.3.6.tar.gz
cd php-5.3.6/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc l --with-zlib  --disable-debug --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect
make && make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ../

    주의해 야 합 니 다. - enable - fastcgi - enable - force - cgi - redirect 를 가 져 가 야 합 니 다. 실행. / configure 를 실행 할 때 어떤 가방 이 부족 하 다 는 것 을 알려 줍 니 다. 예 를 들 어 zlib, gd 등 을 설치 하면 됩 니 다.
    
    압축 을 풀 고 spawn - fcgi 를 설치 합 니 다. 장 연 블 로그 와 달리 제 가 이 블 로 그 를 쓸 때 spawn - fcgi 는 단독 가방 으로 사용 되 었 습 니 다.
 
tar spawn-fcgi-1.6.2.tar.gz
cd spawn-fcgi-1.6.2/
./configure    --prefix=/usr/local/spawn-fcgi
make && make install

    그리고 spawn - fcgi 라 는 파일 을 phop 의 bin 디 렉 터 리 에 복사 하 는 것 뿐 입 니 다. 왜 파일 하나만 있 습 니까?그래, 나 도 몰라.
cp spawn-fcgi /usr/local/php/bin
chmod +x /usr/local/php/bin/spawn-fcgi

       php cgi 프로 세 스 시작
 /usr/local/php/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 250 -u www -f /usr/local/php/bin/php-cgi

  이렇게 되면 환경 이 많이 다 르 지 않 습 니 다. 이 중간 에 문제 가 생기 기 쉬 운 것 은 phop 설치 할 때 일부 공구 꾸러미 가 부족 하 다 고 보고 할 수 있 습 니 다.    
nagios 및 그 플러그 인 nagios - plugin 설치
   
tar nagios-3.2.3.tar.gz
cd nagios-3.2.3/
./configure    --prefix=/usr/local/nagios --with-gd --with-libpng --with-libjpeg
make && make install

    gd, libpng, libjpeg 를 설치 할 때 대응 하 는 devel 패 키 지 를 설치 해 야 합 니 다. 즉, gd - devel, libpng - devel, libjpeg - devel 입 니 다.
tar nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15/
./configure    --prefix=/usr/local/nagios --with-gd --with-libpng --with-libjpeg
make && make install

    fast - cgi 설치
tar FCGI-ProcManager-0.19.tar.gz
cd FCGI-ProcManager-0.19/
./configure    --prefix=/usr/local/fcgi
make && make install

        많은 nginx + nagios 구축 튜 토리 얼 에서 nginx - fcgi 스 크 립 트 파일 을 언급 했 습 니 다. 다운로드 주 소 는?http://www.nginx.eu/nginx-fcgi/nginx-fcgi.txt 그러나 내 가 이 블 로 그 를 썼 을 때 이 주 소 는 이미 효력 을 잃 었 고 스 크 립 트 파일 은 첨부 파일 로 보 냈 다.        그리고 fcgi 시작
 ./nginx-fcgi -l /usr/local/logs/nginx-fcgi.log -pid /tmp/nginx-fcgi.pid -S /tmp/nginx-fcgi.sock

    - pid 는 nginx - fcgi 의 프로 세 스 pid 를 지정 하 는 데 사 용 됩 니 다. 다음 명령 을 실행 하여 실행 권한 을 변경 해 야 합 니 다.
 chmod    777 /tmp/nginx-fcgi.sock

   
설정 nginx
cd /usr/local/nginx/conf
vi nginx.conf

 다음 설정 추가
server {
    listen          80;
    server_name     nagios.test.com;
    root            /usr/local/nagios/share;
    index index.html index.htm index.php default.html default.htm default.php;

    location ~ .*\.php?$ {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            include fastcgi.conf;
            fastcgi_param SCRIPT_FILENAME /usr/local/nagios/share$fastcgi_script_name;
            auth_basic      "nagios admin";
            auth_basic_user_file    /usr/local/nagios/etc/nagiosAdmin.net;
     }
    location ~ .*\.cgi$ {
            root    /usr/local/nagios/sbin;
            rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
            fastcgi_pass unix:/tmp/nginx-fcgi.sock;
            fastcgi_index index.cgi;
            fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
            include fastcgi.conf;
            auth_basic      "nagios admin";
            auth_basic_user_file    /usr/local/nagios/etc/nagiosAdmin.net;

    }
    location /nagios {
            alias /usr/local/nagios/share;
            auth_basic      "nagios admin";
            auth_basic_user_file    /usr/local/nagios/etc/nagiosAdmin.net;

    }
    location ~ .*\.pl$ {
            fastcgi_pass  unix:/tmp/nginx-fcgi.sock;
            fastcgi_index index.pl;
            fastcgi_param SCRIPT_FILENAME  /usr/local/nagios/sbin$fastcgi_script_name;
            include fastcgi.conf;
    }
}

  그 중 authbasic 와 authbasic_user_file 은 이 URI 의 접근 권한 을 지정 하 는 데 사 용 됩 니 다. / usr / local / nagios / etc / nagiosAdmin. net 은 htpasswd 명령 으로 미리 생 성 해 야 합 니 다.    접미사. php 의 URI 용        fastcgi_pass    127.0.0.1:9000;        fastcgi_index   index.php;        spawn - cgi 처리    접미사. cgi URI 용        root    /usr/local/nagios/sbin;        rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;        fastcgi_pass unix:/tmp/nginx-fcgi.sock;        fastcgi_index index.cgi;        fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;        include fastcgi.conf;    방금 시 작 된 nginx - fcgi 프로 세 스 처 리 를 지정 합 니 다. nagios 의 phop 프로그램 은 / usr / local / nagios / share 에 있 습 니 다. cgi 프로그램 은 / usr / local / nagios / sbin 에 있 습 니 다. 경 로 를 잘못 알 지 마 십시오.    그 다음 에 nagios, nginx 를 시작 하여 현재 기기 에 host 를 설정 한 후에 접근 합 니 다.http://nagios.test.com 웹 콘 텐 츠 보기
nagios 설정
nagios 설정 파일 은 / usr / local / nagios / etc 에 있 습 니 다.        nagios.cfg    주 프로필 입 니 다.    cgi.cfg    설정 권한 따위 에 사용    자세 한 프로필 은 / usr / local / nagios / etc / object 에 있 습 니 다. 어떻게 설정 하 는 지 자세 한 내용 은 다음 과 같 습 니 다.http://nagios-cn.sourceforge.net/nagios-cn/cgiconfig.html    설정 파일 이 수정 되면 명령 / usr / local / nagios / bin / nagios - pv / usr / local / nagios / etc / nagios. cfg 업데이트 캐 시 를 실행 합 니 다. 자세 한 내용 은 다음 과 같 습 니 다.http://nagios-cn.sourceforge.net/nagios-cn
  다음은 nginx - fcgi 의 소스 코드 입 니 다.
#!/usr/bin/perl
#
#	author		Daniel Dominik Rudnicki
#	thanks to:	Piotr Romanczuk
#	email		[email protected]
#	version		0.4.3
#	webpage		http://www.nginx.eu/
#
#	BASED @ http://wiki.codemongers.com/NginxSimpleCGI
#
#
# use strict;
use FCGI;
use Getopt::Long;
use IO::All;
use Socket;

sub init {
	GetOptions(	"h"	=> \$help,
			"verbose!"=>\$verbose,
			"pid=s"	=> \$filepid,
			"l=s" => \$logfile,
			"S:s"   => \$unixsocket,
			"P:i"   => \$unixport) or usage();
		usage() if $help;

	print "	Starting Nginx-fcgi
" if $verbose; print " Running with {1}gt; UID" if $verbose; print " Perl $]" if $verbose; # if ( {1}gt; == "0" ) { # print "
\tERROR\tRunning as a root!
"; # print "\tSuggested not to do so !!!

"; # exit 1; # } if ( ! $logfile ) { print "
\tERROR\t log file must declared
" . "\tuse $0 with option -l filename

"; exit 1; } print " Using log file $logfile
" if $verbose; "

" >> io($logfile); addlog($logfile, "Starting Nginx-cfgi"); addlog($logfile, "Running with {1}gt; UID"); addlog($logfile, "Perl $]"); addlog($logfile, "Testing socket options"); if ( ($unixsocket && $unixport) || (!($unixsocket) && !($unixport)) ) { print "
\tERROR\tOnly one option can be used!
"; print "\tSuggested (beacuse of speed) is usage UNIX socket -S

"; exit 1; } if ($unixsocket) { print " Daemon listening at UNIX socket $unixsocket
" if $versbose; addlog($logfile, "Deamon listening at UNIX socket $unixsocket"); } else { print " Daemon listening at TCP/IP socket *:$unixport
" if $verbose; # addlog($logfile, "Daemon listening at TCP/IP socket *:$unixport"); } if ( -e $filepid ) { print "
\tERROR\t PID file $filepid already exists

"; addlog($logfile, "Can not use PID file $filepid, already exists."); exit 1; } if ( $unixsocket ) { print " Creating UNIX socket
" if $verbose; $socket = FCGI::OpenSocket( $unixsocket, 10 ); if ( !$socket) { print " Couldn't create socket
"; addlog($logfile, "Couldn't create socket"); exit 1; } print " Using UNIX socket $unixsocket
" if $verbose; } else { print " Creating TCP/IP socket
" if $verbose; $portnumber = ":".$unixport; $socket = FCGI::OpenSocket( $unixport, 10 ); if ( !$socket ) { print " Couldn't create socket
"; addlog($logfile, "Couldn't create socket"); exit 1; } print " Using port $unixport
" if $verbose; } addlog($logfile, "Socket created"); if ( ! $filepid ) { print "
\tERROR\t PID file must declared
" . "\tuse $0 with option -pid filename

"; exit 1; } print " Using PID file $filepid
" if $verbose; addlog($logfile, "Using PID file $filepid"); my $pidnumber = $; $pidnumber > io($filepid); print " PID number $
" if $verbose; addlog($logfile, "PID number $pidnumber"); } sub addzero { my ($date) = shift; if ($date < 10) { return "0$date"; } return $date; } sub logformat { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$iddst) = localtime(time); my $datestring; $year += 1900; $mon++; $mon = addzero($mon); $mday = addzero($mday); $min = addzero($min); $datestring = "$year-$mon-$mday $hour:$min"; return($datestring); } sub addlog { my ($log_file, $log_message) = @_; my $curr_time = logformat(); my $write_message = "[$curr_time] $log_message"; $write_message >> io($log_file); "
" >> io($log_file); } sub printerror { my $message = @_; print "
Nginx FastCGI\tERROR
" . "\t $message

"; exit 1; } sub usage { print "
Nginx FastCGI
" . "
\tusage: $0 [-h] -S string -P int
" . "
\t-h\t\t: this (help) message" . "
\t-S path\t\t: path for UNIX socket" . "
\t-P port\t\t: port number" . "
\t-p file\t\t: path for pid file" . "
\t-l file\t\t: path for logfile" . "

\texample: $0 -S /var/run/nginx-perl_cgi.sock -l /var/log/nginx/nginx-cfgi.log -pid /var/run/nginx-fcgi.pid

"; exit 1; } init; # END() { } BEGIN() { } *CORE::GLOBAL::exit = sub { die "fakeexit
rc=".shift()."
"; }; eval q{exit}; if ($@) { exit unless $@ =~ /^fakeexit/; } ; # fork part my $pid = fork(); if( $pid == 0 ) { &main; exit 0; } print " Forking worker process with PID $pid
" if $verbose; addlog($logfile, "Forking worker process with PID $pid"); print " Update PID file $filepid
" if $verbose; addlog($logfile, "Update PID file $filepid"); $pid > io($filepid); print " Worker process running.
" if $verbose; addlog ($logfile, "Parent process $ is exiting"); exit 0; sub main { $request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket ); if ($request) { request_loop()}; FCGI::CloseSocket( $socket ); } sub request_loop { while( $request->Accept() >= 0 ) { # processing any STDIN input from WebServer (for CGI-POST actions) $stdin_passthrough = ''; $req_len = 0 + $req_params{'CONTENT_LENGTH'}; if (($req_params{'REQUEST_METHOD'} eq 'POST') && ($req_len != 0) ){ while ($req_len) { $stdin_passthrough .= getc(STDIN); $req_len--; } } # running the cgi app if ( (-x $req_params{SCRIPT_FILENAME}) && (-r $req_params{SCRIPT_FILENAME}) ){ foreach $key ( keys %req_params){ $ENV{$key} = $req_params{$key}; } if ( $verbose ) { addlog($logfile, "running $req_params{SCRIPT_FILENAME}"); } else { addlog($logfile, "running $req_params{SCRIPT_FILENAME} fail"); } # http://perldoc.perl.org/perlipc.html#Safe-Pipe-Opens # open $cgi_app, '-|', $req_params{SCRIPT_FILENAME}, $stdin_passthrough or print("Content-type: text/plain\r
\r
"); print "Error: CGI app returned no output - Executing $req_params{SCRIPT_FILENAME} failed !
"; # addlog($logfile, "Error: CGI app returned no output - Executing $req_params{SCRIPT_FILENAME} failed !"); if ($cgi_app) { addlog($logfile, "$cgi_app is ok.
"); print ; close $cgi_app; } else { addlog($logfile, "$cgi_app is not ok!
"); } } else { print("Content-type: text/plain\r
\r
"); print "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process. File Again!!
"; addlog($logfile, "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process."); } } }

좋은 웹페이지 즐겨찾기