老谢博客

  • 首页
  • WordPress
  • 网络技术
  • 乱七八糟
  • 运维技术
  • 给我留言
  • 关于老谢

Nagios安装与配置

分类:运维技术日期:2013-10-27 - 16:05:19作者:老谢

本篇文章使用MarkDown写作!

公司近期需要搭建一个监控平台,主要目的是实现服务器服务或负载异常的及时报警功能,经过选择最终决定使用Nagios实现

安装Nagios Core

yum -y install gcc glibc glibc-common gd gd-devel php openssl-devel httpd
useradd -m nagios     #添加一个名为nagios的用户来运行nagios 
usermod -a -G nagios apache    #将运行apache用户apache加入nagios组
wget http://ssh.xj123.info/monitor/nagios-3.5.0.tar.gz
tar -zxf nagios-3.5.0.tar.gz
mkdir /etc/httpd/conf/extra  //用来存放关于nagios的http配置文件
cd nagios
./configure --prefix=/usr/local/nagios/ --with-comman-group=nagios --with-httpd-conf=/etc/httpd/conf/extra/ //指定安装目录及用户、组和http的配置目录
make all&&make install
make install-init;make install-config;make install-commandmode;make install-webconf      //初始生成启动脚本、配置文件、命令配置模块和httpd的配置文件

yum -y install gcc glibc glibc-common gd gd-devel php openssl-devel httpd useradd -m nagios #添加一个名为nagios的用户来运行nagios usermod -a -G nagios apache #将运行apache用户apache加入nagios组 wget http://ssh.xj123.info/monitor/nagios-3.5.0.tar.gz tar -zxf nagios-3.5.0.tar.gz mkdir /etc/httpd/conf/extra //用来存放关于nagios的http配置文件 cd nagios ./configure --prefix=/usr/local/nagios/ --with-comman-group=nagios --with-httpd-conf=/etc/httpd/conf/extra/ //指定安装目录及用户、组和http的配置目录 make all&&make install make install-init;make install-config;make install-commandmode;make install-webconf //初始生成启动脚本、配置文件、命令配置模块和httpd的配置文件

安装nagios plugins

wget http://ssh.xj123.info/monitor/nagios-plugins-1.5.tar.gz
tar -zxf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/   //指定安装目录及用户和组
make all&&make install

wget http://ssh.xj123.info/monitor/nagios-plugins-1.5.tar.gz tar -zxf nagios-plugins-1.5.tar.gz cd nagios-plugins-1.5 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/ //指定安装目录及用户和组 make all&&make install

配置Apache

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin   //创建登陆用户名nagiosadmin及密码,为web登陆时的用户名和密码 
vim /etc/httpd/conf/httpd.conf #添加如下行,让nagios.conf生效
 
Include conf/extra/nagios.conf

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin //创建登陆用户名nagiosadmin及密码,为web登陆时的用户名和密码 vim /etc/httpd/conf/httpd.conf #添加如下行,让nagios.conf生效 Include conf/extra/nagios.conf

启动各项服务

chkconfig --add nagios
chkconfig nagios on
chkconfig httpd on
service nagios start
service httpd start

chkconfig --add nagios chkconfig nagios on chkconfig httpd on service nagios start service httpd start

安装NRPE

客户端安装nagios插件

useradd -s /sbin/nologin nagios //添加nagios用户
cd /usr/local/src
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/   //指定安装目录及运行该软件用户和组
make&&make install

useradd -s /sbin/nologin nagios //添加nagios用户 cd /usr/local/src tar zxvf nagios-plugins-1.4.16.tar.gz cd nagios-plugins-1.4.16 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/ //指定安装目录及运行该软件用户和组 make&&make install

客户端安装nrpe

wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
tar -zxf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/
make all
make install-plugin;make install-daemon;make install-daemon-config
ls /usr/local/nagios/libexec/ //验证安装

wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz tar -zxf nrpe-2.14.tar.gz cd nrpe-2.14 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios/ make all make install-plugin;make install-daemon;make install-daemon-config ls /usr/local/nagios/libexec/ //验证安装

客户端配置、启动、测试NRPE

cd /usr/local/nagios/
vim etc/nrpe.cfg
 
