这次被监控主要有2种:

1.web服务器

2.mysql服务器

所以得先保证nginx/apache 或者mysql服务的启动;

下面是mysql监控端部署的函数installmysql () 脚本如下

 

 
  
  1. installmysql () { 
  2.  yum install xinetd -y 
  3.  service xinetd start 
  4.  cd $path 
  5.  useradd -s /sbin/nologin nagios 
  6.  tar -zxvf nagios-plugins-1.4.14.tar.gz 
  7.  cd nagios-plugins-1.4.14 
  8.  ./configure --prefix=$nagiospath --with-nagios-user=nagios --with-nagios-group=nagios 
  9.  make 
  10.  make install 
  11.  cd $path  
  12.  tar -zxvf nrpe-2.12.tar.gz 
  13.  cd nrpe-2.12 
  14.  ./configure 
  15.  make all 
  16.  make install 
  17.  make install-plugin 
  18.  make install-daemon 
  19.  make install-daemon-config 
  20.  make install-xinetd 
  21.  read -p " Please input the nagios server IP: " serverip 
  22.  echo "nrpe            5666/tcp                        #nrpe" >> /etc/services 
  23.  sed -i "s#only_from.*#only_from       = 127.0.0.1 $serverip#" /etc/xinetd.d/nrpe 
  24.  chkconfig --add xinetd 
  25.  chkconfig xinetd on 
  26.  cd $path 
  27.  tar -zxvf check_mysql_health-2.1.tar.gz 
  28.  cd check_mysql_health-2.1 
  29.  ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl  
  30.  make  
  31.  make install 
  32.  yum install perl-DBI perl-DBD-MySQL -y 
  33.  cd $path 
  34.  tar -zxvf check_iftraffic.tar.gz 
  35.  chmod +x check_iftraffic 
  36.  chmod +x check_mem.sh 
  37.  chmod +x check_cpu.sh 
  38.  chmod +x ip_conn.sh 
  39.  cp check_mem.sh /usr/local/nagios/libexec 
  40.  cp check_cpu.sh /usr/local/nagios/libexec 
  41.  cp check_iftraffic /usr/local/nagios/libexec 
  42.  cp ip_conn.sh /usr/local/nagios/libexec 
  43.  read -p "please input the mysql password: " mysqlpwd 
  44.  read -p "please input the nagios for mysql's password: " nagiospwd 
  45.  mysql -uroot -p$mysqlpwd -e "create database nagios;" 
  46.  mysql -uroot -p$mysqlpwd -e "grant select on nagios.* to nagios@'$serverip' identified by '$nagiospwd' ;" 
  47.  mysql -uroot -p$mysqlpwd -e "flush privileges; " 
  48.  cp $path/cfg/nrpe.cfg /usr/local/nagios/etc/  
  49.  chown -R nagios.nagios /usr/local/nagios 
  50.  service xinetd restart 
  51.  echo "##############################" 
  52.  echo "#########**the result**#######" 
  53.  lsof -i:5666 
  54.  echo "------------------------------" 
  55.  /usr/local/nagios/libexec/check_nrpe -H localhost 
  56.  } 
  57.   

下面是web端部署的脚本

 

 
  
  1. installweb () { 
  2.  yum install xinetd -y 
  3.  service xinetd start 
  4.  cd $path 
  5.  useradd -s /sbin/nologin nagios 
  6.  tar -zxvf nagios-plugins-1.4.14.tar.gz 
  7.  cd nagios-plugins-1.4.14 
  8.  ./configure --prefix=$nagiospath --with-nagios-user=nagios --with-nagios-group=nagios 
  9.  make 
  10.  make install 
  11.  cd $path  
  12.  tar -zxvf nrpe-2.12.tar.gz 
  13.  cd nrpe-2.12 
  14.  ./configure 
  15.  make all 
  16.  make install 
  17.  make install-plugin 
  18.  make install-daemon 
  19.  make install-daemon-config 
  20.  make install-xinetd 
  21.  read -p " Please input the nagios server IP: " serverip 
  22.  echo "nrpe            5666/tcp                        #nrpe" >> /etc/services 
  23.  sed -i "s#only_from.*#only_from       = 127.0.0.1 $serverip#" /etc/xinetd.d/nrpe 
  24.  chkconfig --add xinetd 
  25.  chkconfig xinetd on 
  26.  cd $path 
  27.  tar -zxvf check_iftraffic.tar.gz 
  28.  chmod +x check_iftraffic 
  29.  chmod +x check_mem.sh 
  30.  chmod +x check_cpu.sh 
  31.  chmod +x ip_conn.sh 
  32.  cp check_mem.sh /usr/local/nagios/libexec 
  33.  cp check_cpu.sh /usr/local/nagios/libexec 
  34.  cp check_iftraffic /usr/local/nagios/libexec 
  35.  cp ip_conn.sh /usr/local/nagios/libexec 
  36.  cp $path/cfg/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg 
  37.  chown -R nagios.nagios /usr/local/nagios 
  38.  service xinetd restart 
  39.  echo "###################################" 
  40.  echo "#########    the result    ########" 
  41.  echo "-----------------------------------" 
  42.  lsof -i:5666 
  43.  echo "-----------------------------------" 
  44.  /usr/local/nagios/libexec/check_nrpe -H localhost 
  45.  } 
  46.   

验证安装是否成功的方式,与第一篇相同

还是得手敲(悲剧)!!

 

这样就可以了