Linux监控和安全运维---nagios安装及部署

nagios安装

[[email protected] ~]# rpm -ivh http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm

[[email protected] ~]# yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

[[email protected] ~]# htpasswd -c /etc/nagios/passwd nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin

//设置密码

[[email protected] ~]# vim /etc/nagios/nagios.cfg    //查看配置文件

[[email protected] ~]# nagios -v /etc/nagios/nagios.cfg

Total Warnings: 0

Total Errors:   0

//检查配置文件,无告警和错误

[[email protected] ~]# service httpd start

[[email protected] ~]# service nagios start

//启动服务

浏览器访问:192.168.137.21/nagios

输入用户名密码,访问

nagios安装客户端1

在客户端上:

[[email protected] ~]# rpm -ivh http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm

[[email protected] ~]# yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

[[email protected] ~]# vim /etc/nagios/nrpe.cfg

allowed_hosts=192.168.137.21               //允许哪台设备连(服务端)

dont_blame_nrpe=1

[[email protected] ~]# /etc/init.d/nrpe start

监控端服务器添加被监控的主机(192.168.137.23)

[[email protected] ~]# cd /etc/nagios/conf.d/

[[email protected] conf.d]# vim 192.168.137.23.cfg

define host{

use                     linux-server            ; Name of host template to use

; This host definition will inherit all variables that are defined

; in (or inherited by) the linux-server host template definition.

host_name               192.168.137.23

alias                   137.23

address                 192.168.137.23

}

define service{

use                     generic-service

host_name               192.168.137.23

service_description     check_ping

check_command           check_ping!100.0,20%!200.0,50%

max_check_attempts 5

normal_check_interval 1

}

define service{

use                     generic-service

host_name               192.168.137.23

service_description     check_ssh

check_command           check_ssh

max_check_attempts      5

normal_check_interval 1

}

define service{

use                     generic-service

host_name               192.168.137.23

service_description     check_http

check_command           check_http

max_check_attempts      5

normal_check_interval 1

}

[[email protected] conf.d]# nagios -v /etc/nagios/nagios.cfg        //检查配置有无错误

Total Warnings: 0

Total Errors:   0

[[email protected] conf.d]# service nagios restart

点击左侧host,出现192.168.137.23客户端(被监控设备)

点击services查看各种服务状态

nagios监控客户端2

以上监控无需安装其他软件,现借助nrpe监控具体的服务

服务端:

[[email protected] conf.d]# vim /etc/nagios/objects/commands.cfg             //末尾加

define command{

command_name    check_nrpe

command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

[[email protected] conf.d]# vim /etc/nagios/conf.d/192.168.137.23.cfg

define service{

use     generic-service

host_name       192.168.137.23

service_description     check_load

check_command           check_nrpe!check_load

max_check_attempts 5

normal_check_interval 1

}

define service{

use     generic-service

host_name       192.168.137.23

service_description     check_disk_hda1

check_command           check_nrpe!check_hda1

max_check_attempts 5

normal_check_interval 1

}

define service{

use     generic-service

host_name       192.168.137.23

service_description     check_disk_hda3

check_command           check_nrpe!check_hda3

max_check_attempts 5

normal_check_interval 1

}

//尾行在添加三个服务

客户端查看配置文件

[[email protected] ~]# vim /etc/nagios/nrpe.cfg

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10

command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20

command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1

command[check_hda3]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda3

command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200

//查看,服务器上的命令在此定义check_load、check_hda1等,修改hda1成sda1,设备上只有sda1,无hda1.

[[email protected] ~]# ls /usr/lib/nagios/plugins/check_load

/usr/lib/nagios/plugins/check_load

[[email protected] ~]# /etc/init.d/nrpe restart

服务端:

[[email protected] conf.d]# /etc/init.d/nagios restart

网页访问;新添加的三个监控服务已出现

服务端查看nagios日志

[email protected] conf.d]# ls /var/log/nagios/

[[email protected] conf.d]# tail /var/log/nagios/nagios.log

nagios配置邮件告警

先定义人、组。告警人邮箱信息等

[email protected] conf.d]# vim /etc/nagios/objects/contacts.cfg

define contact{                                                 #定义一个人

contact_name                    123

use                             generic-contact

alias                           cai

email                           [email protected]

}

define contact{

contact_name                    456

use                             generic-contact

alias                           yao

email                           [email protected]

}

define contactgroup{                                      #定义一个组有哪些人

contactgroup_name               common

alias                           common

members                         123,456

}6

}

