luobo2ni 发表于 2019-1-14 13:58:34

nagios安装配置及飞信报警

  一、监控服务器端安装配置

  1、下载软件包
      nagios-3.0.6.tar.gz,nagios-plugins-1.4.13.tar.gz,nrpe-2.8.1.tar.gz
  2、安装环境和添加用户组

      yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-server
      groupadd nagcmd

      yseradd -m nagios

      usermod -a -G nagcmd nagios

      usermod -a -G nagcmd apache

  3、编译安装nagios
      tar -zxvf nagios-3.0.6.tar.gz;cd nagios-3.0.6
      ./configure –with-command-group=nagcmd –enable-event-broker
      make all;make install ;make install-init;make install-config;make install-commandmode

  说明:第一步执行make install安装主要的程序、CGI及HTML文件,第二步执行make install-init的步骤,它的作用是把nagios做成一个运行脚本,使nagios随系统开机启动,这是一个很方便的措施。第三步执行 make install-config 把配置文件的例子复制到nagios的安装目录。第四步执行 make install-commandmode 给外部命令访问nagios配置文件的权限。
安装完后 查看一下在/usr/local/nagios下是否存在etc、bin、 sbin、 share、 var这五个目录,如果存在则可以表明程序被正确的安装到系统了。这5个目录的作用是:
bin
Nagios执行程序所在目录,这个目录只有一个文件nagios
etc
Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件
sbin
Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
Share
Nagios网页文件所在的目录
Var
Nagios日志文件、spid 等文件所在的目录
  4、http.conf配置
      在http.conf下面增加这一段

  ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
  
  Options ExecCGI
  AllowOverride None
  Order allow,deny
  Allow from all
  AuthName "Nagios Access"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd
  Require valid-user
  
  Alias /nagios /usr/local/nagios/share
  
  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
  AuthName "Nagios Access"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd
  Require valid-user
  
  重启http
  htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
  4、编译安装nagios-plugins
      tar -zxvf nagios-plugins-1.4.13.tar.gz;cd nagios-plugins-1.4.13
      ./configure –with-nagios-user=nagios –with-nagios-group=nagios
      make &&make install

  5、配置、启动nagios
      chkconfig --add nagios
      chkconfig nagios on

      setenfoce 0

      检查配置文件: /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
      service nagios start

  6、安装NRPE
      tar -zxvf nrpe-2.8.1.tar.gz ;cdnrpe-2.8.1
      ./configure

      make all

      make install-plugin

      make install-daemon
      make install-daemon-config
      启动NRPE: /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
      修改nagios配置文件 commands.cfg

      添加
  define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
  检查配置文件/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

  重启nagios service nagios restart
  二、被监控机配置
  1、下载软件包nagios-plugins-1.4.13.tar.gz,nrpe-2.8.1.tar.gz
  2、安装
      tar -zxvf nagios-plugins-1.4.13.tar.gz;cd nagios-plugins-1.4.13
      ./configure –with-nagios-user=nagios –with-nagios-group=nagios
      make &&make install
      tar -zxvf nrpe-2.8.1.tar.gz;cd nrpe-2.8.1
      ./configure

      make all

      make install-plugin

      make install -daemon

      make install-daemon-config

  3.配置nrpe信息
  
      vim /usr/local/nagios/etc/nrpe.cfg
      allowed_hosts=127.0.0.1,1.1.1.1(监控机IP)//允许监控的IP
      /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
      如果有防火墙,需要将开通5666端口,关闭selinux
  4、检查联通性
     在监控端执行 /usr/local/nagios/libexec/check_nrpe -H 被监控IP,如果测试成功会得到NRPE版本,如果不成功就检查防火墙,检查配置文件设置是否允许监控机IP
  

  三、飞信报警设置
  1、下载和安装飞信软件
  主软件:wget http://www.it-adv.net/fetion/downng/fetion20091117-linux.tar.gz
  主程序:wget http://bbs.it-adv.net/attachment.php?aid=43&k=b1e8997336d66ec8610adc2b790376a2&t=1299230237
  库文件:wget http://www.it-adv.net/fetion/linuxso_20101113.rar
  安装飞信:
  tar zxvf fetion20091117-linux.tar.gz -C /usr/local
  将下载的主程序fetion覆盖掉/usr/local/fx/下的fetion
  在windows中解压linuxso_20101113.rar并将里面的库文件上传至 /usr/local/fx/
  cd /usr/local/fx
  cp lib* /usr/lib
  2.飞信测试
  /usr/local/fx/fetion --mobile=15958045149 --pwd=12346 --to=15958045149 --msg-utf8=test
  这样后在fx目录有个手机号的图片,下载下来查看再输入后就好了,以后就不用输入了
  3.nagios配置
  修改nagios配置文件 commands.cfg
  添加如下
  define command {
               command_name            notify-host-by-fei
               command_line            /usr/local/fx/fetion --mobile=15958045149 --pwd=qazwsxedc --to=$CONTACTPAGER$ --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! on '$LONGDATETIME$'" $CONTACTPAGER$   
               }
  

  # 'notify-service-by-fei' command definition   
  

  define command {
               command_name         notify-service-by-fei
               command_line         /usr/local/fx/fetion --mobile=15958045149 --pwd=qazwsxedc --to=$CONTACTPAGER$ --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$" $CONTACTPAGER$   
               }
   修改contacts.cfg
  在define contact{}里添加下面这段
   service_notification_commands   notify-service-by-fei ; send service notifications via email
        host_notification_commands      notify-host-by-fei
  pager 15958045149
  检查配置文件,重启nagios
  




页: [1]
查看完整版本: nagios安装配置及飞信报警