设为首页 收藏本站
查看: 1159|回复: 0

Nagios 配置笔记

[复制链接]

尚未签到

发表于 2019-1-16 09:14:20 | 显示全部楼层 |阅读模式
  需要安装:gcc、glibc、gd、gd-devel、openssl-devel、httpd-devel、per-GD、net-snmp-devel、php-pdo、php-gd、perl-Crypt-DES,为了方便避开烦人的包依赖问题,我直接 yum install httpd*、php*、net-snmp、mysql*、glibc*;
  AD:
  一、前提:系统、PHP、Apache、MySQL、Mail都工作正常,在这不做介绍;
  二、需要安装:gcc、glibc、gd、gd-devel、openssl-devel、httpd-devel、per-GD、net-snmp-devel、php-pdo、php-gd、perl-Crypt-DES,为了方便避开烦人的包依赖问题,我直接
  yum install httpd*、php*、net-snmp、mysql*、glibc*;
  需要下载的源码包:
  nagios: http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.2.tar.gz
  nagios-plugins: http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
  nrpe: http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
  nagios-snmp-plugins: http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz
  ###############################################  开始安装、配置  #####################################################
  1、修改/etc/snmpd/snmped.conf,完成后的文件;
  [root@Monitor nagios]# cat /etc/snmp/snmpd.conf | grep -v "#"
  sec.name  source          community            //去掉此处的#
  com2sec notConfigUser  127.0.0.1       public
  group   notConfigGroup v1           notConfigUser
  group   notConfigGroup v2c           notConfigUser
  view    systemview    included   .1.3.6.1.2.1.1
  view    systemview    included   .1.3.6.1.2.1.25.1.1
  group          context sec.model sec.level prefix read   write  notif           //去掉此处的#
  access  notConfigGroup ""      any       noauth    exact  systemview none none
  syslocation Unknown (edit /etc/snmp/snmpd.conf)
  syscontact Root  (configure /etc/snmp/snmp.local.conf)
  pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
  2、启动snmpd
  service snmpd start
  3、安装Nagios;
  groupadd nagios
  useradd -g nagios nagios
  passwd nagios
  mkdir /usr/local/nagios
  chown -R nagios:nagios /usr/local/nagios
  chmod 755 /usr/local/nagios/
  usermod -G nagios apache    //将apache、nagios用户加入到nagios组里;
  usermod -G nagios nagios
  tar zxf nagios-3.2.2.tar.gz
  cd nagios-3.2.2
  ./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --enable-event-broker
  根据如下提示:
  the main program and CGIs compiled without any errors, you
  can continue with installing Nagios as follows (type 'make'
  without any arguments for a list of all possible options):
  make install
  - This installs the main program, CGIs, and HTML files
  make install-init
  - This installs the init script in /etc/rc.d/init.d
  make install-commandmode
  - This installs and configures permissions on the
  directory for holding the external command file
  make install-config
  - This installs *SAMPLE* config files in /usr/local/nagios/etc
  You'll have to modify these sample files before you can
  use Nagios.  Read the HTML documentation for more info
  on doing this.  Pay particular attention to the docs on
  object configuration files, as they determine what/how
  things get monitored!
  make install-webconf
  - This installs the Apache config file for the Nagios
  web interface
  *** Support Notes *******************************************
  If you have questions about configuring or running Nagios,
  please make sure that you:
  - Look at the sample config files
  - Read the HTML documentation
  - Read the FAQs online at http://www.nagios.org/faqs
  before you post a question to one of the mailing lists.
  Also make sure to include pertinent information that could
  help others help you.  This might include:
  - What version of Nagios you are using
  - What version of the plugins you are using

  ->
  ->  For more information on obtaining support for Nagios, visit:
  http://www.nagios.org/support/
  依次执行如下操作:
  make all
  make all install
  make install-init
  make install-commandmode
  make install-config
  make install-webconfig
  4、安装nagios-plugins;
  tar zxf nagios-plugins-1.4.15.tar.gz
  cd nagios-plugins-1.4.15
  ./configure --prefix=/usr/local/nagios-plugins
  make
  make install
  安装完成以后在/usr/local/nagios-plugins会产生一个libexec的目录,
  将该目录全部移动到/usr/local/nagios目录下即可。
  如下:
  mv /usr/local/nagios-plugins/libexec /usr/local/nagios/
  5、安装nagios-snmp-plugins;
  tar xzf nagios-snmp-plugins.1.1.1.tgz
  cd nagios_plugins
  perl -MCPAN -e shell
  接着一直回车;
  直到提示符变为cpan>时输入:
  cpan>install Net::SNMP
  完成安装后退出:quit
  最后执行./install.sh;
  6、Apache里的配置文件自动加了nagios.conf,路径为/etc/httpd/conf.d 内容如下:
  ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
  #  SSLRequireSSL
  Options ExecCGI
  AllowOverride None
  Order allow,deny
  Allow from all
  #  Order deny,allow
  #  Deny from all
  #  Allow from 127.0.0.1
  AuthName "Nagios Access"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users
  Require valid-user
  Alias /nagios "/usr/local/nagios/share"
  #  SSLRequireSSL
  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
  #  Order deny,allow
  #  Deny from all
  #  Allow from 127.0.0.1
  AuthName "Nagios Access"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users
  Require valid-user
  重启apache
  service httpd restart
  7、为web访问加入认证的用户名和密码;
  htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  8、配置nagios;
  A、修改nagios中收取报警消息的联系人
  #vi /usr/local/nagios/etc/objects/contacts.cfg
  此处我只修改了email 加入了自己的邮箱地址;
  B、vi /usr/local/nagios/etc/cgi.cfg
  use_authentication=1 改成
  use_authentication=0,
  即不用验证.不然有一些页面不会显示。    //在网上看到这个,不知道这点是什么意思 ,我也做了此修改;
  C、检查配置文件是否正确:
  [root@host etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  Nagios Core 3.2.1
  Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
  Copyright (c) 1999-2009 Ethan Galstad
  Last Modified: 03-09-2010
  License: GPL
  Website: http://www.nagios.org
  Reading configuration data...
  Read main config file okay...
  Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
  Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
  Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
  Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
  Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'...
  Read object config files okay...
  Running pre-flight check on configuration data...
  Checking services...
  Checked 8 services.
  Checking hosts...
  Checked 1 hosts.
  Checking host groups...
  Checked 1 host groups.
  Checking service groups...
  Checked 0 service groups.
  Checking contacts...
  Checked 1 contacts.
  Checking contact groups...
  Checked 1 contact groups.
  Checking service escalations...
  Checked 0 service escalations.
  Checking service dependencies...
  Checked 0 service dependencies.
  Checking host escalations...
  Checked 0 host escalations.
  Checking host dependencies...
  Checked 0 host dependencies.
  Checking commands...
  Checked 24 commands.
  Checking time periods...
  Checked 5 time periods.
  Checking for circular paths between hosts...
  Checking for circular host and service dependencies...
  Checking global event handlers...
  Checking obsessive compulsive processor commands...
  Checking misc settings...
  Total Warnings: 0
  Total Errors:   0
  Things look okay - No serious problems were detected during the pre-flight check
  D、修改日志文件的属主,以后有问题可以查看此文件;
  chown -R nagios:nagios  /usr/local/nagios/var/nagios.log
  E、以上各步配置均没有错误,此时可以启动nagios了,
  service nagios start
  到此nagios配置完成,可以通过下面web访问访问了;
  http://ip/nagios/
  9、配置被监控端;(监控linux服务器)
  下载如下安装包:
  A、nagios-plugins:wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
  B、nrpe:wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
  安装如下;
  (1)在系统中添加nagios用户;
  useradd nagios
  passwd nagios
  (2)安装nagios-plugins;
  tar -zxvf nagios-plugins-1.4.15.tar.gz
  cd nagios-plugins-1.4.15
  ./configure
  make
  make install
  (3)改变nagios下的属主;
  chown nagios.nagios /usr/local/nagios -Rf
  (4)安装nrpe-2.12
  tar -zxvf nrpe-2.12.tar.gz
  cd nrpe-2.12
  ./configure
  make all
  make install-plugin
  make install-daemon
  make install-daemon-config
  (5)修改nrpe.cfg,允许主机为对应公司网关;
  vi  /usr/local/nagios/etc/nrpe.cfg 将allowed_hosts=127.0.0.1改成:X.X.X.X,127.0.0.1
  添加相应要监控的对象,如下所示:
  command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
  command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
  command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
  command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
  command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 500 -c 600
  command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
  (6)  启动nrpe
  /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
  可以查看nrpe是否启动;
  netstat -an|grep 5666
  察看是否能返回nrpv版本号;
  /usr/local/nagios/libexec/check_nrpe -H localhost
  10、配置command.cfg、nagios.cfg……
  vi /usr/local/nagios/etc/objects/commands.cfg
  添加如下内容;
  #check nrpe
  define command{
  command_name check_nrpe
  command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
  }
  添加被监控端的配置文件;
  vi /usr/local/nagios/etc/nagios.cfg
  在此处中间添加;
  cfg_file=/usr/local/nagios/etc/objects/Test.cfg
  编辑该文件;
  define host{
  use                                                         linux-server
  host_name                                             Test
  alias                                                        linux-server
  address                                                  192.168.0.110
  }
  define service{
  use                                                         generic-service
  host_name                                             Test
  service_description                                HTTP
  check_command                                    check_http
  }
  define service{
  use                                                         generic-service
  host_name                                             Test
  service_description                                 FTP
  check_command                                     check_ftp
  }
  define service{
  use                                                         generic-service
  host_name                                             Test
  service_description                                 SSH
  check_command                                     check_ssh
  }
  define service{
  use                                                        generic-service
  host_name                                            Test
  service_description                                SMTP
  check_command                                    check_smtp
  }
  define service{
  use                                                        generic-service
  host_name                                            Test
  service_description                               POP3
  check_command                                   check_pop
  }
  define service{
  use                                                       generic-service
  host_name                                           Test
  service_description                              check-swap
  check_command                                  check_nrpe!check_swap
  }
  define service{
  use                                                       generic-service
  host_name                                           Test
  service_description                               check-load
  check_command                                   check_nrpe!check_load
  }
  define service{
  use                                                      generic-service
  host_name                                           Test
  service_description                              check-disk
  check_command                                   check_nrpe!check_disk
  }
  define service{
  use                                                       generic-service
  host_name                                           Test
  service_description                               zombie_procs
  check_command                                   check_nrpe!check_zombie_procs
  }
  define service{
  use                                                      generic-service
  host_name                                           Test
  service_description                              check-users
  check_command                                  check_nrpe!check_users
  }
  define service{
  use                                                     generic-service
  host_name                                          Test
  service_description                             total_procs
  check_command                                 check_nrpe!check_total_procs
  }
  define service {
  use                                                  generic-service
  host_name                                      Test
  service_description                          check_mysql
  check_command                             check_mysql!192.168.0.110!3306!nagios!nagios!nagdb!60!600
  }
  这里面定义的是监控的对象,修改完成后保存退出,就可以了。
  11、检查配置文件,重启nagios服务;
  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  service nagios restart
  12、此时可以访问该页面,相关的被监控的对象也将出现。
  **************************************   M ySQL监控配置  *************************************
  1、在要监控的MYSQL数据库里新建库和相应的用户;
  CREATE DATABASE nagdb DEFAULT CHARSET=utf8;
  GRANT SELECT ON nagdb.* TO 'nagios'@'%';
  UPDATE mysql.user SET 'Password' = PASSWORD('********') WHERE 'User' = 'nagios'
  FLUSH PRIVILEGES;
  2、修改command.cfg,添加对mysql和主从同步的定义;
  vi /usr/local/nagios/etc/objects/command.cfg;
  define command{
  command_name check_mysql
  command_line    $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$
  }
  define command{
  command_name check_mysql_slave
  command_line    $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$ -S -w $ARG6$ -c $ARG7$
  }
  3、在被监控的主数据库和从数据库的cfg文件中分别添加;
  define service {
  use                                                          generic-service
  host_name                                              Master-Mysql
  service_description                                 check_mysql
  check_command                                     check_mysql!192.168.0.111!3306!nagios!******!nagdb
  }
  define service {
  use                                                          generic-service
  host_name                                              Slave-Mysql
  service_description                                 check_mysql_slave
  check_command                                         check_mysql_slave!192.168.0.112!3306!nagios!******!nagdb!60!600
  }
  4、检查配置文件,重启nagios服务;
  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  service nagios restart
  5、到此MySQL的监控配置完成。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-663831-1-1.html 上篇帖子: nagios监控mysql服务示例 下篇帖子: nagios设置邮件告警
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表