月度归档:2009年08月

nagios的插件安装

安装nagios-plugin的时候,附带的参数说明:
[root@localhost nagios-plugins-1.4.13]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios –prefix=/usr/local/nagios –with-ping-command=”/bin/ping” –with-mysql –without-ipv6
以上我在操作的过程中mysql提示找不到库文件,出错信息如下
“configure: WARNING: Skipping mysql plugin
configure: WARNING: install mysql client libs to compile this plugin (see REQUIREMENTS).”
后来把mysql_config复制到/usr/lib/pkgconfig后,顺利configure,看来还是路径的问题,其实在nagios-plugins-1.4.13的目录下的“REQUIREMENTS”文件已经详细说明了“check_mysql, check_mysql_query:
        – Requires the MySQL libraries available from
          http://www.mysql.org/
                Lib: libmysql, libmysqlclient
                Redhat Powertools Source: mysql-3.20.32a-3.i386.rpm, mysql-devel-3.20.32a-3.i386.rpm (these seem to be broken, howev
er)
                RPMS from www.mysql.org work better
          Must have mysql_config in PATH or specified with –with-mysql=DIR for DIR/bin/mysql_config”

nagios安装,网上太多了,这个是自己安装后的手记。

nagios安装

下载:wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
安装:
tar -zxvf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure –prefix=/usr/local/nagios –with-command-group=nagcmd
make all
make all完毕后有如下提示:
“If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type ‘make’
without any arguments for a list of all possible options):

  make install
     – This installs the main program, CGIs, and HTML files

  make install-init
     – This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     – This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     – This installs *SAMPLE* config files in /usr/local/nagios/etc
       You’ll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

  make install-webconf
     – This installs the Apache config file for the Nagios
       web interface”
依次运行如下命令:
make install
make install-init
make install-commandmode
make install-config
make install-webconf
给nginx添加认证:
修改nginx的配置文件如下:
    location /nagios/ {
    alias /usr/local/nagios/share/;
    index index.html index.htm index.php;
    auth_basic “nagios”;
    auth_basic_user_file /usr/local/nagios/etc/htpasswd admin
    }
生成htpasswd文件:
/usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd admin
其中htpasswd是apache提供的工具
配置nagios
nagios web界面提示
It appears as though you do not have permission to view information for any of the services you requested…
打开cgi.cfg配置文件,里面有个参数:
use_authentication=1
为了保障系统的安全性,nagios设置了这个参数,默认为1,改为0即可

 

配置:
下载插件:
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
tar -zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure –prefix=/usr/local/nagios
make
make install
配置附件:
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure –prefix=/usr/local/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
返回:[root@localhost nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H localhost
      NRPE v2.12
完成。
配置perl,cgi,nginx

nginx的perl的fcgi环境搭建。


首先:有三种方式(三个不同的脚本)搭建cgi环境,第二种,在运行时,nginx的error里会报错。
FastCGI sent in stderr: “Bad file descriptor at /EBS/fcgi.pl line 125”,第二种脚本的好处是可以起多个进程(process)
 方法一
 测试页
 
 

记得一定要给nginx发送头信息 不然会报504错误的。

#!/usr/bin/perl -w
print “Content-type: text/plain\r\n\r\n”;#发送头信息
print “test”;

1、安装FCGI模块:
到http://search.cpan.org/网站上下载FCGI模块:

wget http://search.cpan.org/CPAN/authors/id/S/SK/SKIMO/FCGI-0.67.tar.gz
 
tar -zxvf FCGI-0.67.tar.gz. 
cd FCGI-0.67 
perl Makefile.PL
make 
make install

2、安装 IO 和 IO::ALL模块
下载:
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz
http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.39.tar.gz
安装:
tar -xvzf IO-1.25.tar.gz
cd IO-1.25
perl Makefile.PL
make 
make install
 
tar -xvzf IO-All-0.39.tar.gz
cd IO-ALL-0.39
perl Makefile.PL
make
make install
  
3、如果需要,安装perl-Getopt和 perl-Socket
(转注:以上三项,使用cpan安装会跟简单一些,cpan怎么安装,请看其它日志) 
  
4、perl cgi脚本
或从下面的地址下载perl-fcgi脚本
http://www.nginx.eu/nginx-fcgi/nginx-fcgi.txt
(转注:拿到这个脚本后,可能需要修改一些脚本的路径,在我的操作过程中,我更改了一下sock那个文件的名字,这个文件我是放在/usr/local/nginx/perl-fcgi.pl,我没有取nginx-fcgi.pl这个名字)

5、启动cgi脚本 (nobody为nginx的运行用户)
vi start_perl_cgi.sh
  

#!/bin/bash

#set -x

dir=/usr/local/nginx

 

stop ()

{

#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 nobody.root $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_f

cgi.sh

 

chown nobody.nobody $dir/now_start_perl_fcgi.sh

chmod u+x $dir/now_start_perl_fcgi.sh

 

sudo -u nobody $dir/now_start_perl_fcgi.sh

echo “start perl-fcgi done”

}

 

case $1 in

stop)

