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

rpm环境 + 源码nagios

[复制链接]

尚未签到

发表于 2019-1-16 08:11:28 | 显示全部楼层 |阅读模式
  一,安装apache和php
# yum -y install httpd httpd-devel php php-common php-pdo php-gd
1)编辑apache配置文件
vim /etc/httpd/conf/httpd.conf
391 DirectoryIndex index.html index.php
392 AddType application/x-httpd-php .php

2)写php测试页面
# cat /var/www/html/index.php


二、安装nagios
1)建立nagios用户
useradd -s /sbin/nologin nagios
mkdir /usr/local/nagios                  
chown -R nagios.nagios /usr/local/nagios
2)编译安装nagios
  tar -zxvf nagios-3.2.3.tar.gz
  cd nagios-3.2.3
  ./configure --prefix=/usr/local/nagios/
  make all
  make install
  make install-init
  make install-commandmode
  make install-config
  chkconfig --add nagios
  chkconfig nagios on
  chkconfig --list nagios
3)安装nagios-plugins
tar -zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --prefix=/usr/local/nagios/
make && make install
4)安装汉化包
tar -jxvf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure && make all && make install


三,配置
1)配置httpd添加授权
vim /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
        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
        Require valid-user

2)生成密码
# htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
New password: (输入密码)
Re-type new password: (再输入一次密码)
Adding password for user nagiosadmin
#这里为方便就用了nagiosadmin这个用户,如果用其他用户访问时要在/usr/local/nagios/etc/cgi.cfg里将nagiosadmin后面加上相应的用户即可

# service  nagios start 启动


3)配置nagios
# vim /usr/local/nagios/etc/objects/hosts.cfg /添加要监控的主机,默认这个文件没有的。
define host{
        use     linux-server
        host_name       peace-nagios
        alias   nagios
        address 192.168.10.246
}
define host{
        use     linux-server
        host_name       client-173
        alias   peace-client
        address 192.168.10.173
}
define host{
        use     linux-server
        host_name       client-206
        alias   client
        address 192.168.10.206
}   

# vim /usr/local/nagios/etc/objects/services.cfg /定义监控主机的服务,默认也是没有的
############################ peace-nagios ##############################
define service {
        use     local-service
        host_name       peace-nagios
        service_description     PING
        check_command   check_ping!100.0,20%!500.0,60%
}
define service {
        use     local-service
        host_name       peace-nagios
        service_description     SSH
        check_command   check_tcp!12321
}
define service {
        use     local-service
        host_name       peace-nagios
        service_description     http
        check_command   check_http
}
############################ client-173 ##############################
define service {
        use     local-service
        host_name       client-173
        service_description     PING
        check_command   check_ping!100.0,20%!500.0,60%
}
define service {
        use     local-service
        host_name       client-173
        service_description     SSH
        check_command   check_ssh
}
define service {
        use     local-service
        host_name       client-173
        service_description     http
        check_command   check_http
}
############################ client-206 ##############################
define service {
        use     local-service
        host_name       client-206
        service_description     PING
        check_command   check_ping!100.0,20%!500.0,60%
}
define service {
        use     local-service
        host_name       client-206
        service_description     SSH
        check_command   check_ssh
}
define service {
        use     local-service
        host_name       client-206
        service_description     http
        check_command   check_http
}
# chown nagios.nagios hosts.cfg services.cfg /添加用户组

# vim /usr/local/nagios/etc/nagios.cfg /添加刚定义的两个文件
cfg_file=/usr/local/nagios//etc/objects/hosts.cfg
cfg_file=/usr/local/nagios//etc/objects/services.cfg

自带的检测一下
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 3.2.3
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 10-03-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/hosts.cfg'...
Processing object config file '/usr/local/nagios//etc/objects/services.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
        Checked 9 services.
Checking hosts...
        Checked 3 hosts.
Checking host groups...
        Checked 0 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
# service  nagios restart

四、PNP(小太阳)
1)安装rrdtool需要的环境
#yum -y install cairo-devel libxml2-devel pango pango-devel
2)安装rrdtool
#tar zxvf rrdtool-1.4.4.tar.gz
#cd rrdtool-1.4.4
#./configure --prefix=/usr/local/rrdtool
#make && make install
3)安装pnp
tar -zxvf pnp-0.4.14.tar.gz
cd pnp-0.4.14
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata
make all
make install
make install-config
make install-init
4)配置pnp
cd /usr/local/nagios/etc/pnp/
cp process_perfdata.cfg-sample process_perfdata.cfg
cp npcd.cfg-sample npcd.cfg
cp rra.cfg-sample rra.cfg
chown -R nagios.nagios /usr/local/nagios/etc/pnp/
5)修改process_perfdata.cfg文件
# vim /usr/local/nagios/etc/pnp/process_perfdata.cfg
40 LOG_FILE = /usr/local/nagios/var/perfdata.log
41 #
42 # Loglevel 0=silent 1=normal 2=debug
43 #
44 LOG_LEVEL = 2    /改成2 也就是debug模式
6)修改nagios,增加图标
# vim /usr/local/nagios/etc/objects/templates.cfg  /添加
define host{
        name    hosts-pnp
        register        0
        action_url /nagios/pnp/index.php?host=$HOSTNAME$
        process_perf_data
}
define service{
        name    services-pnp
        register        0
        action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
        process_perf_data
}
# vim /usr/local/nagios/etc/nagios.cfg /找到下面几行,去# 修改后如下:
833 process_performance_data=1
845 host_perfdata_command=process-host-perfdata
846 service_perfdata_command=process-service-perfdata
# vim /usr/local/nagios/etc/objects/commands.cfg  /找到下面的内容,修改如下
# 'process-host-perfdata' command definition
define command{
        command_name    process-host-perfdata
        command_line    /usr/local/nagios/libexec/process_perfdata.pl
        }

