今天在车中读了nagios一段内容。回到家里,想试验一下,因此在一台CentOS6.4(x64)机器上进行了安装。
https://www.nagios.org/downloads/nagios-plugins/
https://www.nagios.org/downloads/nagios-core-addons/
文档
https://library.nagios.com/library/products/nagioscore/manuals/
需要软件。
- nagios-4.1.1.tar.gz --nagios core
- nagios-plugins-2.1.1.tar.gz --nagios plugin
- nrpe-2.15.tar.gz --nagios nrpe 远程收集plugin
服务器需要安装上面三个软件。
被监控端需要安装后面两个软件。
------------------------- -------------------------
| nagios -> check_nrpe | -> | NRPE-> check_disk |
-------------------------- | -> check_http |
监控主机 | -> check_load |
-------------------------
被监控主机
在192.168.40.193中进行安装。
将上面的文件上传到/home/src中。
首先安装监控主机:
尽管是在一台机器,也当作先安装监控主机。
1. 安装基础库
需要以下库:gcc glibc glibc-common gd gd-devel xinetd openssl-devel
其中gd-devel没有,由于在光盘中不存在,因此没有安装。
# rpm -q gcc glibc glibc-common gd gd-devel xinetd openssl-devel
如果系统中没有这些套件,使用yum 安装
# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
2. 创建nagios用户和用户组
# useradd -s /sbin/nologin nagios
# mkdir /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios
查看nagios 目录的权限
# ll -d /usr/local/nagios/
3.安装nagios cores
scp /home/src/nagios-4.1
tar xvf nagios-4.1.1.tar.gz
cd nagios-4.1.1
# ./configure --prefix=/usr/local/nagios
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# chkconfig --add nagios
# chkconfig --level 35 nagios on
# chkconfig --list nagios
4.安装nagios plugins
tar xvf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
[root@jclinux03 nagios-plugins-2.1.1]# ./configure --prefix=/usr/local/nagios
# make && make install
[root@jclinux03 nagios-4.1.1]# make install-webconf
5.安装光盘中的php和apache.
httpd好像已经安装好了。
yum install -y php
使用系统的php和apache。
/etc/httpd/conf
vi httpd.conf
DirectoryIndex index.html index.html.var index.php
~~~~~~~~~~
AddType application/x-httpd-php .php
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
为了简化,这里没有使用nagios认证,需要的人可以自己添加。
如果出错,/etc/httpd/log中有出错信息。
[root@jclinux03 /]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
来运行nagios,看看是否出错。如果出错则,需要重新配置。
service nagios start
如果出现Ok则,启动成功。
http://主机IP/nagios
如果启动后发现"Internal Error"的错误。
看看linux enforce是否启动getenforce。 如果为enabled。需要运行setenforce 0
[root@jclinux03 /]# vi /etc/selinux/config
将设置为disabled.
6.安装check_nrpe
应该安装好插件后就可以了,应该将libexec目录设置为nagios用户。
[root@jclinux03 xinetd.d]# chown -R nagios.nagios /usr/local/nagios/libexec
[root@jclinux03 src]# cd /home/src
[root@jclinux03 src]# tar xvf nrpe-2.15.tar.gz
vi README
可以发现需要执行的程序。
在解压缩目录下有nrpe.pdf文件。
[root@jclinux03 nagios]# ./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
vi /etc/xinetd.d/nrpe
# only_from = 127.0.0.1
注释掉。
vi /etc/services
添加以下行。
nrpe 5666/tcp #nrpe
service xinetd restart
netstat -at | grep nrpe
检查是否正确配置。
[root@jclinux03 nrpe-2.15]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.15
在远程主机
安装nagios插件,设置目录权限。由于本次是同一台机器,因此不需要进行安装了。
安装nrpe插件。同上面一样。
vi /usr/local/nagios/etc/nrpe.cfg
添加以下的监控命令。
command[check_users_1]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load_1]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk_1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/vg_jclinux01-lv_root
command[check_procs_1]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
vi /usr/local/nagios/etc/commands.cfg
# check_nrp command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
vi /usr/local/nagios/etc/service.cfg
define host{
use linux-server
host_name jclinux03
alias My Linux Host
address 127.0.01
}
define service{
use local-service
host_name jclinux03
service_description users
check_command check_nrpe!check_user_1
}
define service{
use local-service
host_name jclinux03
service_description load
check_command check_nrpe!check_load_1
}
define service{
use local-service
host_name jclinux03
service_description disk
check_command check_nrpe!check_disk_1
}
define service{
use local-service
host_name jclinux03
service_description proc
check_command check_nrpe!check_proc_1
}
define servicegroup {
servicegroup_name servicegroup
alias service-group
members jclinux03,users,jclinux03,load,jclinux03,disk,jclinux03,proc
}
[root@jclinux03 nrpe-2.15]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@jclinux03 nrpe-2.15]# service nagios restart
在网页中会出现下面的错误。
It appears as though you do not have permission to view process information...
只要将CGI认证进行修改就可以了。
修改/etc/cgi.cfg
vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1 #把1修改为0,保存
#/service[/email] nagios restart
http://IP/nagios/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/18455/viewspace-2083704/
,如需转载,请注明出处,否则将追究法律责任。