centos 5.5 nginx nagios监控端和被控端安装配置指南
# tar zxvf nagios-3.2.2.tar.gz
# cd nagios-3.2.2
# useradd -m -s /bin/bash nagios
# groupadd nagios
# usermod -G nagios nagios
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd www
# ./configure --prefix=/data/nagios --with-command-group=nagcmd
# make
# make all
# make install
# make install-init # 生成init启动脚本
# make install-config # 安装示例配置文件
# make install-commandmode # 设置相应的目录权限
# tar zxvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/data/nagios
# make
# make install
# cd nrpe-2.12
# ./configure
# make all
# cp src/check_nrpe /data/nagios/libexec/
# 加入系统服务并设为开机自动
# chkconfig --add nagios
# chkconfig nagios on
# chown nagios.nagios /data/nagios/var/rw
# /data/nagios/bin/nagios -v /data/nagios/etc/nagios.cfg
# vi /data/nagios/etc/cgi.cfg
找到use_authentication=1并把值改为0
# vi /data/nagios/etc/objects/contacts.cfg
# vi /data/nagios/etc/objects/commands.cfg
1
2
3
4
|
define command{
command_name check_nrpe
command_line /data/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
|
# service nagios start
01
02
03
04
05
06
07
08
09
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
|
server {
listen 88;
server_name _;
location / {
root /data/nagios/share;
index index.html index.htm index.php;
}
location ~ .*.(php|php5)?$
{
root /data/nagios/share;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location /nagios {
alias /data/nagios/share;
}
location /cgi-bin/p_w_picpaths {
alias /data/nagios/share/p_w_picpaths;
}
location /cgi-bin/stylesheets {
alias /data/nagios/share/stylesheets;
}
location /cgi-bin {
alias /data/nagios/sbin;
}
location ~ .*.(cgi|pl)?$
{
gzip off;
root /data/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*).cgi /$1.cgi break;
fastcgi_pass unix:/data/nginx/logs/perl-fcgi.sock;
fastcgi_index index.cgi;
include fcgi.conf;
fastcgi_read_timeout 60;
}
}
|
# useradd nagios -M -s /sbin/nologin -g nagios
# tar zxvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-gourp=nagios && make && make install
# cd nrpe-2.12
# ./configure --prefix=/usr/local/nagios && make && make install
# cp sample-config/nrpe.cfg /usr/local/nagios/etc/
# vi /usr/local/nagios/etc/nrpe.cfg
修改 allowed_hosts 值为监控端的IP
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# chmod 755 /data/nagios/libexec/check_squid
# yum -y install perl-libwww-perl
url squid dst站点域名 如: http://www.xtgly.com
urluser 目标站点需要认证登录的用户名, 符号"-"代表没有
urlpass 目标站点需要认证登录的用户密码, 符号"-"代表没有
proxy squid cache服务器的IP地址或者域名
proxyport Squid cache服务器监听的端口,默认3128
proxyuser squid cache服务器需要认证登录的用户名, 符号"-"代表没有
proxypass squid cache服务器需要认证登录的用户名, 符号"-"代表没有
expectstatus HTTP协议返回的HTTP code, 符号"2"代表从2开始
# /data/nagios/libexec/check_squid http://www.xtgly.com - - 74.82.*.* 80 - - 2
OK - Status: 200 OK
# vi /data/nagios/etc/objects/commands.cfg 加入
1
2
3
4
|
define command {
command_name check_squid
command_line $USER1$/check_squid $ARG1$ $ARG2$ $ARG3$ $HOSTADDRESS$ $ARG4$ $ARG5$ $ARG6$ $ARG7$
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
|
define host{
use linux-server
host_name 74.82.*.*
alias 74.82.*.*
address 74.82.*.*
}
define hostgroup{
hostgroup_name CDN
alias CDN Servers
members 74.82.*.*
}
define service{
use generic-service
host_name 74.82.*.*
service_description Squid
check_command check_squid!http://www.xtgly.com!-!-!80!-!-!2
notifications_enabled 0
}
|
2.监控mysql
添加数据库监控帐号密码
mysql> CREATE USER 'jk'@'127.0.0.1' IDENTIFIED BY 'jk';
mysql> flush privileges;
# vi /data/nagios/etc/objects/commands.cfg 加入
1
2
3
4
|
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$
}
|
# vi /data/nagios/etc/objects/hosts.cfg 加入
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
|
define host{
use linux-server
host_name 74.82.*.*
alias 74.82.*.*
address 74.82.*.*
}
define hostgroup{
hostgroup_name 74.82.*.*
alias DirectAdmin
members 74.82.*.*
}
define service{
use generic-service
host_name 74.82.*.*
service_description mysql
check_command check_mysql!74.82.*.*!3306!ptjk!ptjk3310000
notifications_enabled 0
}
|
3.监控apache状态
apache服务端添加状态显示
1
2
3
4
5
|
SetHandler server-status
Order deny,allow
Deny from all
Allow from localhost
|
nagios服务端操作
# 安装终端web浏览器
# yum install lync
# 下载check_apachestatus,并放至/data/nagios/libexec目录下
# cd /data/nagios/libexec
# wget http://exchange.nagios.org/components/com_mtree/p_w_upload.php?link_id=1376&cf_id=24
# mv check_apachestatus.pl check_apachestatus (如果nagios不在/usr/local目录下,注意修改这个脚本里的路径)
# chown nagios:nagios check_apachestatus
# chmod 755 check_apachestatus
# vi /data/nagios/etc/objects/commands.cfg 加入
1
2
3
4
|
define command{
command_name check_apachestatus
command_line $USER1$/check_apachestatus -H $HOSTADDRESS$ -p $ARG1$
}
|
# vi /data/nagios/etc/objects/hosts.cfg 加入
1
2
3
4
5
6
7
|
define service{
use generic-service
host_name 74.82.*.*
service_description http
check_command check_apachestatus!81
notifications_enabled 1
}
|
4.监控rsync
# 下载脚本check_rsync,放至/data/nagios/libexec,注意脚本里的nagios路径需要修改
# cd /data/nagios/libexec
# wget http://exchange.nagios.org/components/com_mtree/p_w_upload.php?link_id=307&cf_id=29
# chown nagios:nagios check_rsync
# chmod 755 check_rsync
# vi /data/nagios/etc/objects/commands.cfg 加入
1
2
3
4
|
define command{
command_name check_rsync
command_line $USER1$/check_rsync -H $HOSTADDRESS$ -p $ARG1$
}
|
# vi /data/nagios/etc/objects/hosts.cfg 加入
1
2
3
4
5
6
7
|
define service{
use generic-service
host_name 74.82.*.*
service_description rsync
check_command check_rsync!873
notifications_enabled 1
}
|
5.监控nginx
# nginx服务端添加状态显示
1
2
3
4
5
6
7
8
|
server {
listen 84;
server_name _;
location / {
stub_status on;
access_log off;
}
}
|
# 下载check_nginx,并放至/data/nagios/libexec目录下
# cd /data/nagios/libexec
# wget http://www.nginxs.com/download/check_nginx
# chown nagios:nagios check_nginx
# chmod 755 check_nginx
# vi /data/nagios/etc/objects/commands.cfg 加入
1
2
3
4
|
define command{
command_name check_nginx
command_line $USER1$/check_nginx -U $ARG1$
}
|
# vi /data/nagios/etc/objects/hosts.cfg 加入
1
2
3
4
5
6
7
|
define service{
use generic-service
host_name 74.82.*.*
service_description http
check_command check_nginx!74.82.*.*:84
notifications_enabled 1
}
|
四、nagios cacti npc 整合 (注意php要支持pho-mysql)
# tar zxvf ndoutils-1.4b9.tar.gz
# cd ndoutils-1.4b9
# vi include/config.h
找到261行
1
2
|
#include
#include
|
修改为
1
2
|
#include
#include
|
# ./configure --enable-mysql --disable-pgsql --with-mysql=/data/mysql --with-mysql-lib=/data/mysql/lib
# make
# cp src/ndomod-3x.o /data/nagios/bin/ndomod.o
# cp src/ndo2db-3x /data/nagios/bin/ndo2db
# cp src/log2ndo /data/nagios/bin
# cp src/file2sock /data/nagios/bin
# cp config/ndomod.cfg-sample /data/nagios/etc/ndomod.cfg
# cp config/ndo2db.cfg-sample /data/nagios/etc/ndo2db.cfg
# chown -R nagios:nagios /data/nagios/
# vi /data/nagios/etc/ndomod.cf 主要修改路径,本例如下:
01
02
03
04
05
06
07
08
09
10
11
12
13
|
instance_name=default
output_type=tcpsocket
output=127.0.0.1
tcp_port=5668
use_ssl=0
output_buffer_items=5000
buffer_file=/data/nagios/var/ndomod.tmp
file_rotation_interval=14400
file_rotation_timeout=60
reconnect_interval=15
reconnect_warning_interval=15
data_processing_options=-1
config_output_options=2
|
# vi /data/nagios/etc/ndo2db.cfg 主要修改mysql帐号密码,本例如下:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
lock_file=/data/nagios/var/ndo2db.lock
ndo2db_user=nagios
ndo2db_group=nagios
socket_type=tcp
socket_name=/data/nagios/var/ndo.sock
tcp_port=5668
use_ssl=0
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cacti
db_prefix=npc_
db_user=root
db_pass=iammysql
max_timedevents_age=1440
max_systemcommands_age=10080
max_servicechecks_age=10080
max_hostchecks_age=10080
max_eventhandlers_age=44640
max_externalcommands_age=44640
debug_level=-1
debug_verbosity=2
debug_file=/data/nagios/var/ndo2db.debug
max_debug_file_size=1000000
|
# vi /data/nagios/etc/nagios.cfg 添加以下内容
1
2
3
4
5
|
check_external_commands=1
command_check_interval=-1
event_broker_options=-1
broker_module=/data/nagios/bin/ndomod.o config_file=/data/nagios/etc/ndomod.cfg
process_performance_data=1
|
# ln -s /data/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib/
# 启动ndo2db
# /data/nagios/bin/ndo2db -c /data/nagios/etc/ndo2db.cfg
# cd /tmp
# wget http://www.constructaegis.com/downloads/npc-2.0.4.tar.gz
# tar zxvf npc-2.0.4.tar.gz
# mv npc /data/nginx/html/cacti/plugins/
# chown -R www:www /data/nginx/html/
1
2
3
4
5
6
7
8
|
ALTER TABLE `npc_hostchecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_hoststatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicechecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicestatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_statehistory` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_eventhandlers` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_systemcommands` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_notifications` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
|
转载于:https://blog.51cto.com/daniang/849958