標籤:基於nginx環境部署nagios
安裝思路,僅供參考
####nagios安裝
yum install gd-devel -y
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www
tar xzf nagios-3.5.0.tar.gz
cd nagios
./configure --with-group=nagios --with-user=nagios --with-command-group=nagcmd --prefix=/usr/local/nagios
make all
make install #用於安裝主要的程式、CGI及HTML檔案
make install-init #用於產生init啟動指令碼
make install-config #用於安裝樣本設定檔
make install-commandmode #用於設定相應的目錄許可權
設定nagios web登陸帳號密碼
htpasswd -c /usr/local/nagios/etc/nagiospasswd nagiosadmin
New password:
Re-type new password:
[ Adding password for user nagios
給nagios使用者開許可權,讓他能夠查看資訊! [網站管理員的名字 就是你htpasswd.users中的使用者]
vim /usr/local/nagios/etc/cgi.cfg
在所有的nagiosadmin後面添加nagios 多個使用者之間用逗號隔開 或者直接替換為nagios即可
]
#####安裝外掛程式
tar zxf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/
make
make install
#########
安裝FCGI模組
wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz
tar -zxvf FCGI-0.67.tar.gz
cd FCGI-0.67
perl Makefile.PL
make && make install
安裝FCGI-ProcManager:
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.18.tar.gz
tar -xzxf FCGI-ProcManager-0.18.tar.gz
cd FCGI-ProcManager-0.18
perl Makefile.PL
make && make install
安裝IO和IO::ALL模組
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz
tar zxvf IO-1.25.tar.gz
cd IO-1.25
perl Makefile.PL
make
make install
cd ..
wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gz
tar zxvf IO-All-0.41.tar.gz
cd IO-All-0.41
perl Makefile.PL
make
make install
cd ..
################################################################################################################
nginx的配置
##########安裝nginx
yum install gcc openssl-devel pcre-devel zlib-devel -y
useradd -s /sbin/nologin
useradd -s /sbin/nologin www
tar zixf nginx-1.5.1.tar.gz
cd nginx-1.5.1
./configure --prefix=/usr/local/nginx
make && make install
安裝php
php-5.4.11.tar.bz2 php-5.2.9-fpm-0.5.10-unofficial.diff.gz
tar fvxj php-5.4.11.tar.bz2
gzip -cd php-5.2.9-fpm-0.5.10-unofficial.diff.gz | patch -d php-5.4.11 -p1
./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --disable-fileinfo(當記憶體小於1G加上這個 不然會報錯,若提示不能識別fstcgi,無影響高版本內建此模組不需添加)
make
make install
cp php.ini-production /usr/local/php/lib/php.ini
修改設定檔使用者名稱使用者組(與nginx使用者、組相同)
PHP-FPM的預設設定檔為/usr/local/php/etc/php-fpm.conf
user www
group www
啟動
/usr/local/php/sbin/php-fpm
下載perl指令碼,用來產品perl的fast-cgi介面,讓nginx以CGI的形式來處理perl ,修改許可權為755
wget http://www.mike.org.cn/wp-content/uploads/2011/07/perl-fcgi.zip
解壓並複製到nginx目錄下(建議)
cp perl-fcgi.pl /usr/local/nginx/
chown 755 /usr/local/nginx/perl-fcgi.pl
chmod +x /usr/local/nginx/perl-fcgi.pl
建立一個cgi啟動/停止的指令碼,用來管理上面的指令碼,使用者身份是www,需要根據自己的實際使用者來修改 ,修改許可權755
vim /usr/local/nginx/conf/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 www.www $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 www.www $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh
sudo -u www $dir/now_start_perl_fcgi.sh
echo "start perl-fcgi done"
}
case $1 in
stop)
stop
;;
start)
start
;;
restart)
stop
start
;;
esac
啟動perl
/usr/local/nginx/conf/start_perl_cgi.sh start
#########################################
nginx設定檔
vi nginx.conf
user www www;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server
{
listen 80;
index index.html index.htm index.php;
root /usr/local/nagios/share;
auth_basic "Nagios Access";
auth_basic_user_file /usr/local/nagios/etc/nagiospasswd;
location ~ .*\.(php|php5)?$
{
;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(cgi|pl)?$
{
gzip off;
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
fastcgi_index index.cgi;
fastcgi_read_timeout 60;
fastcgi_param REMOTE_USER $remote_user;
include fastcgi.conf;
auth_basic "Nagios Access";
auth_basic_user_file /usr/local/nagios/etc/nagiospasswd;
}
location /nagios
{
alias /usr/local/nagios/share;
auth_basic "Nagios Access";
auth_basic_user_file /usr/local/nagios/etc/nagiospasswd;
}
access_log /data1/logs/access_www.log wwwlogs;
}
}
若遇到報錯,查看error.log
本文出自 “營運風雲二十年” 部落格,請務必保留此出處http://huangqingwu.blog.51cto.com/9592044/1674902
基於nginx環境部署nagios