创建nagcmd组(可选,我在测试中并没有进行这步,因为觉得它有点多余,但照着官方指引也没错)
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
下载Nagios,在官方指南中,版本如下,而我在写这篇笔记时Nagios是4.1.1,Nagios Plugins是2.1.1,所以下面的wget命令如果照搬的话,未必能下载得到相应的文件。最好还是从官网上找相应的链接。
mkdir ~/downloads
cd ~/downloads
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
wget http://www.nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
开始安装
先解压
cd ~/downloads
tar xzf nagios-4.0.8.tar.gz
cd nagios-4.0.8
./configure --with-command-group=nagcmd #这一步我把nagcmd改为了nagios,这里的是否修改由自己决定,但非常重要,一旦修改,那么以后Nagios运行的组就是现在设置的组名。
make all
make install
make install-init
make install-config
make install-commandmode
#如果依赖的组件都装齐了,一般是不会有Error的
vi /usr/local/nagios/etc/objects/contacts.cfg #修改联系方式,后期再修改也可以
make install-webconf
#重启apache服务
service httpd restart
tar xzf 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
chkconfig --add nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#所有配置文件都OK的情况下,会提示OK,否则会提示Error或者Warning
下载nagios plugin,注意以下为官方指南的链接,未必能下载到文件,理由同上。
mkdir ~/downloads
cd ~/downloads
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.6.tar.gz
tar xzf nagios-plugins-1.4.6.tar.gz
cd nagios-plugins-1.4.6
./configure
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec
yum install xinetd #在老男孩老师的视频里,是独立daemon的方式,而在官方指南里,则是使用xinetd,我同样地用了xinetd,因此xinetd的配置文件有如下修改
下载NRPE
cd ~/downloads
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
tar xzf nrpe-2.8.tar.gz
cd nrpe-2.8
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
配置Client的防火墙
[root@syslog-srv ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT