kaiser_cn 发表于 2019-1-16 07:20:19

Lamp环境下使用nagios监控windows服务器

  Lamp环境下使用nagios监控windows服务器
  [ 日期:2012-03-22 ]            作者:luke
  一、软件简介
Nagios是一个监控系统运行状态和网络信息的监控软件。它能监控所指定的本地或远程主机的系统状态以及运行的服务,同时提供异常通知的功能。另外,Nagios可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志,性能图表等等。
  Nagios的主要功能特点:
- 监视网络服务 (mysql,http,nginx,squid,ping等)
- 监视主机资源 (进程,磁盘,CPU,内存等)
- 简单的插件扩展功能
- 异常通知功能 (通过email,短信网关,飞信等)
- WEB界面使系统管理人员能够随时查看网络服务状态,系统问题等等
  二、实验目的
在lamp环境下使用nagios监控windows服务器,监控主机资源。
  三、安装步骤
  (1).按照linux操作系统,我选择的是rhel5.5,这个大家都会,略过。
  (2).在linux5.5平台下源码编译apache、mysql、php,在这个过程中mysql不做过多要求,php编译后要做测试,测试通过后在编译安装nagios。
  (3).源码编译nagios并测试监控本机服务器资源。
  (4).在windows 操作系统下安装NSClient++32/64,具体多少位根据实际情况而定。
  四、详细过程
  编译安装Lamp环境前,先配置好yum,yum install gcc glibc gd gd-devel glibc-common
  1. 下载软件
  # cd /usr/local/src
  httpd-2.2.6.tar.gz
  mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
  php-5.2.10.tar.gz
  nagios-3.0.5.tar.gz
  nagios-plugins-1.4.13.tar.gz
  2. 安装MySQL
  # tar xzvf mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
  # mv mysql-5.0.86-linux-i686-icc-glibc23 /usr/local/
  # ln - s /usr/local/ mysql-5.0.86-linux-i686-icc-glibc23 /usr/local/mysql
  # useraddmysql –s /sbin/nologin –M –u 504
  # chown -R mysql:root /usr/local/mysql/
  # cd /usr/local/mysql
  # ./scripts/mysql_install_db --user=mysql
  # cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
  # chown root:root /etc/rc.d/init.d/mysqld
  # chmod 755 /etc/rc.d/init.d/mysqld
  # chkconfig --add mysqld
  # chkconfig --level 3 mysqld on
  3. 编译安装Apache
  # cd /usr/local/src
  # tar xzvf httpd-2.2.6.tar.gz
  # cd httpd-2.2.6
  #./configure--prefix=/usr/local/apache --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared
  # make
  # make install
  # echo '/usr/local/apache/bin/apachectl start ' >> /etc/rc.local
  4. 编译安装PHP
  在编译安装PHP之前,我们首先关闭selinux,以免编译时出现错误,后面将会讲到不关闭selinux报错信息。
  # vi /etc/selinux/config
  找到:SELINUX=enforcing
  改为:SELINUX=disabled并重启
  开始安装编译PHP:
  # cd /usr/local/src
  # tar xzvf php-5.2.10.tar.gz
  # cd php-5.2.10
  #./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp --with-libxml-dir=/usr/local/libxml2 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-curl --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-sockets --enable-exif --enable-zend-multibyte --disable-ipv6 --disable-cgi
  # make
  # make install
  # cp php.ini-dist /usr/local/php/etc/php.ini
  在/usr/loca/apache/conf/httpd.conf里添加 index.php
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400069HM3N.jpg
  在/usr/local/apache/htdocs下touch test.php,并写入一下测试代码。
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_13324000698pAn.jpg
  在火狐浏览器里输入http://127.0.0.1/test.php
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400072zUDB.jpg
  4.编译安装nagios
  安装nagios主程序
  # useradd nagios
  # tar –zxvf nagios-3.0.5.tar.gz
  # cd nagios-3.0.5
  #./configure --prefix=/usr/local/nagios
  #make all #编译
  #make install #安装nagios主要程序,cgi和html文件等
  #make install-init # 把nagios做成一个运行脚本,使nagios随系统开机启动
  #make install-config # 把配置文件样例复制到nagios的安装目录
  #make install-commandmode # 给外部命令访问nagios配置文件的权限
  # chown -R nagios:nagios /uar/local/nagios
  安装完成后在/usr/local/nagios里面生成几个目录,分别是 var日志文件,bin执行程序,etc配置文件,sbin, share libexec网页的目录。至此安装成功。
  安装nagios插件
  nagios本身并没有监控的功能,所有的监控是由插件完成的,插件将监控的结果返回给nagios,nagios分析这些结果,以web的方式展现给我们,同时提供相应的报警功能
  #tar –zxvf nagios-plugins-1.4.13tar.gz
  # cd nagios-plugins-1.4.13
  #./configure –prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios 编译到nagios的安装目录
  # make && make install
  安装完成后,会在/usr/local/nagios/ 目录下面生成libexe插件,nagios所有的插件都会在这个目录里面。
  查看是否安装成功的方法是:
  ls /usr/local/nagios/libexec/
  在/usr/local/apache/conf/httpd.conf配置文件里添加下面两段话
  ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin” //cgi文件的目录
  
  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” //nagios的文件目录
  
  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://lukelee.blog.运维网.com/attachment/201203/22/2830351_13324000722iMP.jpg
  Apache配置文件改完后需要使用命令htpasswd给nagiosadmin用户设置密码
  #/usr/local/httpd/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
  # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 查询配置有没有错误
  当出现
  Total Warnings: 0
  Total Errors: 0
  启动nagios服务:/etc/init.d/nagios start
  配置成功,可以登陆http://ip/nagios 查看我们的劳动成果。
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400073cEgw.jpg
  在/usr/local/nagios/etc/nagios.cfg下更改如下:
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400073adRA.jpg
  编辑vi /usr/local/nagios/etc/objects/windows.cfg
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_13324000734084.jpg
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400077Eapv.jpg
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400077ycwg.jpg
  如果监控多台windows主机的话,在windows.cfg里添加就是了。
  5. 在windows服务器上安装NSClient++
  我分别在32bit windows server2003 和 64bit windows server 2008 R2上安装了
  NSClient++-0.3.9-Win32和NSClient++-0.3.8-x64(这两个文件运维网上都有下载)
  下面介绍安装的步骤,非常的简单。
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_13324000782Z96.jpg
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400078Hrbt.png
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400078og7j.png
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400079BrZX.png
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400079maiY.png
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400080Lf9t.png
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_13324000807MvY.png
  打开安装目录:
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400081m84a.jpg
  把port前面的;号去了。
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_13324000815wDN.jpg
  windows+r 打开运行窗口输入:services.msc
  找到NSClient++服务后,点击右键重新启动
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400082lEni.jpg
  最后在nagios主机上,重启nagios,打开浏览器查看刚才配置好的windows服务器
