linux下安装nagios监控服务器-第2步.nagios配置监控本地localhost

本文分三篇文章来讲
1.nagios的安装
2.nagios配置监控本地localhost
3.nagios配置监控远程
4.nagios配置邮件服务设置预警和其他补充问题

新增两项FTP和mysql服务监控
监控服务器: 192.168.1.8

nagios安装完成之后:nagios配置文件介绍

/usr/local/nagios/etc/nagios.cfg    #主配置文件
/usr/local/nagios/etc/objects/     #子配置文件的目录
/usr/local/nagios/etc/objects/localhost.cfg  #一个示例模版,默认定义了监控本机的8个服务
/usr/local/nagios/etc/objects/templates.cfg  #模版定义文件
/usr/local/nagios/etc/objects/commands.cfg  #命令定义文件
/usr/local/nagios/etc/objects/contacts.cfg  #定义通知方式的文件
/usr/local/nagios/etc/objects/timeperiods.cfg #监控时间段定义文件

==================================================


关于nagios配置文件之间的联系讲解示例

# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

# vim /usr/local/nagios/etc/objects/localhost.cfg
define host{
         use                     linux-server #模版
        host_name               localhost    #主机名
         alias                   localhost    #主机别名
         address                 127.0.0.1    #被监控机器的IP
         }
 define hostgroup{
         hostgroup_name  linux-servers
         alias           Linux Servers
         members         localhost    #linux Servers组现在只有localhost这一个成员
        }


下面是8个默认定义的服务,我以监控磁盘利用率的这一段为例

define service{
         use                             local-service     #模版,在templates.cfg 里定义的
         host_name                       localhost   #主机名,调用的是同配置文件里define host里定义的host_name
         service_description             Root Partition  #描述,会在web界面显示的一个标题
        check_command                   check_local_disk!20%!10%!/ #检测利用率的命令,free空间小于20%就报警,小于10就critcal警告
        }

# vim /usr/local/nagios/etc/objects/templates.cfg
#可以根据需要修改一下参数
 define host{
     name                            linux-server
  use                             generic-host #linux主机模版也使用了一个叫generic-host的模版,也在templates.cfg里
 check_period                    24x7    #在timeperiods.cfg 里定义的时间段
 check_interval                  5
  retry_interval                  1
  max_check_attempts              10
  check_command                   check-host-alive   #在commands.cfg 里定义的命令
 notification_period             workhours   #通知时间在timeperiods.cfg里定义的
 notification_interval           120     #通知间隔
 notification_options            d,u,r     #通知选项
 contact_groups                  admins    #通知组,在contacts.cfg 里定义
 register                        0       #不注册,表示这只是一个模版,被调用,不会被nagios进程认为就是一台主机
 }

命令配置:

# vim /usr/local/nagios/etc/objects/commands.cfg
 define command{
         command_name    check-host-alive
         command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
         }

命令都在libexec下,用–help去查

# /usr/local/nagios/libexec/check_ping --help
 # /usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5
 PING OK - Packet loss = 0%, RTA = 0.09 ms|rta=0.088000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0


==================================================


现在查看web界面,默认只监控了localhost,并监控了其8个服务

一些小操作:
1,如果http服务为黄色,是警告,则需要把网站家目录里加一个主页进去(家目录为空,他就会警告)。
但需要等它下一次check才会OK。如果要手动check,可以点http,再右边点Re-schedule the next check of this service去强制check,就OK了

2,默认httpssh是关闭通知的,是因为在localhost.cfg里这两个服务有一句 notifications_enabled       0
也可以手动打开,点进去,再右边点enabled notifications for this service.


3,关闭ssh服务,刷新web界面,还是没有critical.
   点击ssh,可以看到下一次计划的check时间。如果不等的话,在右边点Re-schedule the next check of this service强制check,再刷新就critical

4,修改ssh的check时间间隔

 # vim /usr/local/nagios/etc/objects/localhost.cfg
 define service{
         use                             local-service #使用的这个模版,所以要去改这个模版里的时间
        host_name                       localhost
         service_description             SSH
         check_command                   check_ssh
         notifications_enabled           0
         }