//尾行添加

然后需在告警的服务器里加上contactgroup

服务器上:

[[email protected] conf.d]# vim /etc/nagios/conf.d/192.168.137.23.cfg

define service{

use     generic-service

host_name       192.168.137.23

service_description     check_load

check_command           check_nrpe!check_load

max_check_attempts 5

normal_check_interval 1

contact_groups     common

# notification_period  24*7

# notification_options c,r

}

//如check_load负载需加邮件告警,则在check_load中加contact_groups  common,common为某组,告警组内成员notification_period  24*7告警时间段24*7,notification_options c,r出现问题恢复时告警

时间: 2024-10-12 09:40:21

Linux监控和安全运维---nagios安装及部署的相关文章

Linux监控和安全运维---zabbix安装及部署

zabbix服务端安装 [[email protected] conf.d]# rpm -ivh http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm [[email protected] conf.d]# yum install -y  httpd mysql mysql-libs php php-mysql mysql-server php-bcmath php-g

Linux监控和安全运维--cacti安装部署

cacti安装 [[email protected]~]# rpm -ivh http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm //安装epel扩展源 [[email protected] ~]# yum install -y  httpd php php-mysql mysql mysql-server mysql-devel php-gd  libjpeg li

第四阶段 :安全与监控 Linux监控和安全运维

监控介绍 monitor  cacti(rrdtool) 画图 监控网络设备 流量 展现历史数据功能 nagios 监控服务的状态 磁盘 内存 不会记录数据 一目了然 可自己写脚本 zabbix cacti安装 rpm -ivh http://www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm yum install  epel-release yum install -y  httpd php php-m

Linux监控和安全运维 2.0 zabbix配置邮件告警

1.发邮件启动postfix /etc/init.d/postfix start mail -s "test" 836503270@qq.com < /etc/inittab mailq 查看发送结果 2.配置发邮件文件 mkdir -p /home/zabbix/bin vim /home/zabbix/bin/baojing.sh #! /bin/bash echo "$3" |/bin/mail -s "$2" $1 chmod +x

无监控,不运维!运维监控工具平台建设总结

本文摘自微信公众号<高效运维> 运维行业有句话:"无监控.不运维",是的,一点也不夸张,监控俗称"第三只眼".没了监控,什么基础运维,业务运维都是"瞎子".所以说监控是运维这个职业的根本. 尤其是在现在DevOps这么火的时候,用监控数据给自己撑腰,这显得更加必要,有人说运维是背锅侠,那么,有了监控,有了充足的数据,一切以数据说话,运维还需要背锅吗,所以作为一个运维工程师,如何构建一套监控系统是你的第一件工作. 一.常见的运维监控工具

Linux服务器集群运维经验

公司大概有5000+以上的服务器节点,包括各种应用,我和同事共同维护大约2500+的服务器,主要包括一些视频cdn,直播视频cdn,webcdn和p2p服务器. 以下是自己在运维工作中的一点经验和看法,希望对大家有所帮助 1.       服务器型号的区分,为以后的统一化和标准化作硬件上的准备,很多人忽视这一点,其实如果这一点做得好会使后面的运维工作轻松很多,根据应用我们主要把服务器分为3中,cpu密集型,主要用于大量计算应用,比如p2p;内存密集型,用于cache类应用,比如squid,var

马哥2016全新Linux+Python高端运维班第三周作业作答

                    马哥2016全新Linux+Python高端运维班第三周作业                                           1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可.     [[email protected] ~]# who | awk '{print $1 $NF}'| uniq -d     [[email protected] ~]# who     yicx     :0  

Linux+Python高端运维班第二次作业

Linux+Python高端运维班第二次作业 1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可. [[email protected] ~]# who |cut -d" " -f1|uniq (unknown) root test1 [[email protected] ~]# who |cut -d" " -f1|sort -u root (unknown) wangyanglin 2.取出当前系统上被用户当作其默认shel

Windows服务器Pyton辅助运维--03.安装Visual Studio 的 Python 开发插件 PTVS

PTVS (Python Tools for Visual Studio) http://pytools.codeplex.com/ 当前版本:2.1 RC PTVS (Python Tools for Visual Studio) 是一个开源项目,采用Apache 2.0许可发布.PTVS的主要特性包括:CPython.IronPython.Jython和PyPy:高级编辑功能如IntelliSense:多重构:内置REPL(read-eval-print loop)窗口:调试和分析功能,等等