agios监控mysql的安装配置及报警

文章描述:-2022年4月13日发(作者:万里)一:agios的安装1.安装编译所需的软件包;[root@nagios~]#yum–yinstallhttpdphp-*gd-*mysql-devel[root@nagios~]#setenforce0#关闭selinux[root@nagios~]#sed's/=enforcing/=permissive/'/etc/sysconfig/selinux2.

-

agios监控mysql的安装配置及报警
2022年4月13日发
(作者:万里)

一:agios的安装

1.安装编译所需的软件包;

[root@nagios~]#yum–yinstallhttpdphp-*gd-*mysql-devel

[root@nagios~]#setenforce0#关闭selinux

[root@nagios~]

#sed's/=enforcing/=permissive/'/etc/sysconfig/selinux

2.创建运行nagios服务的用户;

[root@nagios~]#useraddnagios#创建运行nagios服务的用户

[root@nagios~]#usermod–Gnagiosapache#使apache用户对nagios目录具有写

权限,不然web页面操作失败

3.agios软件安装;

[root@nagios~]##释放nagios源码包

[root@nagios~]#cdnagios-cn-3.2.3

Ps:若在RHEL6X32位系统中安装2要先执行makeclean操作,

然后再执行./configure和makeall等操作,否则执行makeall时会报错!

[root@nagiosnagios-cn-3.2.3]#./configure--enable-embedded-perl#编译nagios

[root@nagiosnagios-cn-3.2.3]#makeall

[root@nagiosnagios-cn-3.2.3]#makeinstall#安装主程序,CGI和HTML文件

[root@nagiosnagios-cn-3.2.3]#makeinstall-init#在/etc/rc.d/init.d安装启动脚本

[root@nagiosnagios-cn-3.2.3]#makeinstall-commandmode#配置目录权限

[root@nagiosnagios-cn-3.2.3]#makeinstall-config#安装示例配置文件

[root@nagiosnagios-cn-3.2.3]#makeinstall-webconf#安装nagios的web接口,

会在/etc/httpd/conf.d目录

中创建文件

4.安装agios-plugins插件;

[root@nagios~]#

[root@nagios~]#cdnagios-plugins-1.4.15

[root@nagiosnagios-plugins-1.4.15]#./configure–with-nagios-user=nagios--with-nagios-group=nagios–enable-extra-opts--enable-libtap--enable-perl-modules

[root@nagiosnagios-plugins-1.4.15]#make&&makeinstall

(Ps:会在”/usr/local/nagios/libexec”目录下多出一些文件,这里存放nagios所有插件)

5.修改nagios的主配置文件;

[root@nagios~]#vim/usr/local/nagios/etc/新建cfg_file=/usr/local/nagios/etc/objects/#存放主机与主机组定义cfg_file=/usr/local/nagios/etc/objects/#存放服务与服务组定义修改#cfg_file=/usr/local/nagios/etc/objects/#加”#”注释,在36行

6.创建文件;

[root@nagios~]#vim/usr/local/nagios/etc/objects/inehost{uselinux-server#定义使用的模版host_namenagios#被监控主机名称aliasnagios#别名address127.0.0.1#被监控主机的IP地址icon_tusmap_22d_coords100,3003d_coords100,300,100check_commandcheck-host-alive#监控命令,来自文件max_check_attempts5#检查失败后重试的次数check_period24x7#查看的时间段,来自定义contact_groupsadmins#联系人组,在中定义的notification_interval10#提醒的间隔,每隔10分钟提醒一次notification_period24x7#提醒的周期,24x7,来自定义notification_optid,u,r#指定什么情况下提醒

}

definehostgroup{hostgroup_namelinux-serversaliaslinuxservermembers*

}

7.创建文件;

[root@nagios~]#vim/usr/local/nagios/etc/objects/ineservice{

uselocal-service

host_namenagios

service_groupssystemcheck

service_description主机存活

check_commandcheck-host-alive

}

defineservice{

uselocal-service

host_namenagios

service_groupssystemcheck

service_description登录用户数

check_commandcheck_local_users!20!50

#监测远程主机当前的登录用户数量,如果大于20用户则报warning,如果大

于50则报critical

}

defineservice{

uselocal-service

host_namenagios

service_groupssystemcheck

service_description根分区使用率

check_commandcheck_local_disk!20%!10%!/

#如果可用空间低于20%会报Warning,如果可用空间低于10%则报Critical

}

defineservice{

uselocal-service

host_namenagios

service_groupssystemcheck

service_description进程总数

check_commandcheck_local_procs!250!400!RSZDT

#监测远程主机当前的进程总数,如果大于250进程则报warning,如果大于

400进程则报critical,S(休眠)、R(运行)、Z(僵死)、

D(不可中断)、T(停

止)

}

