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

nagios监控系统的快速部署

[复制链接]

尚未签到

发表于 2019-1-16 08:46:21 | 显示全部楼层 |阅读模式
  最近有需求又搞了下nagios记录下备忘,采用快速安装lamp方式
  1、快速安装lamp
  yum groupinstall "Web Server"
yum groupinstall "MySQL Database"
yum install php-mysql
2、安装nagios
tar -xjvf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --with-nagios-user=nagios --with-nagios-group=nagios
make all && make install
make install-init && make install-commandmode
make install-config
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
3、修改/etc/httpd/conf/httpd.conf
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

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

Alias /nagios /usr/local/nagios/share

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

重启httpd: service httpd restart
4、插件及客户端安装
#!/bin/sh
set -x
#if [ -d /usr/local/nagios ]; then
#        rm -rf /usr/local/nagios*
#fi
if [ -d /usr/local/nrpe ]; then
        rm -rf /usr/local/nrpe*
fi
useradd   nagios
yum -y install xinetd
wget -c http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.14/nagios-plugins-1.4.14.tar.gz/download
tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios --enable-redhat-pthread-workaround
make && make install
chown -R nagios.nagios /usr/local/nagios
cd ../
wget -c http://cdnetworks-kr-1.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --prefix=/usr/local/nagios --enable-command-args
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
cd /etc/xinetd.d/
sed  -i 's/127.0.0.1/127.0.0.1 192.168.120.7/g' nrpe
echo "nrpe            5666/tcp                        # nrpe" >> /etc/services
service xinetd restart
6、添加配置文件在nagios.cfg中
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
注释#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
7、定义hosts.cfg文件
# Define a host for the local machine
define host{
        use                     standard-server
        host_name               localhost-220
        alias                         localhost
        address                   127.0.0.1
define host{
        use                     standard-server
        host_name          DB
        alias                   192.168.120.3
        address                 192.168.120.3
        }

8、定义模版文件templates.cfg
define service{
        name                       service-all
        use                        generic-service  
        contact_groups             admingroup
        register                          0  
        }
define service{
        name                                 generic-service               
        active_checks_enabled                    1                     
        passive_checks_enabled                   1                             
        parallelize_check                        1                           
        obsess_over_service                      1                             
        check_freshness                          0                     
        notifications_enabled                    1                       
        event_handler_enabled                    1                     
        flap_detection_enabled                   1                     
        failure_prediction_enabled               1                     
        process_perf_data                        1                     
        retain_status_information                1                    
        retain_nonstatus_information             1                       
        is_volatile                              0                     
        check_period                            24x7                 
        max_check_attempts                       3                       
        normal_check_interval                    3                     
        retry_check_interval                     1                     
        contact_groups                        admingroup                    
        notification_options                   w,c,r                  
        notification_interval                    0                     
        notification_period                     24x7                  
        register                                 0                  
        }

define host{
        name                            generic-host    ; The name of this host template
        notifications_enabled           1               ; Host notifications are enabled
        event_handler_enabled           1               ; Host event handler is enabled
        flap_detection_enabled          1               ; Flap detection is enabled
        failure_prediction_enabled      1               ; Failure prediction is enabled
        process_perf_data               1               ; Process performance data
        retain_status_information       1               ; Retain status information across program restarts
        retain_nonstatus_information    1               ; Retain non-status information across program restarts
        notification_period             24x7            ; Send host notifications at any time
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

define host{
        name                            standard-server
        use                             generic-host
        check_period                    24x7
        check_interval                  3               
        retry_interval                  1
        max_check_attempts              5               
        check_command                   check-host-alive
        notification_period             24x7                                                        
        notification_interval           0               
        notification_options            d,u,r           
        contact_groups                  admingroup      
        }
9、定义时间文件
# 24x7 monitor
define timeperiod{
        timeperiod_name 24x7
        alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
        monday          00:00-24:00
        tuesday         00:00-24:00
        wednesday       00:00-24:00
        thursday        00:00-24:00
        friday          00:00-24:00
        saturday        00:00-24:00
        }
# workhours monitor
define timeperiod{
        timeperiod_name workhours
        alias           Normal Work Hours
        monday          09:00-17:00
        tuesday         09:00-17:00
        wednesday       09:00-17:00
        thursday        09:00-17:00
        friday          09:00-17:00
        }
# custom monitor time
define timeperiod{
        timeperiod_name smsworkhours
        alias           no sleep time
        sunday          08:30-23:00
        monday          07:00-23:00
        tuesday         07:00-23:00
        wednesday       07:00-23:00
        thursday        07:00-23:00
        friday          07:00-23:00
        saturday        08:30-23:00
        }
10、定义服务配置文件
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-http
        check_command              check_http
        }
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-disk
        check_command              check_nrpe!check_disk
        }
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-alive
        check_command              check-host-alive
        }
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-load
        check_command              check_nrpe!check_load
11、错误处理总结
①#如果提示“Whoops!   Error: Could not read object configuration data! ”,这是因为没有启动nagios后台进程,执行以下命令
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg 或者service nagios restart
②It appears as though you do not have permission to view information for any of the services you requested…
解决:打开cgi.cfg配置文件,里面有个参数:
use_authentication=1
为了保障系统的安全性,nagios设置了这个参数,默认为1,改为0即可




运维网声明 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-663803-1-1.html 上篇帖子: Nagios插件check_traffic.sh问题 下篇帖子: 在RHEL5.3上配置基本的Nagios系统(使用Nagios-3.1.2)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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