# 'process-service-perfdata' command definition
define command{
        command_name    process-service-perfdata
        command_line    /usr/local/nagios/libexec/process_perfdata.pl
        }
# vim /usr/local/nagios/etc/objects/hosts.cfg   /在每个use 后都添加添加services-pnp,如下
define host{
        use     linux-server,hosts-pnp
        host_name       peace-nagios
        alias   nagios
        address 192.168.10.246
}
……
# vim /usr/local/nagios/etc/objects/services.cfg  /在每个use 后都添加添加services-pnp,如下
define service {
        use     local-service,services-pnp
        host_name       peace-nagios
        service_description     PING
        check_command   check_ping!100.0,20%!500.0,60%
}
……
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg /检测没有问题重新启动nagios
# service  nagios restart

五、nrpe
1)被监控端
useradd -s /sbin/nologin nagios
tar -zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure
make && make install
chown nagios.nagios /usr/local/nagios/
chown -R nagios.nagios /usr/local/nagios/libexec/
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure && make all && make install-plugin && make instal-daemon && make install-daemon-config
make install-daemon
make install-daemon-config

# vim /usr/local/nagios/etc/nrpe.cfg    /编辑nrpe,定义命令
allowed_hosts=192.168.10.246,127.0.0.1
# The following examples use hardcoded command arguments...

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_sda]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda
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 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20 -c 10

#usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg  -d  /启动
#/usr/local/nagios/libexec/check_nrpe  -H 127.0.0.1    /检测是否开启
2)监控端
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure && make all && make install-plugin
#/usr/local/nagios/libexec/check_nrpe -H 192.168.10.206   /测试与客户端的连接是否成功
NRPE v2.8.1  /表示OK了

# vim /usr/local/nagios/etc/objects/commands.cfg
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
# vim /usr/local/nagios/etc/objects/services.cfg
define service {
        use     local-service,services-pnp
        host_name       client-206
        service_description     users
        check_command   check_nrpe!check_users
}
define service {
        use     local-service,services-pnp
        host_name       client-206
        service_description     disk
        check_command   check_nrpe!check_sda
}
define service {
        use     local-service,services-pnp
        host_name       client-206
        service_description     swap
        check_command   check_nrpe!check_swap
}

#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#service nagios restart

3)nrpe常见故障

错误一:/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
CHECK_NRPE: Error - Could not complete SSL handshake
解析办法:配置allowed_hosts=192.168.1.100,127.0.0.1,然后kill进程再重启就OK了

错误二:/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
Connection refused by host
解析办法:Nrpe进程没有启动

六、飞信报警
mkdir /usr/local/fetion
cd /usr/local/fetion/
cp /tools/fetion  .
cp /tools/linuxso_20101113.rar .
unrar x linuxso_20101113.rar
chmod +x fetion
./fetion

#/usr/local/fetion/fetion --mobile=15801093291 --pwd=l147258 --to=15801093291 --msg-utf8=测试 /测试飞信,只要输入验证码,下载下来在输入。
SIP-C/4.0 280 Send SMS OK
T: sip:338658633@fetion.com.cn;p=6911
I: 2
Q: 1 M
L: 114
D: Thu, 09 Feb 2012 00:07:48 GMT
XI: E63BC47E056E2D8149F3D435F4F18F6
这样就OK了
# vim /usr/local/nagios/etc/objects/commands.cfg   /定义服务和主机的内容
define command{
        command_name    notify-service-by-sms
        command_line    /usr/local/fetion/fetion --mobile=15801093291 --pwd=l147258 --to=$CONTACTPAGER$ --msg-utf8="service $HOSTADDRESS$ error "
}
define command{
        command_name    notify-host-by-sms
        command_line    /usr/local/fetion/fetion --mobile=15801093291 --pwd=l147258 --to=$CONTACTPAGER$ --msg-utf8="HOST error "
}

# vim /usr/local/nagios/etc/objects/templates.cfg /修改联系人的定义
define contact{
        name                            generic-contact
    ……
    service_notification_commands   notify-service-by-email,notify-service-by-sms   
        host_notification_commands      notify-host-by-email,notify-service-by-sms
    ……
# vim /usr/local/nagios/etc/objects/contacts.cfg /定义接收的手机,多个以,分割

define contact{
        contact_name                    nagiosadmin            
        use                             generic-contact         
        alias                           Nagios Admin            
        email                           nagios@localhost      
        pager                           15801093291
}




运维网声明 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-663778-1-1.html 上篇帖子: Nagios 监控平台快速安装 下篇帖子: 远程nagios监控
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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