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

nagios 布署配置笔记(一)

[复制链接]

尚未签到

发表于 2019-1-16 14:27:41 | 显示全部楼层 |阅读模式
  首发于http://www.linux-ch.com/post-11.html
  花了几天的时间,完成了近500台服务器,多个节点的nagios监控布署.通过nagios可清晰地看到整个监控网络的拓扑,主机状态,服务状态等情况.但在这里我不会贴出真实网络的任何信息,因为这会产生很多不良影响.但会给出我在实际生产过程中使用的量产工具(也就是为了不多打键盘而弄的shell).

系统环境: centos5.5 x86_64
web: apache+php (yum 安装)
nagios: nagios 3.2.1
nagios-plugins: 1.4.15
没有涉及远程主机监控,所以没弄nrpe模块.

因为nagios的页面是要利用cgi生成的,得先让apache支持cgi才行,只要在httpd.conf后面添加下面的内容,不过你自定了nagios的安装路径,那就得以实际为准了
先让apache支持cgi
将下面这行前的#号去掉
#AddHandler cgi-script .cgi

添加目录
scriptalias /nagios/cgi-bin /usr/local/nagios/sbin

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

Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user


下面就准备安装nagios了
先为nagios添加一个运行帐号,并将apache的运行帐号添加到nagios组里面,要不然无法使用页面管理主机

useradd -r -d /usr/local/nagios -s /sbin/nologin nagios
usermod -G nagios apache
解包编译安装
# tar -xvf nagios-3.2.1.tar.gz
# cd nagios-3.2.1
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# chkconfig --add nagios
到此,nagios已经安装到/usr/local/nagios/,但没有plugin,它什么也干不了,接下来还得编译plugin

# tar -xvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./confingure
# make
# make install
plugins已经全部放到了/usr/local/nagios/libexec,安装过程已经结束了

默认是可以直接启动nagios,它将监控本机,但这并不是我要的结果,所以要修改下配置文件
首先修改nagios.cfg,在/usr/local/nagios/etc下面,只对修改的作一个说明
注析掉下面一行,因为它是对本的监控,没必要.改成
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

#主机组配置文件
cfg_file=/usr/local/nagios/etc/objects/hostgroup.cfg

如果要使用一个新的配置文件,在些文件中指定就行了.但它还提供了另一个功能:cfg_dir.指定这个参数后,程序会在目录下搜索所有以cfg结尾的文件.如何使用就看你的具体情况,我在实际中就是新那两个文件夹,一个是用来存放host信息,别一个是存放server信息,其它的是在nagios.cfg中指定.
主机配置文件夹
cfg_dir=/usr/local/nagios/etc/cfg

修改cgi.cfg,这个应该是帐号授权了
authorized_for_system_information=motu
authorized_for_configuration_information=motu
authorized_for_system_commands=motu
authorized_for_all_services=motu
authorized_for_all_hosts=motu
authorized_for_all_service_commands=motu
authorized_for_all_host_commands=motu

修改etc/objects/contacts.cfg
define contact{
        contact_name        motu
    use            generic-contact
        alias            Nagios Admin
        email            flyskyst@163.com
        }
define contactgroup{
        contactgroup_name       sagroup
        alias                   Nagios Administrators
        members                 motu
        }
生成授权文件
htpasswd -c /usr/local/nagios/etc/htpasswd motu


下面就要批量生成监控主机的信息了.为此需要一些shell,还有一些配置文件的模板.还有一个非常重要的就是ip列表,而且是要做好分类的,具体是看你的实际情况,这个是前期一个准备工作,很重要也很乏味.我这里的是分两类:服务器的位置和节点.分好类后就可以利用shell批量生成配置文档了,这又需要模板,如下:

host.temp
-----------------------------
define host{
        host_name               
        alias                  
        address                 
        check_command           check-host-alive
        max_check_attempts      5
        check_period            24x7
        contact_groups          sagroup
        notification_interval   10
        notification_period     24x7
        notification_options    d,u,r
}

services.temp
define service{
        host_name               
        service_description     check_tcp 80
        check_command           check_tcp!80
        max_check_attempts      5
        check_interval          5
        retry_interval          3
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
}

#!/bin/bash
echo "input hostgroup name:"
read hostgroup
for address in $(cat ip.txt)
do
sed -e /host_name/{s/$/$address/} -e /alias/{s/$/$address/} -e /address/{s/$/$address/} host.temp > /usr/local/nagios/etc/hosts/$address.cfg
sed -e /host_name/{s/$/$address/} services.temp > /usr/local/nagios/etc/servers/$address.cfg
done
members=$(sed ':a N;$!b a;s/\n/\,/g' ip.txt)
echo "define hostgroup{" >> /usr/local/nagios/etc/objects/host.cfg
echo "  hostgroup_name          $hostgroup" >> /usr/local/nagios/etc/objects/hostgroup.cfg
echo "  alias                   $hostgroup" >> /usr/local/nagios/etc/objects/hostgroup.cfg
echo "  members                 $members" >> /usr/local/nagios/etc/objects/hostgroup.cfg
echo "    }"  >> /usr/local/nagios/etc/objects/hostgroup.cfg
exit 0
把上面三个文件放在同一目录下,然后将ip列表存入同一目录下的ip.txt文件里就可以了
  接下来将要定义整个网络拓扑中的父子关系,报警设置等,将在下次更新




运维网声明 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-664090-1-1.html 上篇帖子: 整合nagios cacti 监控系统 下篇帖子: nagios监控linux主机和主机上的web服务
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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