nginx下搭建nagios監控環境
2.給Nginx加上對Perl的CGI的支援
(1)安裝FCGI模組
tar zxvf FCGI-0.74.tar.gz
cd FCGI-0.74
perl Makefile.PL
makef
make install
3.安裝FCGI-ProcManager模組
tar zxvf FCGI-ProcManager-0.24.tar.gz
cd FCGI-ProcManager-0.24
perl Makefile.PL
make
make install
4.安裝IO和IO-ALL模組
tar zxvf IO-1.25.tar.gz
cd IO-1.25
perl Makefile.PL
make
make install
cd ..
tar zxvf FCGI-ProcManager-0.24.tar.gz
cd FCGI-ProcManager-0.24
perl Makefile.PL
make
make install
5.在任意目錄下(此處放在/usr/local/bin)建立指令碼fastcgi-wrapper.pl(指令碼內容參照 )
由於此指令碼會在 /var/run/nginx/目錄下生成一個socket檔案,所以執行此指令碼之前要在/var/run/下建立nginx目錄,否則在執行的時候會報錯。
修改指令碼許可權為755:chmod 755 /usr/local/bin/fastcgi-wrapper.pl
執行指令碼啟動perl:perl /usr/lcoal/bin/fastcgi-wrapper.pl
到/var/run/nginx/目錄下如果生成perl_cgi-dispatch.sock,說明指令碼執行成功了。
6.建立nagios使用者,建立組nagcmd
useradd nagios
passwd nagios
groupadd nagcmd
usermod -a -G nagios
usermod -a -G nginx
7.編譯安裝nagios
在安裝nagios之前要先裝gd庫:
yum install gd gd-devel
tar zxvf nagios-3.4.3.tar.gz
cd nagios-3.4.3
./configure --with-command-group=nagcmd
make
make all
make install
make install-init
make install-config
make install-commandmode
到/usr/local/nagios/目錄下,如果看到bin,etc,libexec,include,sbin,share,var這幾個目錄就證明nagios安裝成功了。
進入libexec目錄我們發現裡面是空的,這是由於還沒有安裝nagios的外掛。
8.利用htpasswd工具建立密碼檔案
htpasswd -c /usr/local/nginx/nagiospasswd david --------------密碼檔案存放位置自定
提示輸入密碼
9.修改nagios的配置檔案,使新增使用者有權訪問nagios
cd /usr/local/nagios/etc
vi cgi.cfg
#在一下幾項新增新增的david使用者
authorized_for_system_information=nagiosadmin,david
authorized_for_configuration_information=nagiosadmin,david
authorized_for_system_commands=nagiosadmin,david
authorized_for_all_services=nagiosadmin,david
authorized_for_all_hosts=nagiosadmin,david
authorized_for_all_service_commands=nagiosadmin,david
authorized_for_all_host_commands=nagiosadmin,david
10.編譯安裝nagios外掛
nagios主程式只是提供了一個執行框架,具體的監控功能是靠nagios-plugin完成的。
tar nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
如果在/usr/local/nagios/libexec目錄下看到所有外掛則證明nagios-plugin安裝成功了。
11.修改nginx的配置檔案nginx.conf,以支援perl和php方式訪問nagios
server
{
listen 80;
server_name 146.71.113.42;
access_log logs/access.log;
error_log logs/error.log;
index index.html index.htm index.php;
auth_basic "Nagios";
auth_basic_user_file /usr/local/nginx/nagiospasswd;
root /usr/local/nagios/share;
if ( $request_filename ~ \.(gif|png|jpg|jpeg|ico) ) {
rewrite ^/nagios/(images/.*) /$1 break;
}
if ( $request_filename ~ \.(css) ) {
rewrite ^/nagios/(stylesheets/.*) /$1 break;
}
#php configuration support
location ~ .*\.(php|php5)?$ {
root /usr/local/nagios/share;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location /nagios {
alias /usr/local/nagios/share;
auth_basic "Nagios";
auth_basic_user_file /usr/local/nginx/nagiospasswd;
}
#cgi configuration support
location ~ \.(cgi|pl)?$ {
root /usr/local/nagios/sbin/;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi$2 break;
#fastcgi_pass 127.0.0.1:8999;
fastcgi_pass unix:/var/run/nginx/perl_cgi-dispatch.sock;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$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;
fastcgi_param REMOTE_USER $remote_user;
}
}
12.啟動nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ----------------檢查配置檔案是否正確,如果沒有錯誤就可啟動nagios服務
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg ----------------啟動服務
/usr/local/nagios/bin/nagiostats ----------------檢查nagios的執行狀態
13.主控端安裝nrpe
由於Nagios只能監測自己所在的主機的一些本地情況,例如,cpu負載、記憶體使用、硬碟使用等等。如果想要監測被監控的伺服器上的這些本地情況,就要用到NRPE。NRPE(Nagios Remote Plugin Executor)是Nagios的一個擴充套件,它被用於被監控的伺服器上,向Nagios監控平臺提供該伺服器的一些本地的情況。NRPE可以稱為Nagios的Linux客戶端。
由於NRPE是透過SSL方式在監控和被監控主機上進行資料傳輸的,所以必須先安裝ssl相關的軟體包。
主控端:
tar zxvf nrpe-2.10.tar.gz
cd nrpe-2.10
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
啟動nrpe:
在被控端的配置/usr/local/nagios/etc/nrpe.cfg中
在allowed_hosts=127.0.0.1後面加上",主控端ip"
/usr/local/nagios/libexec/check_nrpe -H localhost ---------------驗證是否被正確安裝
16.回到主控端執行
/usr/local/nagios/libexec/check_nrpe -H 被控端ip ---------------------如果返回nrpe版本號,則說明被控端的nrpe已經配置成功。
17.透過即可訪問nagios監控頁面
================================================================================
說明:在/usr/local/nagios/etc/objects目錄下,有這麼幾個檔案:
command.cfg--------------------------定義命令,這些命令都是利用/usr/local/nagios/libexec目錄下的可執行程式定義的。其中command_name就是命令的名字,此名字在之後定義服務的時候使用,command_line定義具體命令的實現,均為libexec下可執行程式加上變數構成。
templates.cfg----------------------------定義各種模板,如local-service,generic-service,local-host,generic-host,這些模板之後都可以在localhost.cfg中被引用,可節省大量時間且管理方便。
timeperiods.cfg--------------------------監控時間段配置檔案
contacts.cfg------------------------------定義聯絡人,聯絡人組的配置檔案
printer.cfg--------------------------------定義監控印表機的配置檔案模板,預設不啟用此檔案
switch.cfg---------------------------------定義監控路由器的配置檔案模板,預設不啟用此檔案
windows.cfg------------------------------定義監控windows主機的配置檔案模板,預設不啟用此檔案
localhost.cfg------------------------------定義監控本地主機的配置檔案,如果監控本地主機的額外服務,需要在這裡面配置
監控本機特定磁碟情況(以/dev/sda1為例)
1.在command.cfg中定義check_sda1命令,如下:
define command {
command_name check_sda1
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}
2.在localhost.cfg中配置相應的服務,如下:
define service{
use local-service
host_name 192.168.136.128
service_description check_sda1
check_command check_sda1!20%!10%/dev/sda1
}
3.在nrpe.cfg中新增如下內容:
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
4.killall掉nagios,之後重啟即可。
===================================================================
監控遠端主機的服務-----swap,load,users,processes
這裡注意要配置三個配置檔案:主控端---commands.cfg ,services.cfg ,hosts.cfg
被控端---nrpe.cfg
由於我們要監控的是遠端主機,所以一定要在主控端的command.cfg中定義命令check_nrpe。
主控端commands.cfg:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS -t 30 $ARG1$
}
define command{
command_name check_swap
command_line $USER1$/check_swap -w $ARG1$ -c $ARG2$
}
define command{
command_name check_load
command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
}
define command{
command_name check_users
command_line $USER1$/check_users -w $ARG1$ -c $ARG2$
}
define command{
command_name check_procs
command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
}
主控端hosts.cfg:
define host{
use linux-server
host_name 192.168.136.129
alias 192.168.136.129
address 192.168.136.129
}
主控端services.cfg
define service{
use local-service ; Name of service template to use
host_name 192.168.136.129
service_description Swap Usage
check_command check_nrpe!check_swap!20!10
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name 192.168.136.129
service_description Current Load
check_command check_nrpe!check_load!5.0,4.0,3.0!10.0,6.0,4.0
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name 192.168.136.129
service_description Current Users
check_command check_nrpe!check_users!20!50
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name 192.168.136.129
service_description Total Processes
check_command check_nrpe!check_procs!250!400!RSZDT
notifications_enabled 1
}
被控端nrpe.cfg
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_procs]=/usr/local/nagios/libexec/check_procs -w 250 -c 400 -s RSZTD
重啟主控端nagios,被控端nrpe即可。
=======================================================================
被控端自定義命令,服務---------監控/dev/sda1的使用情況
主控端commands.cfg:
define command{
command_name check_sda1_client
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}
主控端services.cfg:
define service{
use local-service
host_name 192.168.136.129
service_description Current sda1
check_command check_nrpe!check_sda1_client!20%!10%!/dev/sda1
notifications_enabled 1
}
被控端nrpe.cfg:
command[check_sda1_client]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 /dev/sda1
主控端重啟nagios,被控端重啟nrpe即可。
================================================================
監控52112埠:
commands.cfg:
define command{
command_name 52112
command_line $USER1$/check_tcp -p 52112
}
services.cfg:
define service{
use local-service
host_name 192.168.136.129
service_description Check 52112
check_command check_nrpe!52112
notifications_enabled 1
}
nrpe.cfg:
command[52112]=/usr/local/nagios/libexec/check_tcp -p 52112
=================================================================
監控sda1裝置IO:
nagios-plugins中預設是沒有check_iostat這個工具的,可到官網下載:
下載完之後放在分別放在主控端和被控端的libexec目錄下,給予可執行許可權。
commands.cfg:
define command{
command_name check_sda1_iostat
command_line $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
}
services.cfg:
define service{
use local-service
host_name 192.168.136.129
service_description Check sda1 IO
check_command check_nrpe!check_sda1_iostat!sda1!1000!2000
notifications_enabled 1
}
nrpe.cfg:
command[check_sda1_iostat]=/usr/local/nagios/libexec/check_iostat -d sda1 -w 1000 -c 2000
===========================================================
監控sda2裝置IO:
commands.cfg:
define command{
command_name check_sda2_iostat
command_line $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
}
services.cfg:
define service{
use local-service
host_name 192.168.136.129
service_description Check sda2 IO
check_command check_nrpe!check_sda2_iostat!sda1!1000!2000
notifications_enabled 1
}
nrpe.cfg:
command[check_sda2_iostat]=/usr/local/nagios/libexec/check_iostat -d sda2 -w 1000 -c 2000
==================================================================
監控網路卡流量:
到nagios官網下載
check_iftraffic_nrpe.pl
分別放到主控端和被控端的libexec目錄下,並改名為check_iftraffic,賦予執行許可權,修改屬組和使用者為nagios。
commands.cfg:
define command{
command_name check_iftraffic
command_line $USER1$/check_iftraffic -i $ARG1$ -w $ARG2$ -c $AGR3$ -b $ARG4$ -u $ARG5$
}
services.cfg:
define service{
use local-service
host_name 192.168.136.129
service_description Check eth0
check_command check_nrpe!check_iftraffic!"eth0"!50!100!100!m
notifications_enabled 1
}
nrpe.cfg:
command[check_iftraffic]=/usr/local/nagios/libexec/check_iftraffic -i eth0 -w 50 -c 100 -b 100 -u m
===============================================================================
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29800581/viewspace-1434899/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- nagios 監控windows環境簡要說明iOSWindows
- Windows環境下的Nginx環境搭建WindowsNginx
- Nagios監控系統搭建iOS
- AIX環境下監控程式指令碼AI指令碼
- Nginx下構建nagios監控平臺Nagios+nrpe+nagios-plugins+pnp安裝文件薦NginxiOSPlugin
- linux下nginx+php+mysql環境搭建LinuxNginxPHPMySql
- nagios監控例項 -- PostgreSQL監控iOSSQL
- LNMP環境搭建(二):NginxLNMPNginx
- Docker 之 Nginx環境搭建DockerNginx
- LNMP環境搭建——Nginx篇LNMPNginx
- REDHAT環境下使用SYSSTAT監控系統效能Redhat
- Linux下信用盤SGWIN程式搭建PHP+Nginx環境搭建LinuxPHPNginx
- 搭建 lnmp 環境之 nginx 篇LNMPNginx
- windows環境下Django環境搭建WindowsDjango
- nagios批量新增監控iOS
- 使用nagios監控oracleiOSOracle
- PHP入門-Window 下利用Nginx+PHP 搭建環境PHPNginx
- mac系統下git、mysql、nginx、php的環境搭建MacGitMySqlNginxPHP
- WINDOWS 環境下 監控ORACLE臨時表空間WindowsOracle
- Nginx+Lua開發環境搭建Nginx開發環境
- win7下搭建nginx+php的開發環境Win7NginxPHP開發環境
- nagios的配置(監控端和被監控端)iOS
- nagios監控例項 -- Windows伺服器監控iOSWindows伺服器
- Node.js環境效能監控Node.js
- 運維監控利器nagios運維iOS
- Nagios 監控ESXI指令碼iOS指令碼
- nginx監控Nginx
- window環境下testlink環境搭建(xammp)
- 以太坊-Win環境下remix環境搭建REM
- 在原始碼安裝的LAMP環境中搭建Nagios原始碼LAMPiOS
- mac 下搭建flutter環境MacFlutter
- Windows 下搭建 lnmp 環境WindowsLNMP
- Centos下搭建golang環境CentOSGolang
- Windows下搭建Solr環境WindowsSolr
- windows下搭建lisp環境WindowsLisp
- docker下LNMP環境搭建DockerLNMP
- centos6.2lnmp環境下安裝zabbix(中文環境)並且監控客戶端CentOSLNMP客戶端
- Jenkins +nginx 搭建前端構建環境JenkinsNginx前端