defineservice{

uselocal-service

host_namenagios

service_groupssystemcheck

service_descriptionCPU负载

check_commandcheck_local_load!5.0,4.0,3.0!10.0,6.0,4.0

#当1分钟多于5个进程等待,5分钟多于4个,15分钟多于3个则为warning状态

#当1分钟多于10个进程等待,5分钟多于6个,15分钟多于4个则为critical状态

}

defineservice{

uselocal-service

host_namenagios

service_groupssystemcheck

service_description交换空间利用率

check_commandcheck_local_swap!20%!10%

#如果交换空间低于20%会报Warning,如果可用空间低于10%则报Critical

}defineservicegroup{

servicegroup_namesystemcheck

aliassystemcheck

}[root@nagios~]#/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/#校验nagios配置文件的正确性[root@nagios~]#htpasswd–c/usr/local/nagios/etc/agiosadmin#添加一个访问nagios页面的授权用户,默认用户是nagiosadmin,创建其他用户修改

/usr/local/nagios/etc/文件:方法一:修改use_authentication=0值为0(在78行)

方法二:

authorized_for_system_information=nagiosadmin

authorized_for_configuration_information=nagiosadmin

authorized_for_system_commands=nagiosadmin

authorized_for_all_services=nagiosadmin

authorized_for_all_hosts=nagiosadmin

authorized_for_all_service_commands=nagiosadmin

authorized_for_all_host_commands=nagiosadmin

(用:%s/nagiosadmin/新用户名命令替换所有nagiosadmin字符)

8.启动httpd和nagios服务并设置开机自动启动

[root@nagios~]#serviceiptablesstop

[root@nagios~]#servicenagiosstart

[root@nagios~]#servicehttpdstart

[root@nagios~]#chkconfighttpdon

[root@nagios~]#chkconfignagioson

[root@nagios~]#chkconfigiptablesoff

(Ps:如果开启了selinux需要配置如下两步:

chcon-R–thttpd_sys_content_t/usr/local/nagios/sbin/

chcon-R–thttpd_sys-content_t/usr/local/nagios/share/)

二:被监控端安装(以mysql为例,监控mysql服务的运行情况)

1.安装并启动mysql的服务

[root@mysql~]#yum–yinstallmysql-server

[root@mysql~]#servicemysqldstart

[root@mysql~]#serviceiptablesstop

[root@mysql~]#chkconfigmysqldon

[root@mysql~]#chkconfigiptablesoff

2.

在mysql服务器上创建

监控检测帐户

[root@mysql~]#mysql

mysql>createdatabasenagdb;

mysql>grantselectonnagdb.*tonagdb@’监控主机IP’;

mysql>flushprivileges;

mysql>exit3.在nagis主机上检测是否可以链接mysql主机上的mysql服务

[root@nagios~]#/usr/local/nagios/libexec/check_mysql–H被监控端IP–unagdb–dnagdb

4.在nagios主机上添加对msyql服务监控的定义

[root@nagios~]#vim/usr/local/nagios/etc/objects/inehost{uselinux-serverhost_namemysqlhostaliasmysqlserveraddress被监控端主机IPicon_tusmap_22d_coords100,3003d_coords100,300,100check_commandcheck-host-alivemax_check_attempts5check_period24x7contact_groupadminsnotification_interval10notification_period24x7notification_optid,u,r

}[root@nagios~]#vim/usr/local/nagios/etc/objects/ineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_descriptionmysqlservicecheck_commandcheck_mysqlcontact_groupsadminsnotification_interval10notification_period24x7notification_optiw,u,r,c

}

defineservicegroup{servicegroup_namemysqlgroupaliasmysqlservices

}[root@nagios~]#vim/usr/local/nagios/etc/objects/inecommand{

command_namecheck_mysql

command_line$USER1$/check_mysql-H$HOSTADDRESS$-unagdb-dnagdb

}[root@nagios~]#/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/#检测无误后重新加载nagios服务[root@nagios~]#servicenagiosreload

三:agios通过RPE监控远程主机系统状况(以mysql主机为例)

1.在被监控端安装nagios-plugins和nrpe

[root@mysql~]#useraddnagios

[root@mysql~]#

[root@mysql~]#cdnagios-plugins-1.4.15

[root@mysqlnagios-plugins-1.4.15]#./configure--with-nagios-user=nagios--with-nagios-group=nagios

[root@mysqlnagios-plugins-1.4.15]#make&&makeinstall

[root@mysqlnagios-plugins-1.4.15]#cd

[root@mysql~]#yum

–yinstallxinetd

[root@mysql~]#

[root@mysql~]#cdnrpe-2.12

