作者:于俊毅智文建志 | 来源:互联网 | 2017-07-19 13:48
服务器先安装好Apache。从http://www.nagios.org下载以下软件:nagios-3.2.3.tar.gznagios-plugins-1.4.15.tar.gznrpe-2.12.tar.gz安装NagiosCore#切换到root用户su-l#添加na
服务器先安装好Apache。
从 http://www.nagios.org 下载以下软件:
- nagios-3.2.3.tar.gz
- nagios-plugins-1.4.15.tar.gz
- nrpe-2.12.tar.gz
安装Nagios Core
- #切换到root用户
- su -l
-
- #添加nagios用户
- useradd -m nagios
- passwd nagios
-
- #创建nagcmd组,允许用户在web上执行命令.
- groupadd nagcmd
- usermod -a -G nagcmd nagios
- usermod -a -G nagcmd apache
-
- tar xzvf nagios-3.2.3.tar.gz
-
- cd nagios-3.2.3
-
- ./configure --with-command-group=nagcmd
-
- make all
-
- make install
- make install-init
- make install-config
- make install-commandmode
configure完成后会显示如下提示
- General Options:
- -------------------------
- Nagios executable: nagios
- Nagios user/group: nagios,nagios
- Command user/group: nagios,nagcmd
- Embedded Perl: no
- Event Broker: yes
- Install ${prefix}: /usr/local/nagios
- Lock file: ${prefix}/var/nagios.lock
- Check result directory: ${prefix}/var/spool/checkresults
- Init directory: /etc/rc.d/init.d
- Apache conf.d directory: /etc/httpd/conf.d
- Mail program: /bin/mail
- Host OS: linux-gnu
-
- Web Interface Options:
- ------------------------
- HTML URL: http://localhost/nagios/
- CGI URL: http://localhost/nagios/cgi-bin/
- Traceroute (used by WAP): /bin/traceroute
配置文件目录/usr/local/nagios/etc
修改/usr/local/nagios/etc/objects/contacts.cfg中的邮箱地址为 nagios@xxx.edu.cn。该邮箱设置了过滤规则,所有信件转发到 xxx@139.com
将/root/nagios-3.2.3/sample-config/httpd.conf中的片段拷贝到/usr/local/apache2/conf/httpd.conf中
添加nagiosadmin用户
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
安装Nagios Plugins
- tar xzvf nagios-plugins-1.4.15.tar.gz
- cd nagios-plugins-1.4.15
-
- ./configure --with-nagios-user=nagios --with-nagios-group=nagios
-
- make
-
- make install
命令安装在/usr/local/nagios/libexec/目录下
启动Nagios
- chkconfig --add nagios #将nagios添加到服务中
- chkconfig nagios on #开启该服务
- chkconfig --list nagios #查看服务启动状态
-
-
- #检查脚本正确性
- /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
- service nagios start
访问 http://ip/nagios/
安装NRPE
先安装Nagios Plugins,如果是在被监控主机上安装,需要先添加nagios用户。
- tar xzvf nrpe-2.12.tar.gz
- cd nrpe-2.12
-
- ./configure
- make all
-
- make install-plugin
安装NRPE Daemon
NRPE Daemon的端口5666
先按照上一步安装NRPE
- make install-daemon
- make install-daemon-config
-
- make install-xinetd
安装完毕后NRPE的配置文件在/usr/local/nagios/etc/nrpe.cfg
编辑/etc/xinetd.d/nrpe
only_from = 127.0.0.1 #这里只能加一个IP
编辑/etc/services,在最后一行加上
nrpe 5666/tcp # NRPE
重启xinetd服务
service xinetd restart
执行下面命令,检查服务有无正常启动
netstat -at | grep nrpe #应该出现以下提示 tcp 0 0 *:nrpe *:* LISTEN
测试NRPE Deamon服务
#测试本机 /usr/local/nagios/libexec/check_nrpe -H localhost #测试远程 /usr/local/nagios/libexec/check_nrpe -H 202.195.160.46 #正常会显示 NRPE v2.12
在监控主机上编辑/usr/local/nagios/etc/objects/commands.cfg,加入下面的command。
- define command{
- command_name check_nrpe
- command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
- }
重启监控主机的Nagios服务
service nagios restart