#找到allowed_hosts添加服务器端ip:allowed_hosts=127.0.0.1,23.监控服务器ip
 
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d  //启动NRPE守护进程
netstat -utpln |grep nrpe        //查看nrpe进程是否已正常启动
 
    tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17619/nrpe
 
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >>/etc/rc.local     //添加nrpe为开机自动启动 
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 
    NRPE v2.14    //nrpe测试结果,此结果为nrpe已经正常工作了

cd /usr/local/nagios/ vim etc/nrpe.cfg #找到allowed_hosts添加服务器端ip:allowed_hosts=127.0.0.1,23.监控服务器ip /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d //启动NRPE守护进程 netstat -utpln |grep nrpe //查看nrpe进程是否已正常启动 tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17619/nrpe echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >>/etc/rc.local //添加nrpe为开机自动启动 /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 NRPE v2.14 //nrpe测试结果,此结果为nrpe已经正常工作了

自定义监控内容

vim /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后面括号中的内容就是定义的变量,变量名可以任意指定,只需和服务器配置文件中的一致即可

vim /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插件

wget http://ssh.xj123.info/monitor/nrpe-2.14.tar.gz
tar -zxf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/
make all;make install-plugin ; make install-daemon;make install-daemon-config   //将check_nrpe插件安装到/usr/local/nagios/libexec/目录下
/usr/local/nagios/libexec/check_nrpe -H 客户端ip
 
    NRPE v2.14 //该结果表示能与客户端通讯

wget http://ssh.xj123.info/monitor/nrpe-2.14.tar.gz tar -zxf nrpe-2.14.tar.gz cd nrpe-2.14 ./configure --with-nagios-user=nagios -with-nagios-group=nagios --prefix=/usr/local/nagios/ make all;make install-plugin ; make install-daemon;make install-daemon-config //将check_nrpe插件安装到/usr/local/nagios/libexec/目录下 /usr/local/nagios/libexec/check_nrpe -H 客户端ip NRPE v2.14 //该结果表示能与客户端通讯

配置Nagios服务器支持远程监控

添加监控主机

cd /usr/local/nagios/etc/objects
vim host.cfg
 
    define host{
        use linux-server
        host_name slaves
        address 192.168.8.15
    }

cd /usr/local/nagios/etc/objects vim host.cfg define host{ use linux-server host_name slaves address 192.168.8.15 }

定义要监控的服务

# vim services.cfg #定义要监控的服务
    define service{
        use local-service
        host_name slaves
        service_description http
        check_command check_http
    }

# vim services.cfg #定义要监控的服务 define service{ use local-service host_name slaves service_description http check_command check_http }

添加定义check_nrpe命令

vim commands.cfg #定义check_nrpe监控命令
    define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
    }

vim commands.cfg #定义check_nrpe监控命令 define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }

添加host.cfg及ervices.cfg到nagios.cfg

cd /usr/local/nagios/etc
vim nagios.cfg
    cfg_file=/usr/local/nagios//etc/objects/host.cfg
    cfg_file=/usr/local/nagios//etc/objects/services.cfg

cd /usr/local/nagios/etc vim nagios.cfg cfg_file=/usr/local/nagios//etc/objects/host.cfg cfg_file=/usr/local/nagios//etc/objects/services.cfg

修改接受报警邮箱

vim contacts.cfg
    email test@test.com ;     #请修改为自己的邮箱地址

vim contacts.cfg email test@test.com ; #请修改为自己的邮箱地址

测试及启动Nagios服务

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检测配置文件是否正确
 
    Total Warnings: 0
    Total Errors: 0 #结果表示配置无错误
 
service nagios restart #重启Nagios服务

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检测配置文件是否正确 Total Warnings: 0 Total Errors: 0 #结果表示配置无错误 service nagios restart #重启Nagios服务

主要参考(感谢以下所有文章的作者):

http://loosky.net/2758.html
http://night85.blog.51cto.com/231209/271546
http://blog.csdn.net/xiangliangyu/article/details/7758739

原文地址 : https://www.xj123.info/4171.html

本站遵循 : 署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5)

版权声明 : 原创文章转载时,请务必以超链接形式标明文章原始出处

Tags: linux , nagios
  • 上一篇:入手极路由
  • 下一篇:Nagios图形外挂pnp4nagios无法绘图报错
0条评论