[root@mysqlnrpe-2.12]#./configure

[root@mysqlnrpe-2.12]#makeall

[root@mysqlnrpe-2.12]#makeinstall-plugin

[root@mysqlnrpe-2.12]#makeinstall-daemon

#安装守护进程

[root@mysqlnrpe-2.12]#makeinstall-daemon-config#安装配置文件

[root@mysqlnrpe-2.12]#makeinstall-xinetd

#安装xinetd脚本

2.配置nrpe,添加nrpe服务

[root@mysql~]#vim/etc/xinetd.d/nrpe修改only_from=127.0.0.1监控主机IP#在后面增加监控主机(即nagios服务器)的地址,以空格间隔

[root@mysql~]#vim/etc/services添加nrpe5666/tcp#nrpe#nrpe服务监听端口

[root@mysql~]#vim/usr/local/nagios/etc/修改command[check_disk]=/usr/local/nagios/libexec/check_disk–w20%-c10%-p/

#在234行,将#注释去掉并修改,’/’表示根分区检测

[root@mysql~]#servicexinetdrestart

[root@mysql~]#netstat–at|grepnrpe

[root@mysql~]#netstat–an|grep5666#重启xinetd服务,并查看RPE是否已经启动

3.监控主机的设置

[root@nagios~]#

[root@nagios~]#cdnrpe-2.12

[root@nagiosnrpe-2.12]#./configure

--with-nagios-user=nagios--with-nagios-group=nagios

[root@nagiosnrpe-2.12]#makeall&&makeinstall-plugin

[root@nagios~]#/usr/local/nagios/libexec/check_nrpe–H被监控端IP#如输出RPEv2.12说明连接正常

[root@nagios~]#vim/usr/local/nagios/etc/objects/inecommand{command_namecheck_nrpe

#定义命令名称为check_nrpe,在中要使用这个名称command_line$USER1$/check_nrpe–H$HOSTADDRESS$-c$ARG1$

#用$USER1$代替/usr/local/nagios/libexec,后面带的$ARG1$参数是传给nrpe

daemon执行的检测命令

}

[root@mysql~]#vim/usr/local/nagios/etc/#监控mysql主机的SWAP分区command[check_swap]=/usr/local/nagios/libexec/check_swap–w20%-c10%

[root@mysql~]#servicexinetdreload

[root@nagios~]#cd/usr/local/nagios/libexec

[root@nagioslibexec]#./check_nrpe–H被监控端主机IP-ccheck_swap

[root@nagios~]#vim/usr/local/nagios/etc/objects/ineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_descriptionSWAP分区check_commandcheck_nrpe!check_swapcontact_groupsadminsnotification_interval10notification_period24x7notification_optiw,u,r,c

}

defineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_descriptionCPU负载check_commandcheck_nrpe!check_loadcontact_groupsadminsnotification_interval10notification_period24x7notification_optiw,u,r,c

}

defineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_description登录用户数check_commandcheck_nrpe!check_userscontact_groupsadminsnotification_interval10notification_period24x7notification_optiw,u,r,c

}

defineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_description磁盘剩余空间check_commandcheck_nrpe!check_diskcontact_groupsadminsnotification_interval10notification_period24x7notification_optiw,u,r,c

}

defineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_description总进程check_commandcheck_nrpe!check_total_procscontact_groupsadminsnotification_interval10notification_period24x7notification_optiw,u,r,c

}

defineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_description僵尸进程check_commandcheck_nrpe!check_zombie_procscontact_groupsadminsnotification_interval10notification_period24x7notification_optiw,u,r,c

}defineservice{usegeneric-servicehost_namemysqlhostservice_descriptionSWAPcheck_commandcheck_nrpe!check_swap

}

[root@nagios~]#/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/

[root@nagios~]#servicenagiosreload

四:通过邮件报警!

1.配置nagios邮箱报警功能

[root@nagios~]#vim/usr/local/nagios/etc/object/inecontact{contact_namenagiosadmin

}

aliasagiosAdmin

service_notification_period24x7

host_notification_period24x7

service_notification_optiw,u,c,r

host_notification_optid,u,r

service_notification_commandsnotify-service-by-email

host_notification_commandsnotify-host-by-email

email1009864@

#多个管理员邮箱地址使用空格或者逗号隔开

2.配置邮件服务器(这里以postfix介绍)

[root@nagios~]#yum–yinstallpostfix*httpd*dovecot*

[root@nagios~]#

[root@nagios~]#vim/etc/postfix/修改myhostname=#在75行mydomain=#在83行myorigin=$myhostname#在98行myorigin=$mydomain#在99行inet_interfaces=all#在113行mydestination=$myhostname,$mydomain#在164行

[root@nagios~]#servicesendmailstop

