百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>服务器> CentOS 6.5 安装nagios监控软件例子
分享文章到:

CentOS 6.5 安装nagios监控软件例子

发布时间:01/15 来源: 浏览: 关键词:
安装nagios软件教程一聚教程小编整理了不少了相关文章了,下面我们再来看看这款免费网络监视工具安装例子吧。
我这里安装的均为当前最新的稳定版本:
nagios-4.0.8
nagios-plugins-2.0.3
 
安装如下:
安装前准备工作
使用root用户操作服务器,需要以下软件环境:
Apache
PHP
DCC编译器
GD开发库
可通过yum进行安装:
yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel
 
  1. 创建用户和用户组
useradd -m nagios
passwd nagios
 
 
Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.
/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd apache
 
2. 下载Nagios和Nagios插件
创建文件夹/software 将下载的文件放到/software目录下
官网下载:http://www.nagios.org/download

 

 

3. 编译安装nagios
# cd /software
# tar -zxvf nagios-4.0.8.tar.gz
# cd nagios-4.0.8
Run the Nagios configure script, passing the name of the group you created earlier like so:
./configure --with-command-group=nagcmd
Compile the Nagios source code.
make all
Install binaries, init script, sample config files and set permissions on the external command directory.
make install

make install-init

make install-config

make install-commandmode
Don't start Nagios yet - there's still more that needs to be done...
 
4.  Customize Configuration
Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You'll need to make just one change before you proceed...
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you'd like to use for receiving alerts.
vi /usr/local/nagios/etc/objects/contacts.cfg
 
5. Configure the Web Interface
 
Install the Nagios web config file in the Apache conf.d directory.
make install-webconf
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin                //这里我将密码设为123456
Restart Apache to make the new settings take effect.
service httpd restart
 Note: Consider implementing the ehanced CGI security measures described here to ensure that your web authentication credentials are not compromised.

6. 安装nagios插件
cd /software
tar -zxvf 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
 
7. 启动nagios
将nagios加入开机启动
chkconfig --add nagios
chkconfig nagios on
 
验证nagios配置文件是否有错:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
 
如果没有错误,则启动nagios:
service nagios start
 
8. 关闭selinux
vim /etc/selinux/config
将SELINUX=enforcing  改为  SELINUX=disabled
修改后需重启系统生效。
临时生效:
# setenforce 0
 
9. 在浏览器中登录
用户名为nagiosadmin 密码为刚才配置的123456
http://localhost/nagios/
 
我这里吧默认80端口改成了800了,如下图:
1431931305101085.png
 
当前系统默认监控的本机的项目:
1431931516613472.png
 
10. nagios配置文件说明
nagios安装完成后主目录为/usr/local/nagios 所有的配置文件在/usr/local/nagios/etc目录下:
blob.png
cgi.cfg
htpasswd.users        //用于web端登录时的验证,上文中添加的
nagios.cfg          //nagios主配置文件,如果监控其他主机,需要在里面添加其他主机的配置文件
resource.cfg        //定义了nagios插件的位置
 
其中objects目录也是非常重要的目录,绝大部分操作都会在这里进行,他的默认文件有:
blob.png
commands.cfg    //命令定义文件,其中的命令可被其他配置文件引用
contacts.cfg    //定义联系人和联系人组的文件
localhost.cfg    //监控本机的文件
printer.cfg    //监控打印机的模板文件,默认没有启用
switch.cfg     //监控路由器的模板文件,默认没有启用
templates.cfg    //定义主机和服务的模板配置文件,可在其他配置文件中引用
timeperiods.cfg    //定义nagios监控时间段的配置文件
windows.cfg    //监控windows主机的配置文件,默认没有启用
 
监控本机:
在/usr/local/nagios/etc/nagios.cfg中加入本机的监控,默认已经添加:
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
 
本机配置文件默认监控了8项服务Current load,Current Users,HTTP,PING,Root Partition,SSH,Swap Usage,Total Processes
添加一个对本机/data分区的监控:
vim localhost.cfg
在后面添加
define service{
        use                             local-service
        host_name                       localhost
        service_description             Data Partition
        check_command                   check_local_disk!20%!10%!/data
        notifications_enabled           1
        }
 
保存重启nagios服务,登录web即可看到。
 
 
Nagios发送邮件的设置:
下载sendmail http://caspian.dotconf.net/menu/Software/SendEmail/

 

cd /usr/local/
tar -zxvf sendEmail-v1.56.tar.gz
复制执行程序 cp sendEmail-v1.56/sendEmail /usr/local/bin/
发件测试:
# sendEmail -f nagios@domain.com -t 7344506@qq.com -s mail.domain.com -u "This is subject" -xu nagios -xp passpwd -m This is content.
解释:
-f 表示发送者的邮箱
-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容

修改commands.cfg
vim /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$
\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | sendEmail -f nagios@domain.com -t $CONTACTEMAIL$ -s mail.domain.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAM
E$ is $HOSTSTATE$ **" $CONTACTEMAIL$ -xu nagios -xp password
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTA
DDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | sendEmail -f nagios@domain.com -t $CONTACTEMAIL$ -s mail.domain.com -u "** $NOTIFIC
ATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -xu nagios -xp password
        }

保存并重启nagios服务。

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有6人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板