暂时没有评论!

发表评论 点击取消评论.

*必填

*必填

  • 文章归档
  • 子网计算
  • 我的共享
  • 锻炼计划
  • 给我留言
  • 关于老谢
2025 年 5 月
一 二 三 四 五 六 日
 1234
567891011
12131415161718
19202122232425
262728293031  
« 4 月    

最新文章

  • 认知,是否是一座大山?当架构决策变成配置清单比价
  • 重装博客服务器环境
  • 特斯拉24款标续 Model Y 2万公里使用体验
  • 接盘的傻子
  • 小牛us电瓶指示灯闪三次不上电
  • 一次还不错的小米售后体验
  • 装台1600元办公主机
  • 2021好久没更新博客
  • Zabbix监控oxidized备份状态
  • Zabbix 5.0 LTS版本MySQL表分区及编译安装随记

最新评论

  • 老陳网志:有点高端,像我们整点nas玩玩就够...
  • springwood:自从 CentOS 不维护之后,我换 U...
  • 大D:难都搞下来了,那就更得YM了
  • 大D:只能是YM了,谢总牛啊
  • 灰常记忆:经济不好 今年我也换了机器 一...
  • 大峰:这是海外服务器嘛?速度挺快的。
  • 大D:只能单走一个6了哈哈哈
  • zwwooooo:买特斯拉和买iPhone的人群其实相似...
  • 平安家属子痕:一直坚持油车,看你写的心里有...
  • 秦大叔:室内每年能开2万公里电车确实划算 ...

日志存档

  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2024 年 9 月
  • 2024 年 5 月
  • 2024 年 1 月
  • 2023 年 4 月
  • 2021 年 10 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2020 年 11 月
  • 2020 年 9 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 10 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 3 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 1 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月
  • 2017 年 2 月
  • 2017 年 1 月
  • 2016 年 12 月
  • 2016 年 11 月
  • 2016 年 10 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 4 月
  • 2016 年 2 月
  • 2016 年 1 月
  • 2015 年 12 月
  • 2015 年 10 月
  • 2015 年 9 月
  • 2015 年 7 月
  • 2015 年 5 月
  • 2015 年 4 月
  • 2015 年 3 月
  • 2015 年 2 月
  • 2015 年 1 月
  • 2014 年 12 月
  • 2014 年 10 月
  • 2014 年 9 月
  • 2014 年 8 月
  • 2014 年 7 月
  • 2014 年 6 月
  • 2014 年 5 月
  • 2014 年 4 月
  • 2014 年 3 月
  • 2014 年 2 月
  • 2014 年 1 月
  • 2013 年 12 月
  • 2013 年 11 月
  • 2013 年 10 月
  • 2013 年 9 月
  • 2013 年 8 月
  • 2013 年 7 月
  • 2013 年 6 月
  • 2013 年 5 月
  • 2013 年 4 月
  • 2013 年 3 月
  • 2013 年 2 月
  • 2013 年 1 月
  • 2012 年 12 月
  • 2012 年 11 月
  • 2012 年 9 月
  • 2012 年 8 月
  • 2012 年 7 月
  • 2012 年 6 月
  • 2012 年 5 月
  • 2012 年 4 月
  • 2012 年 3 月
  • 2012 年 2 月
  • 2012 年 1 月
  • 2011 年 12 月
  • 2011 年 11 月
  • 2011 年 10 月
  • 2011 年 9 月
  • 2011 年 8 月
  • 2011 年 7 月
  • 2011 年 6 月
  • 2011 年 5 月
  • 2011 年 4 月
  • 2011 年 3 月
  • 2011 年 2 月
  • 2011 年 1 月
  • 2010 年 12 月
  • 2010 年 11 月
  • 2010 年 10 月
  • 2010 年 9 月
  • 2010 年 8 月
  • 2010 年 7 月

W3C

  • XHTML 1.0 Transitional
  • CSS level 3
  • Google+
Copyright © 2010-2025 老谢博客 All rights reserved.
Gzipped 76.5% | Optimized loading 45 queries in 0.492 seconds | Memory 39.28 MB | 尼玛的备案
Powered by WordPress. | Hosted By LAOXUEHOST | Theme by WordPress主题巴士 | 站点地图 | SiteMap | uptime查询