nginx+nagios在ubuntu下搭建過程全程指導

大搜車-自娛發表於2012-04-07
今天終於把nginx+nagios在我自己的ubuntu機器下搭建起來,特此寫一個教程,有2個目的,1作為備忘錄留為己用,2作為新手教程指導。

1.安裝nginx,在ubuntu下apt-cache search nginx可以搜尋到nginx包,我安裝的是0.7.65版本。

fcgiwrap - simple server to run CGI applications over FastCGI
collectd-core - statistics collection and monitoring daemon (core system)
nginx - small, but very powerful and efficient web server and mail proxy
nginx-dbg - Debugging symbols for nginx
php5-fpm - server-side, HTML-embedded scripting language (FPM binary)


2.此處列出了fagiwrap包以及php5-fpm包均是以後需要安裝的包,如果搜尋得到即可立即安裝否則等待下面的步驟進行安裝。安裝方法:
sudo apt-get install nginx


3.nginx部署nagios需要安裝fagiwrap以及php5-fpm,可以先進行安裝,我安裝的nagios3.2.0版本是不帶有這2個ubuntu包的。


4.fagiwrap以及php5-fpm的安裝方法:[url=http://myeyeofjava.iteye.com/blog/1477873]參考我的另一篇文章[/url]


5.啟動fcgiwrap以及php5-fpm服務,這裡要記得修改2個包的配置檔案,將執行方式修改為sock方式則可以在如下目錄生成相應的socket檔案unix:/var/run/fcgiwrap.socket,unix:/var/run/php5-fpm.sock,另fastcgi內包含大量的指令碼檔案cgi,這些指令碼會在/etc/nginx/fastcgi_params目錄下,如果你安裝的fastcgi版本低,則該目錄下是一個.conf的檔案,修改php5-fpm的監聽方式修改/etc/php5/fpm/php5-fpm.conf檔案,找到如下位置並修改成這個樣子
listen = /var/run/php5-fpm.sock
;listen = 127.0.0.1:9000

6.給nagios訪問新增驗證服務,建立一個nagiosadmin的使用者用於Nagios的WEB介面登入。記下你所設定的登入口令,一會兒你會用到它
這裡要藉助於apche的htpasswd,在有apache機器上執行下列命令

/usr/local/apache2/bin/htpasswd -c /usr/local/server/nginx/conf/htppasswd nagiosadmin


7.修改nginx配置:

user www-data;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
# multi_accept on;
}

http {
include /etc/nginx/mime.types;

access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

server {
listen 9999;
server_name 10.18.105.110;
auth_basic "Restricted Nagios Area!";
auth_basic_user_file /opt/nagios/etc/htpasswd.users;
charset utf-8;
root /usr/share/nagios3/htdocs ;
index index.html index.htm index.php;

location /nagios3/stylesheets {
alias /etc/nagios3/stylesheets;
}


location /nagios3/images {
alias /usr/share/nagios3/htdocs/images;
}

location ~ \.cgi$ {
root /usr/lib/cgi-bin/nagios3;

rewrite ^/cgi-bin/nagios3/(.*)$ /$1;

include /etc/nginx/fastcgi_params;

fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/nagios3$fastcgi_script_name;

fastcgi_pass unix:/var/run/fcgiwrap.socket;
}

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}}
}


8.配置檔案內著重注意的地方1,root /usr/share/nagios3/htdocs ,nagios首頁頁面所在位置,不要定位到example的index頁面上去,2,樣式以及圖片的過濾路徑,有可能找不到需要你去配置,3.找不到cgi指令碼報指令碼名或者document root錯誤,4,fastcgi引數有include /etc/nginx/fastcgi_params;老版本可能是一個配置檔案,而不是一個資料夾,5,fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/nagios3$fastcgi_script_name; 這裡最好重新定位一下你的指令碼在哪裡,否則fastcgi自帶的配置檔案仍然報找不到指令碼


參考文件:

[url=http://bbs.linuxtone.org/thread-4441-1-1.html]在nginx上搭建nagios[/url]
[url=http://www.3g4k.com/Index/articlecontent/id/49]ubuntu php5-fpm安裝[/url]
[url=http://vladgh.com/blog/nagios-nginx-ubuntu]Nagios with NginX in Ubuntu [/url]
[url=http://johan.cc/2012/02/06/nagios-nginx/]How to serve nagios with nginx[/url]

相關文章