1
2
3
|
yum
install
-y httpd httpd-devel php php-gd php-devel php-mysql php-pdo php-mbstring php-snmp net-snmp-* perl-DBD-MySQL glibc glibc-common libjpeg libjpeg-devel libpng libpng-devel zlib zlib-devel gd gd-devel
service httpd start
chkconfig httpd on
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
groupadd nagcmd
useradd
-G nagcmd nagios
usermod
-a -G nagcmd apache
tar
zxvf nagios-3.4.1.
tar
.gz
cd
nagios
.
/configure
--with-nagios-group=nagios --
enable
-event-broker
#整合时间代理程序,默认安装/usr/local/nagios
make
all
make
install
#安装主要的程序、CGI及HTML文件
make
install
-init
#生成init启动脚本
make
install
-config
#安装示例配置文件
make
install
-commandmode
#设置相应的目录权限
make
install
-webconf
#安装Apache配置文件,Nginx下不需要
chown
nagios:nagios -R
/usr/local/nagios/
/usr/local/nagios/bin/nagios
-
v
/usr/local/nagios/etc/nagios
.cfg
#验证nagios配置文件
Service nagios start
chkconfig nagios on
|
1
2
|
htpasswd -c
/usr/local/nagios/etc/htpasswd
.
users
test
New password: 123456
|
1
2
|
vi
/usr/local/nagios/etc/objects/contacts
.cfg
contact_name nagiosadmin
#把nagiosadmin修改为test
|
1
2
3
4
|
tar
zxvf nagios-plugins-1.4.16.
tar
.gz
cd
nagios-plugins-1.4.16
.
/configure
--with-nagios-user=nagios --with-nagios-group=nagios --with-mysql=
/usr/local/mysql
#添加监控mysql支持
make
&&
make
install
|
1
2
3
4
5
6
7
8
|
vi
nagios
/etc/cgi
.cfg
#默认授权的都是nagiosadmin,改为*所有用户
authorized_for_system_information=*
authorized_for_configuration_information=*
authorized_for_system_commands=*
authorized_for_all_services=*
authorized_for_all_hosts=*
authorized_for_all_service_commands=*
authorized_for_all_host_commands=*
|
1
2
3
4
5
|
tar
zxvf nrpe-2.13.
tar
.gz
#基于nrpe检测,所以必须也要安装
cd
nrpe-2.13
.
/configure
--with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
all
make
install
-plugin
|
1
2
3
4
5
|
vi
/usr/local/nagios/etc/objects/commands
.cfg 末尾添加:
define
command
{
command_name check_nrpe
#定义命令名称为check_nrpe,在services.cfg中要使用这个名称
command_line $USER1$
/check_nrpe
-H $HOSTADDRESS$ -c $ARG1$
}
#这是定义实际运行的插件程序,-c后面带的$ARG1$参数是传给nrpe daemon执行的检测命令
|
1
2
3
|
vi
/usr/local/nagios/etc/nagios
.cfg
在 cfg_file=
/usr/local/nagios/etc/objects/localhost
.cfg 下添加:
cfg_file=
/usr/local/nagios/etc/objects/linux
.cfg
|
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
|
vi
/usr/local/nagios/etc/objects/linux
.cfg
define host{
use linux-server
host_name squid.
test
.com
alias
my squid
#web页面显示的名字
address 192.168.0.202
#被监控主机ip
}
define service{
use generic-service
host_name squid.
test
.com
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name squid.
test
.com
service_description check-disk
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name squid.
test
.com
service_description check-
ssh
check_command check_nrpe!check_ssh
}
define service{
use generic-service
host_name squid.
test
.com
service_description check-http
check_command check_nrpe!check_http
}
保存退出!
/usr/local/nagios/bin/nagios
-
v
/usr/local/nagios/etc/nagios
.cfg
#验证nagios配置文件
service nagios restart
设置开机启动:
echo
"/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d"
>>
/etc/rc
.
local
|
1
2
3
4
5
|
useradd
-s
/sbin/nologin
nagios
tar
-zxvf nagios-plugins-1.4.14.
tar
.gz
cd
nagios-plugins-1.4.14
.
/configure
--with-nagios-user=nagios --with-nagios-group=naigos
make
all &&
make
install
|
1
2
3
4
5
6
7
8
|
tar
-zxvf nrpe-2.12.
tar
.gz
cd
nrpe-2.12
.
/configure
--with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
all
make
install
-plugin
make
install
-daemon
make
install
-daemon-config
make
install
-xinetd
#nrpe安装为xinetd服务
|
1
2
3
4
5
6
7
8
9
|
vi
/etc/xinetd
.d
/nrpe
only_from = 127.0.0.1,192.168.0.204
#添加监控主机地址
vi
/usr/local/nagios/etc/nrpe
.cfg
allowed_hosts=127.0.0.1,192.168.0.204
#允许监控主机对其监控
/usr/local/nagios/bin/nrpe
-c
/usr/local/nagios/etc/nrpe
.cfg -d
#启动nrpe
netstat
-tuplna |
grep
5666 或
ps
-elf |
grep
nrpe
#查看是否启动
/usr/local/nagios/libexec/check_nrpe
-H 192.168.0.203
#在监控端检测被监控端信息,显示版本则成功。
设置开机启动:
echo
"/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d"
>>
/etc/rc
.
local
|
1
2
|
vi
/usr/local/nagios/etc/nagios
.cfg
cfg_file=
/usr/local/nagios/etc/objects/windows
.cfg
#去掉注释
|
1
2
3
4
|
define
command
{
command_name check_nt
command_line $USER1$
/check_nt
-H $HOSTADDRESS$ -p 12489 -
v
$ARG1$ $ARG2$
}
|
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
|
vi
/usr/local/nagios/etc/objects/windows
.cfg
define host{
use windows-server
host_name winserver
alias
My Windows Server
address 192.168.0.202
#被监控主机ip
}
define hostgroup{
hostgroup_name windows-servers
alias
Windows Servers
}
define service{
use generic-service
host_name winserver
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
define service{
use generic-service
host_name winserver
service_description Uptime
check_command check_nt!UPTIME
}
define service{
use generic-service
host_name winserver
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
define service{
use generic-service
host_name winserver
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
define service{
use generic-service
host_name winserver
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use generic-service
host_name winserver
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
define service{
use generic-service
host_name winserver
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}
|