# vim /usr/local/nagios/etc/objects/templates.cfg
  define service{
         name                            local-service
   .............
   normal_check_interval           1  #把这个五分钟改为1分钟
  .............
  }
# /etc/init.d/nagios reload

再去web界面验证,check时间为1分钟了


======================================================== 


1:在默认8个服务的基础上,如何增加监控本机的服务  ftp

思路步骤:
1,看libexec/下是否有检测ftp的命令,如果没有,网上下载,或自己开发
2,在localhost.cfg里定义这个服务
3,在command.cfg里定义命令

安装FTP服务

yum -y install vsftpd
 # /etc/init.d/vsftpd restart
# vim /usr/local/nagios/etc/objects/localhost.cfg  #加上下面一段
define service{
         use                             local-service
         host_name                       localhost
         service_description             FTP
         check_command                   check_ftp!1!3
         }
 # vim /usr/local/nagios/etc/objects/commands.cfg  #下面一段默认就有,不需要加,直接改一下
define command{
         command_name    check_ftp
         command_line    $USER1$/check_ftp -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
         }
# /etc/init.d/nagios restart


练习:
1,如果本机ftp服务为监听2121端口,应该如何监控

# vim /etc/vsftpd/vsftpd.conf
 listen_port=2121  #加上这一句
# /etc/init.d/vsftpd restart
# netstat -ntlup |grep ftp
 # vim /usr/local/nagios/etc/objects/localhost.cfg

加下面一段

define service{
         use                             local-service
         host_name                       localhost
         service_description             FTP #标题改成FTP
         check_command                   check_ftp_2121!1!3!2121
 #命令我这里是没有的,在command.cfg里默认有一个check_ftp,没有
#check_ftp_2121这个,所以要手动去加;!为参数分隔符,1是第一个参数,3是第二个参数,2121是第三个参数;它们对应于我下面定义的-w -c  -p
         }
# vim /usr/local/nagios/etc/objects/commands.cfg
define command{
         command_name    check_ftp_2121
         command_line    $USER1$/check_ftp -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
         }


直接使用监控命令去手工check一下,OK的

# /usr/local/nagios/libexec/check_ftp -w 1 -c 3 -p 2121
 FTP OK - 0.004 second response time on port 2121 [220-#############################
 220-#]|time=0.00389s;1.000000;3.000000;0.000000;10.000000

# /etc/init.d/nagios reload

 reload后,再去web界面可以看到能监控本机的ftp这个服务了


2,监控本机的mysql
安装本机mysql

yum install mysql*
 mysqladmin -u root password "123"
# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
         use                             local-service
         host_name                       localhost
         service_description             MYSQL
         check_command                   check_mysql!root!123
         }
 # vim /usr/local/nagios/etc/objects/commands.cfg
 define command{
         command_name    check_mysql
         command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$ #第一个参数对应上面的root,第二个对应密码123
         }

没有这个文件:/usr/local/nagios/libexec/check_mysql
解决办法:http://www.linuxidc.com/Linux/2011-09/44190.htm

再次安装nagios插件

cd /usr/src/nagios-plugins-2.0.3/
 ./configure --with-nagios-user=nagios --with-nagios-group=nagiosgroup
 make && make install
ll /usr/local/nagios/libexec/check_mysql*

   

手动check一下mysql,OK

# /usr/local/nagios/libexec/check_mysql -u root -p123
Uptime: 189  Threads: 1  Questions: 5  Slow queries: 0  Opens: 12  Flush tables: 1  Open tables: 6  Queries per second avg: 0.026
# /usr/local/nagios/libexec/check_mysql -u root -p123
 Uptime: 415096  Threads: 1  Questions: 9  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.0|Connections=7c;;; Open_files=16;;; Open_tables=8;;; Qcache_free_memory=0;;; Qcache_hits=0c;;; Qcache_inserts=0c;;; Qcache_lowmem_prunes=0c;;; Qcache_not_cached=0c;;; Qcache_queries_in_cache=0;;; Queries=9c;;; Questions=9c;;; Table_locks_waited=0c;;; Threads_connected=1;;; Threads_running=1;;; Uptime=415096c;;;
 # /etc/init.d/nagios reload

2.nagios配置监控本地localhost

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