stop

;;

start)

start

;;

restart)

stop

start

;;

esac 

启动
./start_perl_cgi.sh start

6为Nginx添加FCGI支持(以安装nagios为例)
vi perl_fcgi.conf 

gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped
fastcgi_pass unix:/usr/local/nginx/logs/nginx-fcgi.sock;
fastcgi_index index.cgi;

fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;

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 GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
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

以上为perl_fcgi.conf文件内容(转注)

location ~* .*\.cgi$
                {
                      rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
                        include perl_fcgi.conf;
                }

以上为nginx.conf配置文件中的内容(转注)
将请求cgi的url由/nagios/cgi-bin/*.cgi 重写为/*.cgi,这样,即下面的fastcgi_param中的$fastcgi_script_name,这样,可以正确的拼出cgi文件的路径。

重启nginx后,应该就可以访问perl的cgi文件了 

配置nginx下的perl的fcgi的原因是我需要在我的机器上安装nagios。
以上为摘抄加自己的一些补充,原作地址为:http://blog.chinaunix.net/u/32831/showart_2011754.html

  

解决Nginx + PHP(FastCGI)遇到的502 Bad Gateway错误

解决Nginx + PHP(FastCGI)遇到的502 Bad Gateway错误

昨日,有朋友问我,他将Web服务器换成Nginx 0.6.31  + PHP 4.4.7(FastCGI)后,有时候访问会出现“502 Bad Gateway”错误,如何解决。

  我让按照以下两个步骤去解决,最后在第2步中将FastCGI的timeout时间增加为300,问题解决:

  PS:比较羡慕迅雷的Web服务器,16G内存。


  1、查看当前的PHP FastCGI进程数是否够用:

netstat -anpo | grep “php-cgi” | wc -l

  如果实际使用的“FastCGI进程数”接近预设的“FastCGI进程数”,那么,说明“FastCGI进程数”不够用,需要增大。


  2、部分PHP程序的执行时间超过了Nginx的等待时间,可以适当增加nginx.conf配置文件中FastCGI的timeout时间,例如:

……
http
{
……
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
……
}
……

CPAN基本介绍
1.perl模块是perl的库,就好比c/c++写的可执行文件需要用到.a静态库和.so动态库一样。
2.CPAN(http://www.cpan.org/)是perl官方站点(http://www.perl.com/)的一个“军火库”,里面有上百万的perl模块,用来支撑perl强大的功能,从生物工程到天文计算,从宏观世界到原子力学,无所不有。
3.为了很方便的安装perl模块,有人做了一个CPAN模块,用cpan命令来管理和安装CPAN网站上的所有perl模块。
cpan命令
1.cpan命令其实也是一个perl脚本,对于不同版本的perl,可能cpan命令的功能强弱有所不同;
2.执行cpan,我们进入了一个类似bash的界面,暂且叫做cpanshell,cpanshell上可以像bash一样输入命令,这个命令是CPAN所特有的。
3.我们一般常用到的cpan命令主要有:
1.help
•help命令是显示帮助信息,这里面包含了所有的cpan命令,虽然看上去只有一屏,但功能确是非常强大哟!
2.m //
这个是一个模式,用来查找perl模块,有点像perl正则里面的m//,用于匹配(match),但这里m与//之间多了一个空格,且这里的m指
modules,意思是根据模块名称查找,//内可以使用正则; 同理
a(authors)、b(bundles)、d(distributions)和i(in all)都有这种模式。
3.install
•install命令是安装perl模块,一般是接模块名称,而不是压缩包名字。比如DBD::mysql,而不是DBD-mysql,即

   install DBD::mysql
CPAN配置
•CPAN安装是网络安装,如果没有网络,使用cpan命令是无法安装的,所以CPAN安装的速度是与网络有直接关系;•当然,我们可以选择一个快速的镜像站点来安装CPAN模块,那如何配置呢?

1.如果是第一次使用CPAN,那么执行cpan命令的时候,cpan命令会给出配置的友好提示,不过很多人都对这个友好提示的繁冗程度显得很不耐烦,不过新版本的CPAN模块已经改善了这一缺点;

2.如果不是第一次使用CPAN,而以前别人配置的CPAN镜像站点出了问题不能下载,或镜像站点太慢等等修改一下配置信息,可以重新配置CPAN:

 

 

  CPAN>o conf init

•若不是root用户,使用cpan命令或perl -MCPAN -e shell也可以进行配置后安装:

1.首先,配置好CPAN配置,这个配置可以使用非root用户配置好,配置好的内容一般在$HOME/.cpan/CPAN/MyConfig.pm文件内;

2.配置文件MyConfig.pm中配置信息中确定有 ‘makepl_arg’=>q[PREFIX=~/perl] 这一行,~/perl为你当前用户有权限读、写和执行的目录;

3.最后,设置 PERL5LIB 环境变量,把 ~/perl 下的相关目录添加进 PERL5LIB。以 bash shell 为例,在 ~/.bash_profile 里添加如下即可:

 

 

  export PERL5LIB=~/perl/lib:\  ~/perl/lib/perl5/5.8.0/i386-linux-thread-multi:\  ~/perl/lib/perl5/5.8.0:\  ~/perl/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi:\  ~/perl/lib/perl5/site_perl/5.8.0:\  ${PERL5LIB}
模块检测
•运行

 

  $perl -e ‘use Module’

如果没有任何输出,则表示模块 Module 成功安装

 
•打印模块版本

 

  $perl -MModule -e ‘print $Module::VERSION;’
注意事项
1.使用 CPAN 安装模块有时候会 make test 一步失败。可到 $HOME/.cpan/build 的相应目录下直接 make install;

2.第一次安装 CPAN 时,可以先安装:

 

  install Bundle::CPAN

 
  installBundle::CPANxxl?

这样以后的安装包安装就会少需要的依赖,建议安装。

服务器取名

日积月累,Nagios监控的主机越来越多,给主机起名字就成了一门学问。简洁清楚的名字会在无形中给工作带来方便。
下面,我把我的命名规则介绍一下,希望可以抛砖引玉,也请各位看官多给意见。
应用名称.[物理位置].域名(小写英文)|项目名称首字母(大写字母)
其中“[]”表示可选;“()”表示说明信息;“|”表示或者,此例中及是“二选一”。
其中“应用名称”包括:Web,网站;Data,数据库;App,应用;GW,网关;Srv,其他服务(或另外取名)。

举个例子,例如:
www.hardwork.cn的web服务器,它的名字会是 Web.hardwork.cn
www.hardwork.cn的数据库服务器,它的名字会是 Data.hardwork.cn
www.hardwork.cn在英国的分流服务器,它的名字会是 App.En.hardwork.cn
来个变态一点的,一个服务器上面跑很多服务,hardwork.cn,包括网站、数据库、短信接入等等。那么它的名字会是 Srv.hardwork.cn

^-^ 起名字是一个很有创造性的工作,Enjoy it!

转自:http://blog.chinaunix.net/u/28387/showart_357300.html