在LNMP下用nginx 1.4.7配置nagios监控

简介:

因为网上的教程nginx的版本比较old,所以用新版本的nginx配置教程多数有错误,下面整理,希望能帮到你


LNMP环境已经搭建好,nginx版本是1.4.7,php版本是5.3.17,

1
2
cat /etc/redhat-release
CentOS release  6.4  (Final)
1
2
/usr/local/nginx/sbin/nginx -v
nginx version: nginx/ 1.4 . 7
1
2
/usr/local/php/bin/php -v
PHP  5.3 . 17  (cli) (built: Jan  23  2014  09 : 47 : 42 )

安装配置nagios见 http://bbotte.blog.51cto.com/6205307/1403997

yum install perl perl-devel  fcgi-devel

在服务端进行配置

为nginx添加fcgi支持,下载并安装 http://pan.baidu.com/s/1sXpGj

IO-1.25.tar.gz

IO-All-0.41.tar.gz

FCGI-ProcManager-0.18.tar.gz

FCGI-0.70.tar.gz


安装时候都一样,参考下面

tar -xzf IO-1.25.tar.gz

cd IO-1.25

perl Makefile.PL
make && make install


vim /usr/local/nginx/start_perl_cgi.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/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 nagios.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_fcgi.sh
chown nagios.nagcmd $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh
sudo -u nagios $dir/now_start_perl_fcgi.sh
echo  "start perl-fcgi done"
}
case  $ 1  in
stop)
stop
;;
start)
start
;;
restart)
stop
start
;;
esac


nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
server {
          listen        80 ;
          server_name   192.168 . 22.240 ;
          root /usr/local/nagios/share;
          index index.html index.php;
          auth_basic  "nagiosadmin" ;
          auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
location ~ .*\.php?$
   {
     fastcgi_pass    unix:/tmp/php-cgi.sock;
     fastcgi_index   index.php;
     include  fastcgi_params;
     fastcgi_param SCRIPT_FILENAME /usr/local/nagios/share$fastcgi_script_name;
   }
   location /nagios/
   {
     gzip off;
     alias /usr/local/nagios/share/;
     index index.html index.htm index.php;
   }
   location ~ \.cgi$ {
      rewrite ^/nagios/cgi-bin/(.*)\.cgi /$ 1 .cgi  break ;
      fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock;
      fastcgi_index index.cgi;
      fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
      fastcgi_param HTTP_ACCEPT_LANGUAGE en_US;
      include  fastcgi_params;
   }
}
##下面是其他的web服务器
server
         {
                 listen        80 ;
                 server_name abc.com;
                 index index.html index.htm index.php;
                 root  /data;
                 location ~ .*\.(php|php5)?$
                         {
                                 try_files $uri = 404 ;
                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
                                 fastcgi_index index.php;
                                 include  fcgi.conf;
                         }
                 location /status {
                         stub_status on;
                         access_log   off;
                 }
                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                         {
                                 expires      30d;
                         }
                 location ~ .*\.(js|css)?$
                         {
                                 expires      12h;
                         }
                 access_log  /home/wwwlogs/access.log  access;
         }

nginx里面/usr/local/nagios/etc/htpasswd.users 的密码生成,yum安装一个httpd,生成一个密码,或者写 nagiosadmin:50QHC5y6Y1r7k  用户名是nagiosadmin 密码是123456


执行start_perl_cgi.sh,生成perl-fcgi.sock

1
/usr/local/nginx # ./start_perl_cgi.sh start

这个脚本会生成一个now_start_perl_fcgi.sh  

ps aux|grep fcgi

nagios   17577  0.0  0.4 138952  5000 pts/3    S    17:49   0:00 /usr/bin/perl /usr/local/nginx/perl-fcgi.pl -l /usr/local/nginx/logs/perl-fcgi.log -pid /usr/local/nginx/logs/perl-fcgi.pid -S /usr/local/nginx/logs/perl-fcgi.sock


下面是php-fpm的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[global]
pid = /usr/local/php/ var /run/php-fpm.pid
error_log = /usr/local/php/ var /log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi.sock
user = www
group = www
#listen =  127.0 . 0.1 : 9000
#pm =  dynamic
pm =  static
pm.max_children =  10
pm.start_servers =  2
pm.min_spare_servers =  1
pm.max_spare_servers =  6
request_terminate_timeout =  60


如果在nagios页面出现502错误,则修改权限 /usr/local/nginx # chmod 777 logs/perl-fcgi.sock

wKiom1NeJePAO7YXAADi88Kpucw779.jpg


总结:

php-fpm会生成/tmp/php-cgi.sock (参考上面配置),start_perl_cgi.sh 这个脚本会生成 /usr/local/nginx/logs/perl-fcgi.sock

nginx处理php页面用php-cgi.sock,nagios/sbin/下面的cgi用perl-fcgi.sock解析,(有些文章添加了.pl支持,也是perl-fcgi.sock解析

所以只需要安装FCGI支持就可以的


wKiom1NeJs_yfoJcAAL_TBWNGUM505.jpg


如果出现下面问题

It appears as though you do not have permission to view information for any of the services 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


请把/nagios/etc/cgi.cfg 里面use_authentication=1 改为use_authentication=0,因为nginx里面已经包含认证的文件和密码,










本文转自 bbotte 51CTO博客,原文链接:http://blog.51cto.com/bbotte/1404134,如需转载请自行联系原作者
目录
相关文章
|
16天前
|
运维 应用服务中间件 Linux
LNMP详解(十三)——Nginx子页面详解
LNMP详解(十三)——Nginx子页面详解
14 3
|
23天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
26 0
|
22天前
|
运维 负载均衡 应用服务中间件
LNMP详解(九)——Nginx虚拟IP实战
LNMP详解(九)——Nginx虚拟IP实战
34 2
|
22天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
90 0
|
2天前
|
安全 应用服务中间件 网络安全
SSL原理、生成SSL密钥对、Nginx配置SSL
现在,你的Nginx虚拟主机应该已经配置了SSL,可以通过HTTPS安全访问。确保在生产环境中使用有效的SSL证书来保护通信的安全性。
9 0
|
4天前
|
域名解析 缓存 负载均衡
Nginx正向代理域名的配置
Nginx正向代理域名的配置
|
5天前
|
前端开发 JavaScript 应用服务中间件
修改Jeecg-boot context-path(附加图片+Nginx配置)
修改Jeecg-boot context-path(附加图片+Nginx配置)
12 0
|
15天前
|
应用服务中间件 nginx
nginx进行反向代理的配置
在Nginx中设置反向代理的步骤:编辑`/etc/nginx/nginx.conf`,在http段加入配置,创建一个监听80端口、服务器名为example.com的虚拟主机。通过`location /`将请求代理到本地3000端口,并设置代理头。保存配置后,使用`sudo nginx -s reload`重载服务。完成配置,通过example.com访问代理服务器。
24 0
|
16天前
|
运维 监控 应用服务中间件
LNMP详解(十四)——Nginx日志详解
LNMP详解(十四)——Nginx日志详解
16 2
|
16天前
|
应用服务中间件 网络安全 nginx
nginx配置https访问
nginx配置https访问
26 0