这个只是总体脚本中的监控端的一个函数 installserver () 

具体脚本如下:

 

 
  
  1. #!/bin/bash 
  2.  #this is nagios server or client install shell 
  3.  #at 2012/10/29 
  4.  path=`pwd` 
  5.  httppath=/usr/local/apache2 
  6.  mysqlpath=/usr/local/mysql 
  7.  nagiospath=/usr/local/nagios 
  8.  installserver () { 
  9.  yum install -y xinetd 
  10.  useradd -m nagios 
  11.  groupadd nagcmd 
  12.  useradd -a -G nagcmd nagios 
  13.  useradd -a -G nagcmd apache 
  14.  cd $path 
  15.  tar -zxvf nagios-3.2.0.tar.gz 
  16.  cd nagios-3.2.0 
  17.  ./configure --with-command-group=nagcmd --with-nagios-user=nagios --with-nagios-group=nagios 
  18.  make all 
  19.  make install 
  20.  make install-init 
  21.  make install-config 
  22.  make install-commandmode 
  23.  make install-webconf 
  24.  echo "########################################" 
  25.  echo "please create the nagios user for apache" 
  26.  echo "----------------------------------------" 
  27.  cat $path/http.txt >> /etc/httpd/httpd.conf 
  28.  $httppath/bin/htpasswd -c $nagiospath/etc/htpasswd.users nagiosadmin  
  29.  chkconfig --add nagios 
  30.  chkconfig nagios on 
  31.  cd $path 
  32.  tar -zxvf nagios-plugins-1.4.14.tar.gz 
  33.  cd nagios-plugins-1.4.14 
  34.  ./configure --prefix=$nagiospath --with-nagios-user=nagios --with-nagios-group=nagios 
  35.  make 
  36.  make install 
  37.  cd $path  
  38.  tar -zxvf nrpe-2.12.tar.gz 
  39.  cd nrpe-2.12 
  40.  ./configure 
  41.  make all 
  42.  make install 
  43.  make install-plugin 
  44.  make install-daemon 
  45.  make install-daemon-config 
  46.  make install-xinetd 
  47.  read -p " Please input the nagios server IP: " serverip 
  48.  echo "nrpe            5666/tcp                        #nrpe" >> /etc/services 
  49.  sed -i "s#only_from.*#only_from       = 127.0.0.1 $serverip#" /etc/xinetd.d/nrpe 
  50.  chkconfig --add xinetd 
  51.  chkconfig xinetd on 
  52.  service xinetd restart 
  53.  cd $path 
  54.  tar -zxvf check_mysql_health-2.1.tar.gz 
  55.  cd check_mysql_health-2.1 
  56.  ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl  
  57.  make  
  58.  make install 
  59.  yum install perl-DBI perl-DBD-MySQL -y 
  60.  cd $path 
  61.  tar -zxvf check_iftraffic.tar.gz 
  62.  chmod +x check_iftraffic 
  63.  chmod +x check_mem.sh 
  64.  chmod +x check_cpu.sh 
  65.  chmod +x ip_conn.sh 
  66.  cp check_mem.sh /usr/local/nagios/libexec 
  67.  cp check_cpu.sh /usr/local/nagios/libexec 
  68.  cp check_iftraffic /usr/local/nagios/libexec 
  69.  cp ip_conn.sh /usr/local/nagios/libexec 
  70.  mv $path/cfg/server/etc/* /usr/local/nagios/etc 
  71.  mv $path/cfg/server/objects/* /usr/local/nagios/etc/objects 
  72.  chown -R nagios.nagios /usr/local/nagios 
  73.  service httpd restart 
  74.  service xinetd restart 
  75.  echo "###################################" 
  76.  echo "#########    the result    ########" 
  77.  echo "-----------------------------------" 
  78.  /usr/sbin/lsof -i:5666 
  79.  echo "-----------------------------------" 
  80.  /usr/local/nagios/libexec/check_nrpe -H localhost 
  81.  } 
  82.   

悲剧的是

/usr/sbin/lsof -i:5666

 echo "-----------------------------------"

 /usr/local/nagios/libexec/check_nrpe -H localhost

 还得手动敲命令,

正常得到的结果如下:

 

这样就代表安装成功了

补充一下:nagios+lamp的统一安装包将在后面放出