http://lukelee.blog.运维网.com/attachment/201203/22/2830351_1332400083lrgU.jpg
  有兴趣的朋友可以继续研究nagios的各种功能。
  下面是部署nagios监控windows时可能遇到的问题,贴出来,仅供大家参考。
  1.编译PHP时报错:
  # make install
  Installing PHP SAPI module: apache2handler
  /usr/local/apache//build/instdso.sh SH_LIBTOOL='/usr/local/apache//build/libtool' libphp5.la /usr/local/apache//modules
  /usr/local/apache//build/libtool --mode=install cp libphp5.la /usr/local/apache//modules/
  cp .libs/libphp5.so /usr/local/apache//modules/libphp5.so
  cp .libs/libphp5.lai /usr/local/apache//modules/libphp5.la
  libtool: install: warning: remember to run `libtool --finish /usr/local/src/php-5.2.10/libs'
  chmod 755 /usr/local/apache//modules/libphp5.so
  
  Installing PHP CLI binary: /usr/local/php/bin/
  Installing PHP CLI man page: /usr/local/php/man/man1/
  Installing build environment: /usr/local/php/lib/php/build/
  Installing header files: /usr/local/php/include/php/
  Installing helper programs: /usr/local/php/bin/
  program: phpize
  program: php-config
  Installing man pages: /usr/local/php/man/man1/
  page: phpize.1
  page: php-config.1
  Installing PEAR environment: /usr/local/php/lib/php/
  /usr/local/src/php-5.2.10/sapi/cli/php: error while loading shared libraries: /usr/local/mysql/lib/libmysqlclient.so.15: cannot restore segment prot after reloc: Permission denied
  make: *** Error 127
  make: *** Error 2
  解决办法:关掉防火墙后,并重启。
  Vi /etc/selinux/config
  SELINUX=enforcing改为SELINUX=disbled
  2.搭建lamp环境中,编译php后,用phpinfo来测试php是否能解析,发现无法解析。
  解决办法:
  增加默认主页的php支持:
  #
  # DirectoryIndex: Name of the file or files to use as a pre-written HTML
  # directory index. Separate multiple entries with spaces.
  #
  ;
  DirectoryIndex index.php index.html
  ;
  增加php后缀支持:
  #
  # AddType allows you to tweak mime.types without actually editing it, or to
  # make certain files to be certain types.
  #
  AddType application/x-tar .tgz
  AddType image/x-icon .ico
  AddType application/x-httpd-php .php .phtml .php3 .inc
  AddType application/x-httpd-php-source .phps
  3.账户无法使用
  # /etc/init.d/nagios restart
  Running configuration check...done.
  Stopping nagios: done.
  Starting nagios:This account is currently not available.
  done.
  解决办法:
  修改/etc/passwd
  将/sbin/nologin改成/bin/bash
  4.打开nagios时报错:
  You don't have permission to access /nagios/cgi-bin/status.cgi on this server.
  Forbidden
  You don't have permission to access /nagios/cgi-bin/tac.cgi on this server.
  解决办法:vi /usr/local/apache/conf/httpd.conf 里的配置可能写的不对,需要仔细核对。或者未安装GD库
  5.检查你的配置文件是不是都配置对了?
  # service nagios restart
  Running configuration check... CONFIG ERROR! Restart aborted. Check your Nagios configuration.
  配置文件有误,可以使用/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg查看语法是否有问题。



页: [1]
查看完整版本: Lamp环境下使用nagios监控windows服务器