【nagios 一】自动化安装nagios

由于nagios的源码安装过程比较繁琐,于是将整个编译安装过程写进脚本让系统自动运行,这样减少人为干预,提高效率。

思路来源于“dl528888”的博客,http://dl528888.blog.51cto.com/

实验环境:centos 6.3 x86_64, 关闭防火墙,SELinux设为Disabled

安装包: nagios-3.4.1.tar.gz

         nagios-plugins-1.4.16.tar.gz

         nrpe-2.13.tar.gz

将该脚本nagiosauto.sh 和nagios的安装包nagios-3.4.1.tar.gz和插件安装包nagios-plugins-1.4.16.tar.gz 以及nrpe-2.13.tar.gz放在目录/usr/local/src下,并执行nagiosauto.sh脚本即可进行安装。

脚本执行完后,打开浏览器,输入http://ip/nagios, 提示输入用户名和密码,分别为nagiosadmin 和你所设置的密码 即可进入nagios的控制界面。

关于nagios的详细配置还需继续深入研究。

 

  
  
  
  
  1. #!/bin/bash  
  2. #auto install nagios  
  3. #v2.0   -- add nrpe and correct path 
  4. #2012-12-10  
  5.  
  6. LANG=C  
  7. nagiosdir="/usr/local/nagios"  
  8.   
  9. function init_pack()        #安装需要的包和库文件 
  10. {  
  11.     yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel  openldap-clients openldap-servers libxslt-devel libevent-devel ntp  libtool-ltdl bison libtool vim-enhanced gd*  
  12. }  
  13.   
  14.   
  15. function install_httpd()  #安装httpd和php 服务 
  16. {  
  17.     yum -y install httpd* php*  
  18.     chkconfig httpd on  
  19.     service httpd restart 
  20. }  
  21.   
  22. function user_group()      #添加nagios用户和组 
  23. {  
  24.     if [ ! $(grep 'nagios' /etc/passwd) ]; then  
  25.         useradd nagios 
  26.     fi  
  27.     if [ ! $(grep 'nagcmd' /etc/group) ]; then  
  28.         groupadd nagcmd  
  29.     fi  
  30.     usermod -G nagcmd nagios  
  31.     usermod -G nagcmd apache  
  32. }  
  33.   
  34. function install_nagios()   #编译安装nagios 
  35. {  
  36.     cd /usr/local/src 
  37.     tar zxvf nagios-3.4.1.tar.gz 
  38.     tar zxvf nagios-plugins-1.4.16.tar.gz 
  39.     tar zxvf nrpe-2.13.tar.gz 
  40.   
  41.     cd /usr/local/src/nagios  
  42.     ./configure --with-command-group=nagcmd --prefix=$nagiosdir  
  43.     make all  
  44.     make install  
  45.     make install-init  
  46.     make install-config  
  47.     make install-commandmode  
  48.     make install-webconf 
  49.   
  50.     cd /usr/local/src/nagios-plugins-1.4.16  
  51.     ./configure --with-nagios-user=nagios --with-nagios-group=nagios --perfix=$nagiosdir  
  52.     make && make install  
  53.   
  54.     cd /usr/local/src/nrpe-2.13 
  55.     ./configure 
  56.     make all 
  57.     make install-plugin 
  58.     make install-daemon 
  59.     make install-daemon-config 
  60.   
  61.     htpasswd -bc $nagiosdir/etc/htpasswd.users nagiosadmin "bcd123"      #设置自己的密码 
  62.     chown -R nagios:nagios $nagiosdir  
  63.     chmod -R 755 $nagiosdir  
  64.     chcon -R --reference=/var/www/html/ $nagiosdir  
  65.     chkconfig --add nagios  
  66.     chkconfig nagios on  
  67.     $nagiosdir/bin/nagios -v $nagiosdir/etc/nagios.cfg  
  68.     service nagios start  
  69. }  
  70.   
  71. init_pack 
  72. install_httpd  
  73. user_group  
  74. install_nagios  

 

 

 

 

你可能感兴趣的:(linux,shell,nagios)