最近需要对公司内的所有服务器进行监控,当然现在有很多软件可以进行这个功能的实现,比如说微软的SCOM,还有就是今天的Nagios软件了,但是前者还好说Windows 平台下的产品,还是比较好配置和安装的,但是如果我们要安装Nagios的话,就可能会有一小些不好搞,因为这个东东是装在Linux平台上的,昨天晚上没怎么睡,搞了搞怎么去装,今天呢把相关的安装方法呢发上来,分享一下,供博友们参考参考。
首先我们来看看,什么是Nagios?,Nagios是一款用来监视系统和网络的开源监控软件,它一般被运行于一个主服务器上,这个服务器运行 Liunx 或 Unix 操作系统。Nagios 可以通过强大的插件功能来实现对本机和远端服务的监控,当被监控对象出现异常,Nagios 就会及时给管理人员告警。这个功能不错哦,呵呵,再者说它其实也可以看成是一个基于TCP/IP协议的软件包,包含有nagios主程序和它的各个插件,配置非常灵活,可以监视的项目很多,也可以通过自定义一些shell 脚本进行监控服务,非常适合各类企业的网络和系统平台服务监控的应用。
听起来Nagios功能非常强大,它可以监控服务和主机,但是其实他自身并不包括这部分功能的代码,所有的监控、检测功能都是有插件来完成的。比如说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是nagios很重要的功能之一。但是,同样的,nagios自身也没有报警部分的代码,甚至没有插件这部分,我们也只能是找一些相关插件来搞定了,这里我们介绍的只是nagios安装,是指基本平台,也就是nagios软件包的安装。它是监控体系的框架,也是所有监控的基础,后期我也会根据配置的进度不定期地把后边的东东也发上来补充给大家,一同学习,一同进步。
接下来,我们就一起来看看如何在Linux平台上安Nagios这个东东吧,在这里,我个人认为Centos还是比较不错的平台,如果大家要去安装的话Centos这个是不错的选择哦,而且大家还可以通过在Linux命令行下运行yum Update来实现系统的升级,我个人感觉相关方便好用。好了,接下来我们言归正传吧,谈谈怎么安装:
1) 安装apache,并设置开机启动
? 安装Apache程序
<b>[root@localhost nagios-3.2.3]# </b>yum install httpd
<b>Total download size</b><b>:1.6M</b>
<b>IS this OK[Y/N]</b><b>:</b>Y
<b>Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 Is this ok [y/N]</b><b>:</b>Y
安装成功后将显示如下图所示内容:
<a href="http://tingdongwang.blog.51cto.com/attachment/201110/27/1056852_1319714894SIbS.png"></a>
<b>[root@localhost nagios-3.2.3]# </b>chkconfig --levels 35 httpd on
<b>[root@localhost nagios-3.2.3]# </b>service httpd start
<b>启动 httpd:[确定]</b>
2) 安装配置PHP
安装PHP程序
<b>[root@localhost nagios-3.2.3]# </b>yum install php
<b>Total download size: 4.9 M</b>
<b>Is this ok [y/N]:</b> y
安装完成后显示下图所示内容
<a href="http://tingdongwang.blog.51cto.com/attachment/201110/27/1056852_1319714894uPGQ.png"></a>
3)安装mysql,并设置mysql开机自启动,同时启动mysql
安装Mysql
<b>[root@localhost ~]# </b>yum install mysql
<b>Total download size: 10 M</b>
<b>Is this ok [y/N]: </b>Y
安装成功后,将显示下图所示内容
<a href="http://tingdongwang.blog.51cto.com/attachment/201110/27/1056852_13197148948PiR.png"></a>
<b>[root@localhost ~]# </b>yum install mysql-server
<b>Is this ok [y/N]</b><b>:</b>Y
<b>[root@localhost ~]# </b>chkconfig --levels 35 mysqld on
<b>[root@localhost ~]# </b>service mysqld start
配置MySql的root密码
<b>[root@localhost ~]# </b>mysql_secure_installation
<b>Enter current password for root (enter for none): </b>( 回车)
<b>OK, successfully used password, moving on...</b>
<b>Setting the root password ensures that nobody can log into the MySQL</b>
<b>root user without the proper authorisation.</b>
<b>Set root password? [Y/n] </b><b>:</b>Y
<b>New password: </b>(这里输入密码,注意输入内容是不会显示出来的哦)
<b>Re-enter new password: </b>(这里再次输入密码,注意输入内容是不会显示出来的哦)
<b>Password updated successfully!</b>
<b>Reloading privilege tables..</b>
<b>... Success!</b>
<b>By default, a MySQL installation has an anonymous user, allowing anyone</b>
<b>to log into MySQL without having to have a user account created for</b>
<b>them. This is intended only for testing, and to make the installation</b>
<b>go a bit smoother. You should remove them before moving into a</b>
<b>production environment.</b>
<b>Remove anonymous users? [Y/n]</b><b>:</b>Y
<b>Normally, root should only be allowed to connect from 'localhost'. This</b>
<b>ensures that someone cannot guess at the root password from the network.</b>
<b>Disallow root login remotely(</b><b>是否禁止root的远程登录)? [Y/n]:</b>Y
<b>By default, MySQL comes with a database named 'test' that anyone can</b>
<b>access. This is also intended only for testing, and should be removed</b>
<b>before moving into a production environment.</b>
<b>Remove test database and access to it? [Y/n]</b><b>: </b>Y
<b>Reload privilege tables now? [Y/n] </b><b>:</b>Y
<b>Cleaning up...</b>
<b>All done! If you've completed all of the above steps, your MySQL</b>
<b>installation should now be secure.</b>
<b>Thanks for using MySQL!</b>
4)Nagions安装
下载Nagions-3.2.3安装包
? 解压Nagions-3.2.3安装包
<b>[root@localhost ~]#</b> tar -zxvf nagios-3.2.3.tar.gz
? 安装GCC
注意:不装这个,后边的make all就没办法执行了,会报错的哦~
<b>[root@localhost ~]#</b> cd nagios-3.2.3
<b>[root@localhost ~]# </b>yum instll gcc
<b>[root@localhost ~]#</b> ./configure --prefix=/usr/local/nagios
<b>[root@localhost nagios-3.2.3]#</b> ./configure
为nagions增加用户,此步必需做,否则无法mak all编译
<b>[root@localhost nagios-3.2.3]#</b> useradd nagios
<b>[root@localhost nagios-3.2.3]# </b>mkdir /usr/local/nagios
<b>[root@localhost nagios-3.2.3]# c</b>hown nagios.nagios /usr/local/nagios
<b>[root@localhost nagios-3.2.3]# </b>make all
<b>[root@localhost nagios-3.2.3]#</b> make install; make install-init;make install-commandmode;make install-config;make install-webconf
验证程序是否被正确安装
<b>[root@localhost nagios-3.2.3]# </b>cd ~
<b>[root@localhost ~]#</b> cd /usr/local/nagios
<b>[root@localhost nagios]#</b> ls
<b>bin etc libexec sbin share var</b>
如果有上述6个文件,说明就是安装成功了
修改nagios页面文件
<b>[root@localhost nagios]# </b>more /etc/httpd/conf.d/nagios.conf
<b>[root@localhost nagios]#</b> cp /etc/httpd/conf.d/nagios.conf /var/www/html/
生成nagios页面访问账号
<b>[root@localhost nagios]# </b>touch /usr/local/nagios/etc/htpasswd.users
<b>[root@localhost nagios]# </b>/usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users root
<b>Re-type new password:</b>(这里再次输入密码,注意输入内容是不会显示出来的哦)
<b>[root@localhost nagios]# </b>cat /usr/local/nagios/etc/htpasswd.users
<b>root:TTiPq0FKlL0iw</b>
<b>修改nagios主配置文件</b>
<b>[root@localhost nagios]# </b>vi /usr/local/nagios/etc/nagios.cfg
输完上边的命令后,将会出现一个编辑区域,你可以移动方向键到你想要添加的位置,按下字母I键进行编辑,编辑完成后,按ESC键,现按下右shift+;键,在出来的输入点处,输入WQ键,回车即可,如果你改错了,想不保存想重新进入编辑,也好办,只需要在输入点处,输入Q!回车,就退出来了,要是什么都没做要退出的话,只要在输入点处,输入Q键即可退出,好了,在下边的内容后换行增加对应的信息。
command_check_interval=15s
#command_check_interval=-1
<b>[root@localhost nagios]#</b> touch /usr/local/nagios/var/nagios.log
<b>[root@localhost nagios]#</b> chown nagios.nagios /usr/local/nagios/var/nagios.log
<b>测试nagios是否成功</b>
<b>[root@localhost nagios]# </b>chkconfig nagios on
<b>[root@localhost nagios]# </b>service nagios start
<b>[root@localhost nagios]#</b> service httpd restart
<b>测试nagios是否成功启动</b>
在IE输入 http:// 这里输入承担Nagios服务的Linux服务器IP地址/nagios/ ,在弹出的对话框中,输入“生成nagios页面访问账号”里新建的寻附上帐号及密码,如果输入密码正确的话就进入了Nagios的Web页面了。
<a href="http://tingdongwang.blog.51cto.com/attachment/201110/27/1056852_1319714895XRY6.png"></a>
总得来说,通过装Nagios学习了Linux下的命令,收获很大,嘻嘻~,分享一下。
本文转自wangtingdong 51CTO博客,原文链接:http://blog.51cto.com/tingdongwang/699279,如需转载请自行联系原作者