Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等等。
在云平台端,我们也可以通过Nagios来监控虚拟机状态。
下面来说说我在项目中如何安装的Nagios。
1.确定Centos系统中是否安装了web server、GCC、GD等,没安装就安装吧:
#Apache
yum -y install httpd
#GCC compiler
yum -y install gcc
yum -y install glibc glibc-common
#GD development libraries
yum -y install gd gd-devel
2.创建一个nagios user并为其设置password
useradd nagios
passwd nagios
3.创建用户组并将nagios user和apache user加入到用户组中
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
4.下载最新的nagios软件包及nagios插件
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.4.2.tar.gz
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz
5.编译安装nagios
tar xzf nagios-3.4.2.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
6.配置web接口
make install-webconf
#添加nagiosadmin管理用户
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#重启apache服务器,让刚才的配置生效。
service httpd restart
7.安装nagios插件
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios group=nagios
make
make install
8.把nagios服务增加到服务清单中并设置开机自启动
chkconfig --add nagios
chkconfig nagios on
9.检查nagios服务器是否存在配置错误。
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
===================================================
Total Warnings: 0
Total Errors: 0
===================================================
#若没有错误信息就启动nagios服务器
service nagios start !
10.在ie中输入
http://serverip/nagios/,能正常打开web页面,表示Nagios安装成功
Nagios中默认管理用户是nagiosadmin,在Nagios的配置文件中我们可以看到默认配置文件都是以nagiosadmin作为用户的。正常登录后,本地服务器的性能情况都能看到。其他服务器需要进行手工配置,也可以按照NagiosQL进行web方式配置。至于NagiosQL如何安装,那真的很简单的,后面再做介绍。