欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nagios监控

程序员文章站 2022-05-16 20:34:16
...

nagios监控

一、 配置nagios监控
1、 配置LAMP平台
1)
安装LAMP软件

[aaa@qq.com ~]# rm -rf /etc/yum.repos.d/CentOS-*
[aaa@qq.com ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[aaa@qq.com ~]# yum -y install httpd mariadb mariadb-server php php-mysql openssl-devel
2)
创建php测试文件

[aaa@qq.com ~]# vim /var/www/html/index.php

<?php phpinfo(); ?>

3)
客户端访问

nagios监控
4)
启动apache、mariadb

[aaa@qq.com ~]# systemctl start httpd
[aaa@qq.com ~]# systemctl enable httpd
[aaa@qq.com ~]# systemctl start mariadb
[aaa@qq.com ~]# systemctl enable mariadb
5)
创建管理nagios账户

[aaa@qq.com ~]# useradd -M -s /sbin/nologin nagios
6)
配置nagios

[aaa@qq.com ~]# umount /mnt/
nagios监控
[aaa@qq.com ~]# tar zxvf /mnt/nagios-4.0.1.tar.gz -C /usr/src/
[aaa@qq.com nagios-4.0.1]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
7)
安装nagios

[aaa@qq.com nagios-4.0.1]# make all && make install && make install-init
[aaa@qq.com nagios-4.0.1]# make install-commandmode && make install-config
8)
设置目录的所有者

[aaa@qq.com ~]# chown -R nagios:nagios /usr/local/nagios/
9)
添加系统访问设置开机自启

[aaa@qq.com ~]# chkconfig --add nagios
[aaa@qq.com ~]# chkconfig --level 35 nagios on
2、 安装nagios依赖组件
1)
安装nagios-plugins

[aaa@qq.com ~]# tar -zxvf /mnt/nagios-plugins-1.5.tar.gz -C /usr/src/
[aaa@qq.com ~]# cd /usr/src/nagios-plugins-1.5/
[aaa@qq.com nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios
[aaa@qq.com nagios-plugins-1.5]# make && make install
2)
安装nrpe

[aaa@qq.com ~]# tar zxvf /mnt/nrpe-2.15.tar.gz -C /usr/src/
[aaa@qq.com ~]# cd /usr/src/nrpe-2.15/
[aaa@qq.com nrpe-2.15]# ./configure && make all && make install-plugin
3、 配置httpd支持nagios
1)
修改apache主配置文件

[aaa@qq.com ~]# vim /etc/httpd/conf/httpd.conf
ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”

<Directory “/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.users”
Require valid-user

Alias /nagios “/usr/local/nagios/share”

<Directory “/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.users”
Require valid-user

2)
生成登陆验证账户密码

[aaa@qq.com ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
3)
重新启动apache

[aaa@qq.com ~]# systemctl restart httpd
4、 配置sendmail
1)
安装sendmail

[aaa@qq.com ~]# tar zxvf /mnt/sendEmail-v1.55.tar.gz -C /usr/src/
2)
移动sebdEnail到bin下

[aaa@qq.com ~]# mv /usr/src/sendEmail-v1.55/sendEmail /usr/local/bin/
3)
修改配置文件

[aaa@qq.com ~]# vim /usr/local/nagios/etc/nagios.cfg
36 cfg_dir=/usr/local/nagios/etc/conf
4)
创建目录

[aaa@qq.com ~]# mkdir /usr/local/nagios/etc/conf/
5、 定义nagios命令
[aaa@qq.com ~]# vim /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name notify-host-by-sendEmail command_line /usr/bin/printf “%b” “***** Nagios ***\n\nNotification Type: NOTIFICATIONTYPENOTIFICATIONTYPE\nHost: HOSTNAMEHOSTNAME\nState: HOSTSTATEHOSTSTATE\nAddress: HOSTADDRESSHOSTADDRESS\nInfo: HOSTOUTPUTHOSTOUTPUT\n\nDate/Time: LONGDATETIMELONGDATETIME\n" | /usr/local/bin/sendEmail -o fqdn=FQND -f aaa@qq.com -t CONTACTEMAILCONTACTEMAIL -s smtp.qq.com -u " NOTIFICATIONTYPENOTIFICATIONTYPE Host Alert: HOSTNAMEHOSTNAME is HOSTSTATEHOSTSTATE **” -xu 821409986 -xp hehe
}