[root@nagios~]#servicepostfixstart

[root@nagios~]#netstat–an|grep25

[root@nagios~]#servicedovecotrestart

[root@nagios~]#postmap/etc/postfix/virtual

-

agios监控mysql的安装配置及报警

发布时间:2022-04-13 01:57:04
文章版权声明:除非注明,否则均为IT技术网-学习WEB前端开发等IT技术的网络平台原创文章,转载或复制请以超链接形式并注明出处。

发表评论

评论列表 (有 17 条评论,113人围观)
陈昊优胜教育加盟V铁粉15 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
c}defineservice{uselocal-servicehost_namemysqlhostservice_groupsmysqlgroupservice_description僵尸进程check_commandcheck_nrpe!check_zombie_procscontact_groupsadminsnotification_interval10notification_period24x7notification_optiw
性爱与性欲V铁粉24 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
如果可用空间低于10%则报Critical}defineservicegroup{servicegroup_namesystemcheckaliassystemcheck}[root@nagios~]#/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/#校验nagios配置文件的正确性[root@nagios~]#htpasswd–c/usr/local/nagios/etc/agiosadmin#添加一个访问nagios页面的授权用户
诺贝尔奖将揭晓V铁粉25 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
c}defineservicegroup{servicegroup_namemysqlgroupaliasmysqlservices}[root@nagios~]#vim/usr/local/nagios/etc/objects/inecommand{command_namecheck_mysqlcommand_line$USER1$/check_mysql-H$HOSTADDRESS$-unagdb-dnagdb}[root@nagios~]#/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/#检测无误后重新加载nagios服务[root@nagios~]#servicenagiosreload三:agios通过RPE监控远程主机系统状况(以mysql主机为例)1.在被监控端安装nagios-plugins和nrpe[root@mysql~]#useraddnagios[root@mysql~]#[root@mysql~]#cdnagios-plugins-1.4.15[root@mysqlnagios-plugins-1.4.15]#./configure--with-nagios-user=nagios--with-nagios-group=nagios[root@mysqlnagios-plugins-1.4.15]#make&&makeinstall[root@mysqlnagios-plugins-1.4.15]#cd[root@mysql~]#yum–yinstallxinetd[root@mysql~]#[root@mysql~]#cdnrpe-2.12[root@mysqlnrpe-2.12]#./configure[root@mysqlnrpe-2.12]#makeall[root@mysqlnrpe-2.12]#makeinstall-plugin[root@mysqlnrpe-2.12]#makeinstall-daemon#安装守护进程[root@mysqlnrpe-2.12]#makeinstall-daemon-config#安装配置文件[root@mysqlnrpe-2.12]#makeinstall-xinetd#安装xinetd脚本2.配置nrpe
大连商标注册V铁粉30 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
在中要使用这个名称command_line$USER1$/check_nrpe–H$HOSTADDRESS$-c$ARG1$#用$USER1$代替/usr/local/nagios/libexec
鼓楼大街二手房V铁粉0 second ago Google Chrome 93.0.4577.82 Windows 10 x64
u
中介者V铁粉21 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
%s/nagiosadmin/新用户名命令替换所有nagiosadmin字符)8.启动httpd和nagios服务并设置开机自动启动[root@nagios~]#serviceiptablesstop[root@nagios~]#servicenagiosstart[root@nagios~]#servicehttpdstart[root@nagios~]#chkconfighttpdon[root@nagios~]#chkconfignagioson[root@nagios~]#chkconfigiptablesoff(Ps
中关村美女V铁粉9 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
添加nrpe服务[root@mysql~]#vim/etc/xinetd.d/nrpe修改only_from=127.0.0.1监控主机IP#在后面增加监控主机(即nagios服务器)的地址
中国电信广东V铁粉27 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
100check_commandcheck-host-alivemax_check_attempts5check_period24x7contact_groupadminsnotification_interval10notification_period24x7notification_optid
购房工具V铁粉22 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
如果可用空间低于10%则报Critical}defineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_description进程总数check_commandcheck_local_procs!250!400!RSZDT#监测远程主机当前的进程总数
华明镇二手房信息V铁粉28 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
u
丰县华山中学V铁粉16 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
T(停止)}defineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_descriptionCPU负载check_commandcheck_local_load!5.0
柑橘多酚V铁粉23 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
3003d_coords100
手工啤酒V铁粉12 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
将#注释去掉并修改
瓦斯的主要成分V铁粉11 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
3003d_coords100
普京手机V铁粉26 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
15分钟多于3个则为warning状态#当1分钟多于10个进程等待
黄维简介V铁粉21 minutes ago Google Chrome 93.0.4577.82 Windows 10 x64
若在RHEL6X32位系统中安装2要先执行makeclean操作