版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】源码安装nagios监控系统(centos7)
一、nagios简介1、一款开源的电脑系统和网络监视工具,可以有效监控windows、Linux和Unix的主机状态
,交换机、路由器等网络设置。在系统或服务状态异常时发出邮件或者短信报警,第一
时间通知支离维人员,在状态恢复后发出正常的邮件或者短信通知。2、主要功能
网络服务监控(SMTP、POP3、HTTP、NNTP、ICMP、SNMP、FTP、SSH)
主机资源监控(CPUload、diskusage、systemlogs),也包括Windows主机(使用NSClient++plugin)
可以指定自己编写的Plugin通过网络收集数据来监控任何情况
可以通过配置Nagios远程执行插件远程执行脚本
远程监控支持SSH或SSL加通道方式进行监控
简单的plugin设计允许用户很容易的开发自己需要的检查服务,支持很多开发语言
包含很多图形化数据Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios等)
可并行服务检查
能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查
当服务或主机出现问题时发出通告,可通过email,pager,sms或任意用户自定义的plugin进行通知
能够自定义事件处理机制重新激活出问题的服务或主机
自动日志循环
支持冗余监控
包括Web界面可以查看当前网络状态,通知,问题历史,日志文件等二、nagios工作原理1、Nagios的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控、检测功能都是通过各种插件来完成的。2、Nagios4种状态返回信息
0(OK)表示状态正常/绿色
1(WARNING)表示出现警告/***
2(CRITICAL)表示出现非常严重的错误/红色
3(UNKNOWN)表示未知错误/深***3、Nagios通过NRPE来远端管理服务
Nagios执行安装在它里面的check_nrpe插件,并告诉check_nrpe去检测哪些服务。
通过SSL,check_nrpe连接远端机子上的NRPEdaemon
NRPE运行本地的各种插件去检测本地的服务和状态(check_disk)
最后,NRPE把检测的结果传给主机端的check_nrpe,check_nrpe再把结果送到Nagios状态队列中。
Nagios依次读取队列中的信息,再把结果显示出来。三、nagios安装(CentOS7)1、lamp环境搭建(1)源码安装apr-1.5.2和apr-util-1.5.4
cdapr-1.5.2
./configure&&make&&makeinstall
cdapr-util-1.5.4
./configure
--with-apr=/usr/local/apr/&&make&&makeinstall(2)安装openssl-devel
#mod_sslhasbeenrequested
yum-yinstallopenssl-devel(3)源码安装httpd-2.4.17
#./configure--prefix=/usr/local/apache2--sysconfdir=/etc/httpd/--enable-so--enable-ssl=static--with-ssl=/usr/local/ssl/--enable-mods-shared=all--with-apr=/usr/local/apr/--with-apr-util=/usr/local/apr/
--enable-cgi--enable-suexec
./configure--prefix=/usr/local/apache2--sysconfdir=/etc/httpd/--enable-so--enable-ssl=static--with-ssl=/usr/local/ssl/--enable-mods-shared=all--with-apr=/usr/local/apr/--with-apr-util=/usr/local/apr/
--enable-cgi
make&&makeinstall(4)源码安装mysql-5.6.27-linux-glibc2.5-x86_64
#FATALERROR:pleaseinstallthefollowingPerlmodulesbeforeexecutingscripts/mysql_install_db:Data::Dumper
yum-yinstallperl-Data-Dumper
tarzxvfmysql-5.6.27-linux-glibc2.5-x86_6.tar.gz-C/uar/local/
cd/usr/local
ln-smysql-5.6.27-linux-glibc2.5-x86_64/mysql
cdmysql
#添加mysql用户和群组
groupaddmysql
useradd-r-gmysqlmysql
#修改相关目录和文件属主和所属群组
chown-Rmysql.
chgrp-Rmysql.
或者:chown-Rmysql:mysql.
#将目录属主更改为root,避免mysql用户将目录删除
chown-Rroot.
chown-Rmysqldata
#使用mysql用户权限来初始化数据库
scripts/mysql_install_db--user=mysql
#将mysql添加为服务
cpsupport-files/mysql.server/etc/init.d/mysqld
chkconfig--addmysqld
#将mysql的bin目录加入到PATH环境变量
#在/etc/profile最后面添加
echo"PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
source/etc/profile
#脚本初始化已经添加mysqld脚本,如果没有直接cp/etc/init.d/mysqld
/etc/rc.d/init.d/mysqld
#启动mysql
mkdir-p/var/run/mysqld/
chown-Rmysql:mysql/var/run/mysqld/
#/var/log/mariadb/mariadb.logNosuchfileordirectory
mkdir-p/var/log/mariadb//var/run/mariadb/
touch/var/log/mariadb/mariadb.log
chownroot:mysql/var/log/mariadb/mariadb.log/var/run/mariadb/
chmod-R774/var/log/mariadb/mariadb.log/var/run/mariadb/
/usr/local/mysql/bin/mysqld_safe&
ln-s/var/lib/mysql/mysql.sock/tmp/mysql.sock
#在/etc/f文件socket参数指定为/tmp/mysql.sock
echo"socket=/tmp/mysql.sock">>/etc/f
#修改root密码为love
#mysqladmin-uroot-ppasswordlove--socket=/var/lib/mysql/mysql.sock
mysqladmin-uroot-ppasswordlove
(4)源码安装php-5.6.15
#apxs是在安装php时生成动态连接模块工具,如果不指明路径,apache就无法调用php
#一定要添加--with-apxs2=/usr/local/apache2/bin/apxs
#php安装完成后,可以看到会在httpd.conf文件添加"LoadModulephp5_modulemodules/libphp5.so"
#安装依赖包libxml2-devel
#error:xml2-confignotfound.Pleasecheckyourlibxml2installation
yum-yinstalllibxml2-devel
#libzip:notfound
yum-yinstalllibzip-devel
#动态加载php来完成解析
#./configure--prefix=/usr/local/php--with-config-file-path=/etc--with-mysql=/usr/local/mysql/--with-apxs2=/usr/local/apache2/bin/apxs
./configure--prefix=/usr/local/php--with-config-file-path=/etc--with-mysql=/usr/local/mysql/--with-apxs2=/usr/local/apache2/bin/apxs
--enable-mbstring--with-libzip--enable-zip
make&&makeinstall
cpphp.ini-development/etc/php.ini
#不需要进行手动更改就可以让apache调用php
#php在编译的时候会修改httpd.conf配置文件,添加如下一行
LoadModulephp5_module
modules/libphp5.so
#如果在编译的时候没有指定--with-apxs2=/usr/local/apache2/bin/apxs,则apache无法加载php
(5)lamp连接测试
#设置service方式启动apache
#将启动脚本复制为/etc/init.d/httpd
cp/usr/local/apache2/bin/apachectl/etc/init.d/httpd
#可以这样来停止、启动和重启apache
servicehttpdstop/start/restart
/etc/init.d/httpdstop/start/restart
/usr/local/apache2/bin/apachectlstop/start/restart
#或许是因为兼容性不好,无法使用chkconfig设置开机启动
chkconfig–addhttpd
#但是可以修改/etc/rc.local设置apache开机启动
#在/etc/rc.local添加
/usr/local/apache2/bin/apachectlstart
#修改httpd.conf:
#如果使用yum安装apache,配置文件存放在
/etc/httpd/conf/httpd.conf
#DocumentRoot为
/var/www/html
#如果是使用源码方法安装,配置文件存放在
/usr/local/apache2/conf/httpd.conf
#DocumentRoot为
/usr/local/apache2/htdocs
#在<IfModule></IfModule>添加如下两行,以便apache知道怎样解析php文件
AddTypeapplication/x-httpd-php.php.phtml
AddTypeapplication/x-httpd-php-source.phps
#修改ServerName
ServerName0:80
#在htdocs目录添加文件index.php,内容如下
#读取mysql数据库中的数据表user内容<?php
$con=mysql_connect("localhost","root","love");
$sql="selectuser,passwordfromuser";
$db_select=mysql_select_db("mysql",$con);
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
echo$row["user"]."".$row["password"];
echo"<br/>";
}
mysql_close($con);?>
#从mysql数据库中读取数据表user并显示
#加载cgi解析
#在"LoadModulephp5_module
modules/libphp5.so"后面添加
LoadModulecgi_modulemodules/mod_cgi.so2、安装nagios-4.1.1
cdnagios-4.1.1
useraddnagios-M-s/sbin/nologin
#unzip:commandnotfound
yum-yinstallunzip
./configure--prefix=/usr/local/nagios--with-nagios-group=nagios
makeinstall&&makeall&&makeinstall-init&&makeinstall-commandmode&&makeinstall-config
cpsample-config/httpd.conf/etc/httpd/nagios.conf
#makeinstall-exfoliation,因找不到目录而失败
#cp:target/usr/local/nagios/share/stylesheetsisnotadirectory
mkdir-p/usr/local/nagios/share/stylesheetsis
cp-rfcontrib/exfoliation/stylesheets/*/usr/local/nagios/share/stylesheetsis/
#makeinstall-classicui
#cp:targetusr/local/nagios/share/stylesheetsisnotadirectory
cp-rfhtml/stylesheets/*/usr/local/nagios/share/stylesheets
#安装插件
cdnagios-plugins-2.1.1
./configure--with-gnutls--enable-perl-modules--enable-libtap
--with-openssl--with-gnutls&&make&&makeinstall
#Can'tlocateExtUtils/MakeMaker.pm
yum-yinstallperl-CPAN
cpan-iExtUtils::MakeMaker
#或者
yum-yinstallperl-ExtUtils-MakeMaker.noarch
#添加nagios管理用户
/usr/local/apache2/bin/htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosadmin
#检查配置文件
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
#下面的是因为nagios没有启动,启动nagios即可
#Error:Couldnotreadobjectconfigurationdata!
/usr/local/nagios/bin/nagios-d/usr/local/nagios/etc/nagios.cfg
#打开浏览器访问,IP为实际IP或者域名,如果是域名一定要能够解析
22/nagios
3、监控windows主机
(1)安装NSCP-43-Win32.msi#启用以下选项EnablecommoncheckpluginsEnablensclientserver(check_nt)EnableNRPEserver(check_nrpe)Secure(UserCertificatesforauthentication)EnableNSCAclientAllowhosts:,::1,11,password:123456#配置文件存放于安装目录下的nsclient.ini(2)查看nsclient++监控端口5666netstat-anbv|find"5666"(3)配置nagios#命令行检查,检查系统运行时间#-H:指定主机,-s:指定密码,-p:指定端口,-v:指定查询选项/usr/local/nagios/libexec/check_nt-H22-s123456-p12489-vUPTIME#检查CPU信息#-w:警告比例;-c:紧急比例;-l:过去5分钟平均值,80%为警告,90%为紧急/usr/local/nagios/libexec/check_nt-H22-s123456-p12489-vCPULOAD-w80-c90-l5,80,90#检查硬盘使用率#-w:警告比例;-c:紧急比例;-l:指定盘符/usr/local/nagios/libexec/check_nt-H22-s123456-p12489-vUSEDDISKSPACE-w80-c90-lC#在/usr/local/nagios/etc/command.cfg最后添加definecommand{
command_namecheck_win
command_line$USER1$/check_nt-H$HOSTADDRESS$-p12489-v$ARG1$$ARG2$}#复制/usr/local/nagios/etc/objects/windows.cfg一份win-222.cfg,并修改为#继承模板/usr/local/nagios/etc/objects/template.cfgwindows-server主机监控设置以及generic-service服务监控设置#监控主机IP为22,被监控的服务分别为:系统运行时间、CPU负载、内存使用情况、C盘使用情况以及explorer.exe进程数definehost{
use
windows-server
;Inheritdefaultvaluesfromatemplate
host_name
win-222;Thenamewe'regivingtothishost
alias
MyWindowsServer
;Alongernameassociatedwiththehost
address
22;IPaddressofthehost
}definehostgroup{
hostgroup_name
windows-servers;Thenameofthehostgroup
alias
WindowsServers;Longnameofthegroup
}defineservice{
use
generic-service
host_name
win-222
service_description
NSClient++Version
check_command
check_nt!CLIENTVERSION
}defineservice{
use
generic-service
host_name
win-222
service_description
Uptime
check_command
check_nt!UPTIME
}defineservice{
use
generic-service
host_name
win-222
service_description
CPULoad
check_command
check_nt!CPULOAD!-l5,80,90
}defineservice{
use
generic-service
host_name
win-222
service_description
MemoryUsage
check_command
check_nt!MEMUSE!-w80-c90
}defineservice{
use
generic-service
host_name
win-222
service_description
C:\DriveSpace
check_command
check_nt!USEDDISKSPACE!-lc-w80-c90
}defineservice{
use
generic-service
host_name
win-222
service_description
Explorer
check_command
check_nt!PROCSTATE!-dSHOWALL-lexplorer.exe
}
#效果图示,可以看到已经正常监控到windows各项服务
4、监控linux主机#监控IP为的linux主机,分别监控ping、root分区使用情况、现存用户情况、进程数、实时负载、swap使用情况、ssh和httpd进程definehost{
use
linux-server
;Nameofhosttemplatetouse
;Thishostdefinitionwillinheritallvariablesthataredefined
;in(orinheritedby)thelinux-serverhosttemplatedefinition.
host_name
linux-6
alias
linux-6
address
}definehostgroup{
hostgroup_name
my-linux-servers;Thenameofthehostgroup
alias
MyLinuxServers;Longnameofthegroup
members
linux-6
;Commaseparatedlistofhoststhatbelongtothisgroup
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
PING
check_command
check_ping!100.0,20%!500.0,60%
notifications_enabled
1
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
RootPartition
check_command
check_local_disk!20%!10%!/
notifications_enabled
1
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
CurrentUsers
check_command
check_local_users!20!50
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
TotalProcesses
check_command
check_local_procs!250!400!RSZDT
notifications_enabled
1
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
CurrentLoad
check_command
check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
notifications_enabled
1
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
SwapUsage
check_command
check_local_swap!20!10
notifications_enabled
1
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
SSH
check_command
check_ssh
notifications_enabled
1
}defineservice{
use
local-service
;Nameofservicetemplatetouse
host_name
linux-6
service_description
HTTP
check_command
check_http
notifications_enabled
1
}#在/usr/local/nagios/etc/nagios.cfg添加如下一行,并重新加载或者启动nagioscfg_file=/usr/local/nagios/etc/objects/linux-6.cfg/etc/init.d/nagiosrestart/etc/init.d/nagiosreloadsystemctlrestartnagiossystemctlreloadnagios
5、邮件报警设置5、邮件报警设置
#在/usr/local/nagios/etc/object/contact.cfg下修改为
#定义两个NagiosAdmin邮箱地址,并隶属于admins组
definecontact{
contact_name
nagiosadmin
;Shortnameofuser
use
generic-contact
;Inheritdefaultvaluesfromgeneric-contacttemplate(definedabove)
alias
NagiosAdmin
;Fullnameofuser
nagiosadmin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 江西省赣州市石城县2022年公务员考试《行政职业能力测验》深度预测试题含解析
- 第9章 力与运动-2024学年八年级《物理》下册单元速记清单(苏科版)(解析版)
- 磷酸氧钛钾晶体(KTP)项目可行性报告
- 天然级复盆子酮项目可行性报告
- 弹射救生系统项目综合评估报告
- 三年级数学期中工作总结
- 阀门和龙头项目可行性分析报告
- 一周生产个人工作总结
- 6s推进工作总结
- 21.3 实际问题与一元二次方程 2022-2023学年人教版九年级数学上册
- 生物制药厂危险源识别评价表及重大危险源清单
- 安全生产工作考核评价表
- 高中语文课标测试题及答案(共三套)
- 2021年语文高考真题卷-上海春季卷(含答案解析)
- 农机修理工中级理论知识题库与答案
- 实施黄山旅游国际化战略的思考与建议
- 2022计算机类教学质量国家标准
- 初中英语 沪教牛津版 8B U6-1 Reading Head to head 课件
- 2014北京东城区小学划片区域信息全解
- 2022年NMR常见溶剂峰和水峰
- 积极培育石化化工中小企业实施方案
评论
0/150
提交评论