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

Nagios安装与配置详解

[复制链接]

尚未签到

发表于 2019-1-15 09:35:59 | 显示全部楼层 |阅读模式
Nagios安装与配置详解
Nagios是一款用于系统和网络监控的应用程序。它可以在你设定的条件下对主机和服务进行监控,在状态变差和变好的时候给出告警信息 。
搭建Nagios也不是什么难的是,下面我们就来揭开nagios的面纱:
1、 安装前的准备:配置yum源安装phphttpdmysql,创建用户等。
创建用户:
[root@nagios ~]#nagios  # 需要一些基础支持套件才能运行,如apache,gcc,glibc,gd库等。
[root@nagios ~]#useradd -m nagios        #添加一个名为nagios的用户来运行nagios           
[root@nagios ~]#groupadd nagios  #添加nagios用户组,用以通过web页面提交外部控制命令
[root@nagios ~]#usermod -a -G nagios daemon    #将运行apache用户daemon加入nagios组
配置yum并安装httpdphpmysql(测试用):
[root@nagios ~]# mount /dev/cdrom /mnt #挂载光驱到/mnt目录下
[root@nagios ~]# cd /etc/yum.repos.d/
[root@nagios yum.repos.d]# cp rhel-source.repo rhel.repo
[root@nagios yum.repos.d]# vi rhel.repo #添加下列内容
[rhel-local] #yum源的名称
name=yum server from local repo! #yum的描述
baseurl=file:///mnt/ #指定软件存放的位置,即光盘挂载的位置
enabled=1 #1为启用该源,0为禁用
gpgcheck=1 #检查检验码
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@nagios ~]# yum install httpd php php-mysql mysql mysql-server -y # 安装httpd,PHP,mysql等。-y表示直接安装,不提示。
2、 编译安装nagios及其插件:
安装nagios
[root@localhost src]mkdir /etc/httpd/conf/extra
[root@localhost src]# tar zxvf nagios-3.2.0.tar.gz #解压nagios软件
[root@localhost src]# cd nagios-3.2.0
[root@localhost nagios-3.2.0]# ./configure --prefix=/usr/local/nagios/ --with-comman-group=nagios --with-httpd-conf=/etc/httpd/conf/extra/ #指定安装目录及用户、组和http的配置目录
[root@localhost nagios-3.2.0]# make all;make install
[root@localhost nagios-3.2.0]# make install-init;make install-config;make install-commandmode;make install-webconf #初始生成启动脚本、配置文件、命令配置模块和httpd的配置文件
安装nagios-plugins
[root@localhost src]# tar zxvf nagios-plugins-1.4.16.tar.gz #解压nagios-plugins
[root@localhost src]# cd nagios-plugins-1.4.16
[root@localhost nagios-plugins-1.4.16]# pwd
/usr/src/nagios-plugins-1.4.16
[root@localhost nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/ #指定安装目录及用户和组
[root@localhost nagios-plugins-1.4.16]# make;make install
配置httpd
[root@localhost ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin #创建登陆用户名nagiosadmin及密码
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf #添加如下行,让nagios.conf生效
Include conf/extra/nagios.conf
启动httpdnagios服务并验证:
[root@localhost ~]# chkconfig --add nagios #设置nagios及http开机自启动
[root@localhost ~]# chkconfig nagios on
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# service nagios start
[root@localhost ~]# service httpd start
在浏览器中输入如:http://192.168.8.15/nagios/访问nagios,一般情况下能看到英文的nagios监控界面。说明nagios基本能进行工作了。
3、 汉化nagios:
[root@localhost ~]# cd /usr/src
[root@localhost src]# tar jxvf nagios-cn-3.2.3(2).tar.bz2 # 解压nagios-cn
[root@localhost src]# cd nagios-cn-3.2.3
[root@localhost nagios-cn-3.2.3]# ./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/
[root@localhost nagios-cn-3.2.3]# make all;make install
在浏览器中输入如:http://192.168.8.15/nagios/访问nagios,注意ip地址nagios服务器的IP地址,查看效果如图:

4、配置nagios监控远程计算机:需要分别在被监控机器及服务器端(监控端)安装nrpe插件
配置被监控机器(客户端):
安装nagios-plugins
[root@localhost ~]# useradd -s /sbin/nologin nagios #添加nagios用户
[root@localhost ~]# cd /usr/src
[root@localhost src]# tar zxvf nagios-plugins-1.4.16.tar.gz
[root@localhost src]# cd nagios-plugins-1.4.16
[root@localhost nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/ #指定安装目录及运行该软件用户和组
[root@localhost nagios-plugins-1.4.16]#make;make install
安装nrpe
[root@localhost nagios-plugins-1.4.16]# cd ..
[root@localhost src]# tar zxvf nrpe-2.13.tar.gz
[root@localhost src]# cd nrpe-2.13
[root@localhost nrpe-2.13]# ./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/
[root@localhost nrpe-2.13]# make all
[root@localhost nrpe-2.13]# make install-plugin;make install-daemon;make install-daemon-config
[root@localhost nrpe-2.13]# ls /usr/local/nagios/libexec/ #验证安装
check_apt check_ftp check_mailq check_overcr check_tcp
配置、启动、测试NRPE
[root@localhost nrpe-2.13]# cd /usr/local/nagios/
[root@localhost nagios]# vi etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.8.16 #添加服务器端的IP地址
[root@localhost nagios]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d #启动NRPE守护进程
[root@localhost nagios]# netstat -utpln |grep nrpe
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17619/nrpe
[root@localhost nagios]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >>/etc/rc.local #添加nrpe为开机自动启动
[root@localhost nagios]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 #测试
NRPE v2.13 #nrpe测试结果,此结果为nrpe已经正常工作了
定义监控内容:
[root@localhost ~]# vi /usr/local/nagios/etc/nrpe.cfg #定义监控服务器内容
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 #监控CPU的负载
command[check_sda2]=/usr/local/nagios//libexec/check_disk -w 20% -c 10% -p /dev/sda2 #监控磁盘利用率,这里的sda2必须是实际的硬盘分区,可使用fdisk –l查
command[check_swap]=/usr/local/nagios//libexec/check_swap -w 20 -c 10 #监控交换空间
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后面括号中的内容就是定义的变量,变量名可以任意指定,只需和服务器配置文件中的一致即可。
在服务器端安装NRPE和配置Nagios服务:
安装NRPE插件:
[root@localhost src]# tar zxvf nrpe-2.13.tar.gz
[root@localhost src]# cd nrpe-2.13
[root@localhost nrpe-2.13]# ./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/
[root@localhost nrpe-2.13]# make all;make install-plugin #将check_nrpe插件安装到/usr/local/nagios/libexec/目录下
[root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.8.16 #测试
NRPE v2.13 #该结果表示能与客户端通讯
5、配置Nagios服务器支持远程监控:
添加监控主机:
[root@localhost etc]# pwd
/usr/local/nagios/etc
[root@localhost objects]# vi host.cfg #定义要监控的主机
define host{
use linux-server
host_name web
alias web-stlong
address 192.168.8.15
}
define host{
use linux-server
host_name mysql
alias mysql-stlong
address 192.168.8.16
}
define hostgroup{
hostgroup_name sa-servers
alias sa servers
members web,mysql
}
定义要监控的服务:
[root@localhost etc]# pwd
/usr/local/nagios/etc
[root@localhost objects]# vi services.cfg #定义要监控的服务
#############stlong web #####################
define service{
use local-service
host_name web
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name web
service_description SSH
check_command check_ssh
}
define service{
use local-service
host_name web
service_description SSHD
check_command check_tcp!22
}
define service{
use local-service
host_name web
service_description http
check_command check_http
}
##########stlong MySQL##############
define service{
use local-service
host_name mysql
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name mysql
service_description SSH
check_command check_ssh
}
define service{
use local-service
service_description ftp
check_command check_ftp
}
define service{
use local-service
host_name mysql
service_description mysqlport
check_command check_tcp!3306
}
#############nrpe----stlong###########
define service{
use local-service
host_name mysql
service_description users
check_command check_nrpe!check_users
}
define service{
use local-service
host_name mysql
service_description load
check_command check_nrpe!check_load
}
define service{
use local-service
host_name mysql
service_description disk
check_command check_nrpe!check_sda2
}
define service{
use local-service
host_name mysql
service_description swap
check_command check_nrpe!check_swap
}
define servicegroup{
servicegroup_name servergroup
alias serer-group-stlong
members web,PING,web,SSH,web,SSHD,web,http,mysql,users,mysql,load,mysql,disk,mysql,swap
}
添加定义check_nrpe命令:
[root@localhost objects]# vi commands.cfg #定义check_nrpe监控命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
添加host.cfgervices.cfgnagios.cfg
[root@localhost etc]# pwd
/usr/local/nagios/etc
[root@localhost etc]#vi nagios.cfg
cfg_file=/usr/local/nagios//etc/objects/host.cfg
cfg_file=/usr/local/nagios//etc/objects/services.cfg
修改接受报警邮箱:
[root@localhost objects]# vi contacts.cfg
email shchfa@163.com ;

运维网声明 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.iyunv.com/thread-663443-1-1.html 上篇帖子: nagios 远程Mysql 监控 PHP图表 下篇帖子: 【nagios 二】nagios配置篇
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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