本次安装未加入客户端,就是配置本机成为监控对象
一、nagios简介
Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
Nagios 可以监控的功能有:
1 2 3 4 5 6 7 8 9 10 11 |
1、监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);
|
二、安装Nagios基础支持套件和添加用户
1).创建nagios用户和用户组(先进行该步骤,不然编译nagios时会报错)
1 2 |
# useradd -s /sbin/nologin nagios
|
2).安装httpd和php
1 2 |
# yum install httpd* ##安装Web服务器Apache相关服务,nagios提供了web监控界面,通过web 界面可以看到被监控主机运行状态
|
三、安装Nagios
yum -y install nagios nagios-plugins nagios-snmp-plugins chkconfig --add nagios chkconfig nagios on
1)添加管理账号nagcmd,并将apache,nagios都加入nagcmd用户组;将apache加入nagios用户组,并且更改nagios目录属主属组。
useradd -s /sbin/nologin nagcmd usermod -G nagcmd nagios usermod -G nagcmd apache usermod -G nagios apache chown -R nagios.nagcmd /usr/share/nagios/html/*
2)这里我们的php是直接安装的php;这里php与httpd是通过模块的方式连接
yum -y install httpd php*
1)这里还是需要对/etc/httpd/conf.d/nagios.conf进行一下编辑,根据系统版本进行更改,我这里是CentOS7-2,列出配置
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER # # This file contains examples of entries that need # to be incorporated into your Apache web server # configuration file. Customize the paths, etc. as # needed to fit your system. ScriptAlias /nagios/cgi-bin/ "/usr/lib64/nagios/cgi-bin/" <Directory "/usr/lib64/nagios/cgi-bin/"> # SSLRequireSSL Options ExecCGI AllowOverride None AuthName "Nagios Access" AuthType Basic AuthUserFile /etc/nagios/passwd require valid-user <IfModule mod_authz_core.c> # Apache 2.4 <RequireAll> # Require all granted # Require local Require valid-user </RequireAll> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 # Order allow,deny # Allow from all # Order deny,allow # Deny from all # Allow from 127.0.0.1 Require valid-user </IfModule> </Directory> Alias /nagios "/usr/share/nagios/html" #proxyrequests off #proxypassmatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/share/nagios/html/$1 <Directory "/usr/share/nagios/html"> # SSLRequireSSL Options None AllowOverride None AuthName "Nagios Access" AuthType Basic AuthUserFile /etc/nagios/passwd require valid-user <IfModule mod_authz_core.c> # Apache 2.4 <RequireAll> # Require all granted # Require local Require valid-user </RequireAll> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 # Order allow,deny # Allow from all # Order deny,allow # Deny from all # Allow from 127.0.0.1 Require valid-user </IfModule> </Directory>
3).关闭SELinux和防火墙:
a、临时关闭(不用重启机器):
1 2 |
# setenforce 0 ##设置SELinux 成为permissive模式 (关闭SELinux)
|
b、修改配置文件需要重启机器:
1 |
# vi /etc/selinux/config
|
4).验证程序是否配置正确
1 |
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
|
5)这里创建登录用户
htpasswd -c -m /etc/nagios/passwd sjf (Enter输入密码)
6).启用服务并进入nagios
1 2 3 |
# systemctl start httpd.service
|
四、这里的安装就完成了
由于时间有限,这里就不演示图形界面pnp4nagios插件的演示了,这个有机会可以给大家展示nagios的使用。