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

Centos6.5

[复制链接]

尚未签到

发表于 2019-1-13 13:40:42 | 显示全部楼层 |阅读模式
  写这个文档的目的,就是为了方便 快捷的部署nagios,涉及到个人喜好的配置,大家自行修改,可以套用。
  一、下载并安装所需软件
  1,yum install gcc mysql httpd php gd openssl openssl-devel mysql-server vim wget
  Wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.7.tar.gz
  Wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
  Wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
  

  

  Ls 可以看到nagios-4.0.7.tar.gz nagios-plugins-2.0.3.tar.gz nrpe-2.14.tar.gz
  

  yum install wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp
  useradd nagios
  passwd nagios
  groupadd nagcmd
  usermod –a –G nagcmd nagios
  (nagcmd:x:504:nagios)
  

  tar –xvzf nagios-4.0.7.tar.gz
  cd nagios-4.0.7
  ./configure –with-command-group=nagcmd
  

  可以先./configure –help先看看帮助,应为默认为主是用nagios用户,不需要指定—with-nagios-user或其它什么的。
  

  

  

  make all
  make install
  make install-init
  这个安装/etc/rc.d/init.d中的init脚本
  make install-commandmode
  这个安装和配置权限
  目录的外部命令文件
  make install-config
  这个安装* * /usr/local/nagios/etc配置文件示例
  你必须修改这些示例文件之前
  使用Nagios。阅读HTML文档
  

  make install-webconf
  这个安装Nagios的Apache配置文件
  Web界面
  

  

  Cp –R contrib/eventhandlers/ /usr/local/nagios/libexec/
  (-R:递归复制目录,即连同目录下的子目录和文件一起复制。)
  

  Chown –R nagios:nagios /usr/local/nagios/libexec/eventhandlers
  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (检测配置文件是否有错误)
  

  { [root@Nagios libexec]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers/
  [root@Nagios libexec]# ll
  total 4
  drwxr-xr-x. 4 nagios nagios 4096 Oct 21 01:16 eventhandlers}
  

  /etc/init.d/nagios start 或者service nagios start
  Chkconfig --add nagios
  Chkconfig nagios on
  Chkconfig httpd on
  Service httpd start
  

  二、创建web用户
  

  切换到ngios用户
  

  htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  输入密码nagios
  

  

  三、安装nagios-plugins
  

  Tar –xvzf nagios-plugins-2.0.3.tar.gz
  Cd nagios-plugins-2.0.3
  

  ./configure {–with-nagios-user=nagios –with-nagios-group=nagios}
  Make
  Make install
  前面这步做了可以略过,反正要做一次。
  Chkconfig nagios on 或者chkconfig –level 35 nagios on
  Chkconfig httpd on 或者 chkconfig –level 35 httpd on
  

  四、关闭防火墙和selinux
  

  service iptables stop
  

  Vim /etc/sysconfig/selinux 把selinux改成disabled这个需重启生效。
  

  

  http://192.168.1.202/nagios/ 这个是nagios地址,要输入用户名和密码的nagiosadmin nagios
  

  ******无法开题notifications报错****************************************
  

  Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!
  这个主要是apache 用户 没有执行权限 /usr/local/nagios/var/rw/nagios.cmd 造成,
  解决方法:
  usermod -a -G nagcmd apache
  将apache用户添加到nagios用户组,就OK了。
  

  

  date -s 调整日期时间   clock -w 保存
  

  

  五、安装NRPE插件。
  

  Tar –xvzf nrpe-2.14.tar.gz
  Cd nrpe-2.14
  ./configure
  make && make install
  make install-plugin
  把check_nrpe放到/usr/local/nagios/libex下。才能使用check_nrpe。
  

  ***********************************************************************************
  *********************************2***************************************************
  

  在被监控机器上安装。
  

  Nagios-plugins安装.
  

  Useradd nagios
  Passwd nagios
  Tar –xvzf nagios-plugins-2.0.3.tar.gz
  Cd nagios-plugins
  ./configure
  Make
  Make install
  Chown –R nagios:nagios /usr/local/nagios
  

  

  安装nrpe-2.14
  Tar –xvzf nrpe-2.14.tar.gz
  Cd nrpe-2.14
  ./configure
  make all
  make install-plugin
  make install-daemon
  make install-daemon-config
  

  

  yum install xinetd
  chkconfig --add xinetd
  chkconfig xinetd on
  

  make install-xinetd
  

  

  vim /etc/xinetd.d/nrpe
  在该文件的only_from  = 127.0.0.1 192.168.1.107  //在后面增加监控主机的地址,以空格间隔
  

  vim /usr/local/nagios/etc/nrpe.cfg 这里也是充许访问里添加 192.168.107
  

  vim /etc/services
  启动nrpe就好了。
  

  /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
  

  service xinetd restart
  netstat -at |grep nrpe
  Netstat –an | grep 5666
  

  

  Vim /etc/sysconfig/iptables
  

  -A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT (该语句有待,不过我另一台也是这样配的)
  好像不添加上面这个不得行,会报check_nrpe:Error - Could not complete SSL handshake
  

  

  运行ipables –F 清空一下规则,然后保存。
  然后iptables –L –n 查看确认后。
  

  Service iptables save
  Service iptables restart
  

  2、配置文件方面:
  (1)/usr/local/nagios/etc/nrpe.cfg 此配置文件是配置正确,多个IP地址逗号隔开,且要注意空格:allowed_host=127.0.0.1,  192.168.0.1 这是不对的,必须是allowed_host=127.0.0.1,192.168.1.202   逗号之后不能有空格;
  (2)检查是否配置里限制了,在 /etc/xinetd.d/nrpe 文件中要添加允许访问的服务器的IP地址,在 “only_from = ” 这一行添加, 多个IP地址用空格隔开,例如:only_from       = 192.168.0.8 192.168.1.202
  

  被控端:
  vi /etc/xinetd.d/nrpe
  only_from 增加主控IP
  vi /usr/local/nagios/etc/nrpe.cfg
  allowed_hosts 增加主控IP
  service xinetd restart
  主控端:
  /usr/local/nagios/libexec/check_nrpe -H 被监控端IP地址       测试是否连接成功
  

  

  

  

  修改nrpe.cfg后一定要重启nrpe,大侠我是这样做的:
  pkill nrpe;
  /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg  -d
  

  

  二、添加监控节点及service
  

  

  

  三】增加验证用户
  也就是通过web访问nagios的时候,必须要用这个用户登陆.在这里我们增加用户test:密码为12345
  64.   [root@localhost nagios-plugins-1.4.13]# htpasswd -c /usr/local/nagios/etc/htpasswd test
  可以用 which命令查看 htpasswd命令的位置,如果是源码安装的apache这里就写htpasswd的全路径。用户是test,命令结束会提示你输入密码,这里输入123456即可。
  65.   查看认证文件的内容
  66.   [root@localhost nagios-plugins-1.4.13]# less /usr/local/nagios/etc/htpasswd
  67.   到这里nagios的安装也就基本完成了,你可以通过web来访问了.
  

  三、检测定义快捷命令
  

  问题1:新建立文件夹及节点无法生效
  

  解决:修改nagios目录文件,使其目录被检测
  vi /usr/local/nagios/etc/nagios.cfg
  添加 要检测的目录。
  cfg_dir=/usr/local/nagios/etc/cfgs
  

  

  问题2:《《apache 启动失败 》》  默认安装在/usr/sbin/下,执行apachectl start时候,提示如下错误:
  

  httpd: apr_sockaddr_info_get() failed for shiwei
  httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
  

  

  

  于是上网查了一下,根据前人的经验,问题终于解决了。总结一下,方便以后使用。
  

  原因:这个问题应该是没有在 /etc/httpd/conf/httpd.conf 中设定 ServerName。所以apache会用主机上的名称来取代,首先会去找 /etc/hosts 中有没有主机的定义。
  

  解决办法:
  

  (1)可以设定httpd.conf文件中的 ServerName,如下:ServerName localhost:80
  

  (2)在 /etc/hosts 中填入自己的主机名称 bogon,如下:127.0.0.1 shiwei (用户名称)
  

  问题3 NRPE: Unable to read output
  我的解决办法是:修改nagios目录的权限
  #chown -R nagios:nagios nagios/
  #chmod -R 775 nagios/
  问题解决。linux
  

  

  四、添加command
  command[check_cpu]=/usr/local/nagios/libexec/check_cpu_pct -w $ARG1$ -c $ARG2$
  command[check_memory]=/usr/local/nagios/libexec/check_mem -w $ARG1$ -c $ARG2$
  将配置文件拷贝到指定目录后,修改所属及访问权限。
  

  command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
  command[check_swap]=/usr/local/nagios/libexec/check_swap -w $ARG1$ -c $ARG2$228
  command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$
  command[check_io]=/usr/local/nagios/libexec/check_iostat -d $ARG3$ -w $ARG1$ -c $ARG2$
  

  

  

  五、安装sendmail
  首先要确保sendmail相关组件的完整安装,我们可以使用如下的命令来完成sendmail的安装:
  # yum install -y sendmail*
  然后重新启动sendmail服务:
  # service sendmail restart
  然后发送测试邮件,验证sendmail的可用性:
  # echo "Hello World" | mail abc@abc.com
  

  

  Root@Nagios objects]# service sendmail restart
  Shutting down sendmail:                                    [FAILED]
  Starting sendmail:                                         [  OK  ]
  Starting sm-client:                                        [  OK  ]
  

  chkconfig sendmail off
  

  

  

  chkconfig sendmail off  加速开机时间
  重启服务器注意1,开机nrpe 二启动sendmail 三 iptables 设置
  

  

  

  

  Nagios 多用户的一些配置
  刚开始我想到在搭nagios的时候,用户验证是用apache来做的,接到这个需求后的第一反应是这个东西可能做不了。但接着一想,不应该啊,nagios本身至少会有一些用户配置的吧,于是乎开始寻找相关资料,基本配置如下:
  (1)新增一个apache用户,如qiuyuetao
  [root@service3F-38 ~]# htpasswd /usr/local/nagios/etc/htpasswd.users  qiuyuetao
  (2)更改cgi.cfg配置
  [root@service3F-38 ~]# vi /usr/local/nagios/etc/cgi.cfg
  use_authentication=1
  如果只允许查看,不允许管理,加上下面配置
  authorized_for_read_only=qiuyuetao
  authorized_for_all_services=qiuyuetao
  authorized_for_all_hosts=qiuyuetao
  

  (3)将userA设为联系人
  [root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/contacts.cfg  #添加如下配置
  define contact{
  contact_name                   qiuyuetao
  use                                      generic-contact
  alias                                     qyt
  }
  (4)在属于userA的主机、服务配置文件的联系人中加入qiuyuetao
  [root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/hosts.cfg
  define host {
  host_name web02-1.22@sh
  alias web02-1.22@sh
  address 10.1.1.22
  contacs qyt
  contact_groups sys_admins
  check_command check-host-alive
  max_check_attempts 5
  notification_interval  3
  notification_period 24x7
  notification_options d,u,r
  }
  (5)重启nagios后生效
  [root@service3F-38 ~]#  /etc/init.d/nagios restart
  





运维网声明 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-662783-1-1.html 上篇帖子: Nagios监控HP硬件状态 下篇帖子: nagios_ndoutlis_nagiosql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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