Nginx 플랫폼 에 Nagios 모니터링 서비스 설치 (0608 업데이트)
Nginx 플랫폼 설치
1. 관련 소프트웨어 다운로드
FCGI-0.67.tar.gz FCGI-ProcManager-0.18.tar.gz IO-All-0.39.tar.gz nagios-3.2.3.tar.gz nagios-plugins-1.4.15.tar.gz
2. 관련 사용자 만 들 기
useradd nagios groupadd nagcmd usermod -g nagcmd nagios usermod -g nagcmd www
3. Nagios 설치
tar zxvf nagios - 3.2.3. tar. gz cd nagios - 3.2.3. / configure -- with - group = nagios -- with - user = nagios -- with - command - group = nagcmd -- with - gd - lib = / usr / local / gd / lib -- with - gd - inc = / usr / local / gd / include (0608 업데이트) make install make install - init make install - config make install - config make install - commandmode
4. Nagios 플러그 인 설치
tar zxvf nagios-plugins-1.4.15.tar.gz cd nagios-plugins-1.4.15 ./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install
5. Nagios 시작 설정
chkconfig --add nagios chkconfig nagios on service nagios start
6. Perl fcgi 모듈 을 설치 하여 Nginx 가 CGI 를 지원 하도록 합 니 다.
tar -zxf FCGI-0.67.tar.gz cd FCGI-0.67 perl Makefile.PL make && make install tar -zxf FCGI-ProcManager-0.18.tar.gz cd FCGI-ProcManager-0.18 perl Makefile.PL make && make install tar zxf IO-All-0.39.tar.gz cd IO-All-0.39 perl Makefile.PL make && make install
nginx - fcgi 스 크 립 트 만 들 기
vi /usr/local/nginx/sbin/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 $> UID" if $verbose;
- print " Perl $]" if $verbose;
-
- # if ( $> == "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 $> 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}) &&
- (-s $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}");
- }
- # 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) {
- print ;
- close $cgi_app;
- }
- } 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.
";
- addlog($logfile, "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process.");
- }
- }
- }
chmod +x /usr/local/nginx/sbin/nginx-fcgi
스 크 립 트 실행:
/usr/local/nginx/sbin/nginx-fcgi -l /usr/local/nginx/logs/nginx-fcgi.log -pid /usr/local/nginx/logs/nginx-fcgi.pid -S /usr/local/nginx/logs/nginx-fcgi.sock
sock 권한 부여 777:
chmod 777 /usr/local/nginx/logs/nginx-fcgi.sock
7. 로그 인 계 정 및 비밀번호 설정
메모: 여기 서 생 성 된 사용자 가 nagiosadmin 이 아니라면 / usr / local / nagios / etc / cgi. cfg 설정 파일 에 계 정 을 추가 해 야 합 니 다. 그렇지 않 으 면 새로 만 든 lihp 계 정 은 nagios 를 조작 할 수 있 는 권한 이 없습니다.
/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd lihp
apache 가 없 으 면 인터넷 에서 htpasswd 를 만 들 수 있 습 니 다.
8. Nginx 가상 호스트 만 들 기
다음은 제 가상 호스트 설정 입 니 다.
- server
- {
- listen 80;
- server_name www.nagios.com;
- root /usr/local/nagios/share;
- index index.php;
- auth_basic "lihp";
- auth_basic_user_file /usr/local/nginx/conf/htpasswd;
-
-
- #access_log /usr/local/nginx/logs/nagios.log nagios;
- location ~ \.cgi$ {
- root /usr/local/nagios/sbin;
- rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
- fastcgi_index index.cgi;
- fastcgi_pass unix:/usr/local/nginx/logs/nginx-fcgi.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;
- #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;
- }
- location ~ .*\.(php|php5)?$
- {
- #fastcgi_pass unix:/tmp/php-cgi.sock;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fcgi.conf;
- }
- }
마지막 으로 설정 다시 읽 기:
/usr/local/nginx/sbin/nginx -s reload
그리고 HOSTS 를 연결 하고 브 라 우 저 www. nagios. com 을 엽 니 다.
9. 사진 의 비정상적인 수정 방법:
mkdir -p /usr/local/nagios/share/nagios ln -s /usr/local/nagios/share/p_w_picpaths /usr/local/nagios/share/nagios/p_w_picpaths ln -s /usr/local/nagios/share/stylesheets /usr/local/nagios/share/nagios/stylesheets
10. GD 동적 라 이브 러 리 불 러 오기 (0608 업데이트)
vi /etc/ld.so.conf
include ld.so.conf.d/*.conf /usr/local/gd/lib #GD 동적 라 이브 러 리 경로 추가
그리고 수 동 으로 실행:
ldconfig
맵 과 trends 오류 해결!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
양식 제출 후 제출 버튼 비활성화텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.