测试环境,发行版本均为centos6.5:
监控主机:192.168.1.213(以下简称213)
被监控主机:192.168.1.210(以下简称210)
监控原理:
此处monitoring host为213
remote linux/unix host为210
【监控机213】
以下均在root中操作
先yum install gcc gd gd-devel glibc glibc-devel
然后确保apache已经安装
若无,则yum install httpd
#附带两个操作
启动apache服务:service httpd start
将apache服务作为开机启动项:chkconfig --level 345 httpd on
建立nagios用户及用户组:
user add -m nagios
passwd nagios
groupadd nagcmd
usermod -G nagcmd nagios
首先下载nagios-3.5.1.tar.gz
将下载好的tar包放入/usr/local/目录中
tar -zxvf nagios-3.5.1.tar.gz
cd nagios-3.5.1
./configure --with-command-group=nagcmd
初始化后进行编译安装
make install
make install-init
make install-config
make install-commandmode
make install-webconf
安装完后,应该可以在/usr/local/nagios下看到:
bin etc include libexec sbin share var
这些文件夹若有,则表示nagios安装成功(nagios-core)
相关的apache配置文件为/etc/http/conf.d/nagios.conf
htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
其中admin为后续需要登录到监控平台的用户名,接下来输入密码则为该用户的密码
可以在 /usr/local/nagios/etc/htpasswd.user来查看。
继续下载nagios-plugins插件
此处我用的是nagios-plugins-2.0.3
在/usr/local中:
tar -zxvf 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
nagios验证nagios.cfg配置文件:(nagios.cfg为nagios的主配置文件)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果无警告错误,可启动nagios服务。
service nagios start
接下来需要安装NRPE插件
NRPE可以向nagios监控平台提供该服务器的一些本地的情况。
此处我用的NRPE版本是2.15
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
在监控主机213上安NRPE插件实际上是为了简易快速地安装check_nrpe
【被监控机210】
接下来需要在被监控主机上安装:
useradd nagios
passwd nagios
此处需要安装nagios-plugins和NRPE。
步骤如上:
tar -zxvf 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
然后
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
修改用户所属
chown nagios.nagios /usr/local/nagios
接下来需要确认是否安装xinetd,若有,则不需要,若无,可以yum install xinetd。
然后继续在nrpe文件夹中
make install-xinetd
打开vi /etc/xinetd.d/nrpe
然后修改 only_from 将值改为 192.168.1.213
即允许213的主机对本机进行监控。
vi /etc/service
加入nrpe 5666/tcp # nrpe
重启xinetd服务:
/etc/init.d/xinetd restart
查看nrpe:
netstat -nl | grep 5666
【监控机213】
继续切回监控机
通过check_nrpe插件来验证210上的nrpe是否可用:
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.210
若出现版本号,如v2.15则表示监测主机能够通过SSL与被监测主机上的NRPE正常通信。
如果报错,可以检查以下问题
1. nrpe的版本号和nrpe-plugin的版本号是否一致。版本不一致极有可能造成该问题。
2. SSL是否被关闭。确保NRPE以及check_nrpe插件在编译的时候都加入了SSL支持,同时在运行时都开启SSL。不过一般编译过程中默认都会假如支持SSL选项。
3. 确保NRPE的配置文件nrpe.cfg文件可以被nagios用户读取并且nagios用户可以执行nrpe二进制程序。
4. 确认在/etc/xinetd.d/nrpe文件的“only_from=x.x.x.x”中x.x.x.x是访问NRPE的监测主机的IP地址。
cd /usr/local/nagios/etc
进入nagios的配置文件夹
vi objects/localhost.cfg
删除或注释HOST DEFINITION和“HOST GROUP DEFINITION的内容。
保留SERVICE DEFINITION并修改:
将每一个define service的 host_name修改为210
添加一个新的cfg文件
vi objects/localhost.cfg
修改为以下内容:
define host{
use linux-server
host_name 210
alias remote server
address 192.168.1.210
}
保存退出
vi objects/services.cfg
define servicegroup{
servicegroup_name 210
members 210,PING,210,Root Partition,210,Current Users,210,Total Processes,210,Current Load,210,Swap Usage,210,SSH,210,HTTP
}
保存退出
vi hostgroups.cfg
define hostgroup{
hostgroup_name web_server
alias web_server
members 210
}
保存退出
然后vi nagios.cfg
将刚刚添加的hosts文件写入其中
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
最后验证配置文件是否正确
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
启动nagios服务,并将其添加到系统启动项:
service nagios start
chkconfing --level 345 nagios on
通过浏览器访问即可:
192.168.1.213/nagios
监控主机:192.168.1.213(以下简称213)
被监控主机:192.168.1.210(以下简称210)
监控原理:
此处monitoring host为213
remote linux/unix host为210
【监控机213】
以下均在root中操作
先yum install gcc gd gd-devel glibc glibc-devel
然后确保apache已经安装
若无,则yum install httpd
#附带两个操作
启动apache服务:service httpd start
将apache服务作为开机启动项:chkconfig --level 345 httpd on
建立nagios用户及用户组:
user add -m nagios
passwd nagios
groupadd nagcmd
usermod -G nagcmd nagios
首先下载nagios-3.5.1.tar.gz
将下载好的tar包放入/usr/local/目录中
tar -zxvf nagios-3.5.1.tar.gz
cd nagios-3.5.1
./configure --with-command-group=nagcmd
初始化后进行编译安装
make install
make install-init
make install-config
make install-commandmode
make install-webconf
安装完后,应该可以在/usr/local/nagios下看到:
bin etc include libexec sbin share var
这些文件夹若有,则表示nagios安装成功(nagios-core)
相关的apache配置文件为/etc/http/conf.d/nagios.conf
htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
其中admin为后续需要登录到监控平台的用户名,接下来输入密码则为该用户的密码
可以在 /usr/local/nagios/etc/htpasswd.user来查看。
继续下载nagios-plugins插件
此处我用的是nagios-plugins-2.0.3
在/usr/local中:
tar -zxvf 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
nagios验证nagios.cfg配置文件:(nagios.cfg为nagios的主配置文件)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果无警告错误,可启动nagios服务。
service nagios start
接下来需要安装NRPE插件
NRPE可以向nagios监控平台提供该服务器的一些本地的情况。
此处我用的NRPE版本是2.15
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
在监控主机213上安NRPE插件实际上是为了简易快速地安装check_nrpe
【被监控机210】
接下来需要在被监控主机上安装:
useradd nagios
passwd nagios
此处需要安装nagios-plugins和NRPE。
步骤如上:
tar -zxvf 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
然后
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
修改用户所属
chown nagios.nagios /usr/local/nagios
接下来需要确认是否安装xinetd,若有,则不需要,若无,可以yum install xinetd。
然后继续在nrpe文件夹中
make install-xinetd
打开vi /etc/xinetd.d/nrpe
然后修改 only_from 将值改为 192.168.1.213
即允许213的主机对本机进行监控。
vi /etc/service
加入nrpe 5666/tcp # nrpe
重启xinetd服务:
/etc/init.d/xinetd restart
查看nrpe:
netstat -nl | grep 5666
【监控机213】
继续切回监控机
通过check_nrpe插件来验证210上的nrpe是否可用:
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.210
若出现版本号,如v2.15则表示监测主机能够通过SSL与被监测主机上的NRPE正常通信。
如果报错,可以检查以下问题
1. nrpe的版本号和nrpe-plugin的版本号是否一致。版本不一致极有可能造成该问题。
2. SSL是否被关闭。确保NRPE以及check_nrpe插件在编译的时候都加入了SSL支持,同时在运行时都开启SSL。不过一般编译过程中默认都会假如支持SSL选项。
3. 确保NRPE的配置文件nrpe.cfg文件可以被nagios用户读取并且nagios用户可以执行nrpe二进制程序。
4. 确认在/etc/xinetd.d/nrpe文件的“only_from=x.x.x.x”中x.x.x.x是访问NRPE的监测主机的IP地址。
cd /usr/local/nagios/etc
进入nagios的配置文件夹
vi objects/localhost.cfg
删除或注释HOST DEFINITION和“HOST GROUP DEFINITION的内容。
保留SERVICE DEFINITION并修改:
将每一个define service的 host_name修改为210
添加一个新的cfg文件
vi objects/localhost.cfg
修改为以下内容:
define host{
use linux-server
host_name 210
alias remote server
address 192.168.1.210
}
保存退出
vi objects/services.cfg
define servicegroup{
servicegroup_name 210
members 210,PING,210,Root Partition,210,Current Users,210,Total Processes,210,Current Load,210,Swap Usage,210,SSH,210,HTTP
}
保存退出
vi hostgroups.cfg
define hostgroup{
hostgroup_name web_server
alias web_server
members 210
}
保存退出
然后vi nagios.cfg
将刚刚添加的hosts文件写入其中
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
最后验证配置文件是否正确
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
启动nagios服务,并将其添加到系统启动项:
service nagios start
chkconfing --level 345 nagios on
通过浏览器访问即可:
192.168.1.213/nagios
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29773961/viewspace-1760447/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29773961/viewspace-1760447/