define command{
command_name notify-service-by-sendEmail
command_line /usr/bin/printf “%b” “***** Nagios ***\n\nNotification Type: NOTIFICATIONTYPENOTIFICATIONTYPE\n\nService: SERVICEDESCSERVICEDESC\nHost: HOSTALIASHOSTALIAS\nAddress: HOSTADDRESSHOSTADDRESS\nState: SERVICESTATESERVICESTATE\n\nDate/Time: LONGDATETIMELONGDATETIME\n\nAdditional Info:\n\nSERVICEOUTPUTSERVICEOUTPUT\n" | /usr/local/bin/sendEmail -o fqdn=FQDN -f aaa@qq.com -t CONTACTEMAILCONTACTEMAIL -s smtp.qq.com -u " NOTIFICATIONTYPENOTIFICATIONTYPE Service Alert: HOSTALIASHOSTALIAS/SERVICEDESCSERVICEDESC is SERVICESTATESERVICESTATE **” -xu 821409986 -xp hehe
}

define command{
command_name check_nrpe
command_line USER1USER1/check_nrpe -H HOSTADDRESSHOSTADDRESS -c ARG1ARG1
}
6、 定义联系人
[aaa@qq.com ~]# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name 821409986
alias 821409986
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-sendEmail
host_notification_commands notify-host-by-sendEmail
email aaa@qq.com
}
define contactgroup{
contactgroup_name 821409986
alias Nagios admin
members 821409986
}
7、 定义监控主机
1)
配置监控主机100.20

[aaa@qq.com ~]# vim /usr/local/nagios/etc/conf/hostgroups.cfg
define hostgroup{
hostgroup_name web-server
alias web-server
members 192.168.100.20
}

[aaa@qq.com ~]# vim /usr/local/nagios/etc/conf/192.168.100.20.cfg
define host{
host_name 192.168.100.20
alias web-server
address 192.168.100.20
check_command check-host-alive
max_check_attempts 5
check_period 24x7
notification_period 24x7
notification_options d,u,r
contact_groups 821409986
}

define service{
host_name 192.168.100.20
service_description check-host-alive
check_command check-host-alive
max_check_attempts 3
normal_check_interval 2
retry_check_interval 2
check_period 24x7

notification web-server_interval 10

    notification_period                     24x7
    notification_options            w,u,c,r
    contact_groups                  821409986

}

define service{
host_name 192.168.100.20
service_description check-procs
check_command check_nrpe!check_total_procs
max_check_attempts 3
normal_check_interval 2
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups 821409986
}

define service{
host_name 192.168.100.20
service_description check-load
check_command check_nrpe!check_load
max_check_attempts 3
normal_check_interval 2
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups 821409986
}
2)
设置目录所有者并重启apache、nagios

[aaa@qq.com ~]# chown -R nagios:nagios /usr/local/nagios/
[aaa@qq.com ~]# systemctl restart httpd
[aaa@qq.com ~]# systemctl restart nagios
3)
客户端访问nagios,账户nagisoadmin,密码aaa@qq.com

nagios监控
nagios监控
nagios监控
8、 部署被监控端
1)
安装软件包

[aaa@qq.com ~]# rm -rf /etc/yum.repos.d/CentOS-*
[aaa@qq.com ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[aaa@qq.com ~]# yum -y install openssl-devel openssl
2)
安装nagios-plugins插件

[aaa@qq.com ~]# useradd -s /sbin/nologin nagios
[aaa@qq.com ~]# umount /mnt/
nagios监控[aaa@qq.com ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[aaa@qq.com ~]# tar zxvf /mnt/nagios-plugins-1.5.tar.gz -C /usr/src/
[aaa@qq.com nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[aaa@qq.com nagios-plugins-1.5]# make && make install
3)
安装nrpe

[aaa@qq.com ~]# tar zxvf /mnt/nrpe-2.15.tar.gz -C /usr/src/
[aaa@qq.com ~]# cd /usr/src/nrpe-2.15/
[aaa@qq.com nrpe-2.15]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[aaa@qq.com nrpe-2.15]# make all && make install-plugin && make install-daemon && make install-daemon-config
4)
修改配置文件

[aaa@qq.com ~]# vim /usr/local/nagios/etc/nrpe.cfg
81 allowed_hosts=127.0.0.1,192.168.100.10
[aaa@qq.com ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
5)
客户端访问

nagios监控
nagios监控
nagios监控
nagios监控

相关标签: nagios监控 nagios