你的关注是我发文的动力
Nagios所需要的软件
LAP环境,不需要mysql
nagios-3.5.1.tar.gz #Nagios核心文件,Nagios服务文件,不建议用最新,很多插件没做好
nagios-plugins-2.1.1.tar.gz
#Nagios插件,用于存放脚本和命令
NSCP-0.5.0
#也就是Nsclient++,用来监控Windows,分为64位、32位版本
nrpe-2.15.tar.gz
#代理服务,用于监控非Nagios服务器的服务器本地私有信息代理
vautour_style.zip
#主题包
部署Nagios监控服务器
部署之前,需要做好最基本的环境,包括LAP环境的构建(这里直接使用yum方式安装即可,做zabbix的时候需要使用我们编译的LNMP环境来做)
解决依赖和安装LAP环境
安装epel源:
[root@juny-24 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
获取http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
警告:/var/tmp/rpm-tmp.8qsESe: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:epel-release-7-10 ################################# [100%]
[root@juny-24 ~]# yum clean all && yum list
安装lap环境
[root@juny-24 ~]# yum install -y gcc glibc glibc-common php gd gd-devel libpng libmng libjpeg zlib
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
软件包 gcc-4.8.5-16.el7.x86_64 已安装并且是最新版本
软件包 glibc-2.17-196.el7.x86_64 已安装并且是最新版本
软件包 glibc-common-2.17-196.el7.x86_64 已安装并且是最新版本
软件包 gd-2.0.35-26.el7.x86_64 已安装并且是最新版本
软件包 2:libpng-1.5.13-7.el7_2.x86_64 已安装并且是最新版本
软件包 libjpeg-turbo-1.2.90-5.el7.x86_64 已安装并且是最新版本
软件包 zlib-1.2.7-17.el7.x86_64 已安装并且是最新版本
正在解决依赖关系
--------------------------------------------中间省略了一些提示信息-------------------------------------------------------------
作为依赖被安装:
expat-devel.x86_64 0:2.1.0-10.el7_3
fontconfig-devel.x86_64 0:2.10.95-11.el7
freetype-devel.x86_64 0:2.4.11-15.el7
httpd.x86_64 0:2.4.6-67.el7.centos.5
httpd-tools.x86_64 0:2.4.6-67.el7.centos.5
libX11-devel.x86_64 0:1.6.5-1.el7
libXau-devel.x86_64 0:1.0.8-2.1.el7
libXpm-devel.x86_64 0:3.5.12-1.el7
libjpeg-turbo-devel.x86_64 0:1.2.90-5.el7
libpng-devel.x86_64 2:1.5.13-7.el7_2
libxcb-devel.x86_64 0:1.12-1.el7
libzip.x86_64 0:0.10.1-8.el7
mailcap.noarch 0:2.1.41-2.el7
php-cli.x86_64 0:5.4.16-42.el7
php-common.x86_64 0:5.4.16-42.el7
xorg-x11-proto-devel.noarch 0:7.7-20.el7
zlib-devel.x86_64 0:1.2.7-17.el7
完毕!
[root@juny-24 ~]# yum install -y httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
软件包 httpd-2.4.6-67.el7.centos.5.x86_64 已安装并且是最新版本
无须任何处理
[root@juny-24 ~]# systemctl start httpd
创建Nagios用户
[root@juny-24 ~]# systemctl start httpd #建立Nagios用户,这里不能使用nologin的shell,nagios会用到
[root@juny-24 ~]# useradd nagios #建立一个组
[root@juny-24 ~]# groupadd nagcmd
#将Nagios和apache加入该组
[root@juny-24 ~]# usermod -G nagcmd nagios
[root@juny-24 ~]# usermod -G nagcmd apache
新建一个Nagios目录然后在这目录下去
[root@juny-24 ~]# mkdir Nagios
[root@juny-24 ~]# cd Nagios/
上传需要用到的包
[root@juny-24 Nagios]# ls
nagios-3.5.1.tar.gz nrpe-2.15.tar.gz
nagios-plugins-2.1.1.tar.gz vautour_style.zip
解压包
[root@juny-24 Nagios]# tar xvf nagios-3.5.1.tar.gz -C /usr/local/src/
到解压包的目录下并开始编译
[root@juny-24 Nagios]# cd /usr/local/src/nagios/
[root@juny-24 nagios]# ./configure --with-command-group=nagcmd
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios #运行用户
Command user/group: nagios,nagcmd #运行用户组
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/Nagios #默认安装到了/usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d #Apache的conf.d配置文件目录
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/ #登陆地址
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Review the options above for accuracy. If they look okay,
type'make all' to compile the main program and CGIs. #出现这个提示 说明编译没有问题
[root@juny-24 nagios]# make all
*** Compile finished ***
If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
#下面已经提示安装步骤,我们依次安装就好
make install
- This installs the main program, CGIs, and HTML files
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
make install-webconf
- This installs the Apache config file for the Nagios
web interface
make install-exfoliation #主题相关的 可以不用安装
- This installs the Exfoliation theme for the Nagios
web interface
make install-classicui #主题相关的 可以不用安装
- This installs the classic theme for the Nagios
web interface
*** Support Notes *******************************************
If you have questions about configuring or running Nagios,
please make sure that you:
- Look at the sample config files
- Read the documentation on the Nagios Library at:
http://library.nagios.com
before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you. This might include:
- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:
http://support.nagios.com
*************************************************************
Enjoy.
我选择一次性给他把所有需要安装的都安装完
[root@juny-24 nagios]# make install && make install-init && make install-commandmode && make install-config && make install-webconf
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
*** Nagios/Apache conf file installed ***
出现这个说明安装成功了
安装的时候会生成启动脚本 我现在看看启动脚本
[root@juny-24 nagios]# ls /usr/local/nagios/etc/
cgi.cfg nagios.cfg objects resource.cfg
提示:包括安装plugin等软件后,配置文件也会放到这个目录下来
resource.cfg 定义很多资源变量的调用
在make install-webconf的时候,已经把已经把web-conf的配置文件放入了/etc/httpd/conf.d/下面
[root@juny-24 nagios]# ls /etc/httpd/conf.d/nagios.conf
/etc/httpd/conf.d/nagios.conf #这里配置了一个别名,直接引用/usr/local/nagios/share目录
[root@juny-24 nagios]# vim /etc/httpd/conf.d/nagios.conf
图中 1是别名 2是物理路径
下面是nagios的主目录
[root@juny-24 nagios]# ll /usr/local/nagios/
总用量 0
drwxrwxr-x 2 nagios nagios 38 10月 20 09:21 bin # Nagios执行程序所在目录
drwxrwxr-x 3 nagios nagios 74 10月 20 09:21 etc #nagios配置文件所在目录,初始安装只有几个*.cfg文件
drwxrwxr-x 2 nagios nagios 6 10月 20 09:21 libexec #监控所用命令,需要安装了nagios-plugins插件了才会有,检测命令,不装是空的
drwxrwxr-x 2 nagios nagios 311 10月 20 09:21 sbin #Nagios的Cgi文件所在目录,外部命令所需要的文件存放目录
drwxrwxr-x 10 nagios nagios 257 10月 20 09:21 share #Nagios前端页面
drwxrwxr-x 5 nagios nagios 45 10月 20 09:21 var #日志文件,pid文件等
[root@juny-24 nagios]# vim /usr/local/nagios/etc/nagios.cfg
log_file=/var/log/nagios/nagios.log #日志位置
cfg_file=/etc/nagios/objects/commands.cfg #这个文件定义了很多命令
cfg_file=/etc/nagios/objects/contacts.cfg #定义联系人,怎么联系
cfg_file=/etc/nagios/objects/timeperiods.cfg #定义了时间段
cfg_file=/etc/nagios/objects/templates.cfg #模板(联系人,主机,时间)
cfg_file=/etc/nagios/objects/localhost.cfg #监控本机相关配置文件
#cfg_file=/etc/nagios/objects/windows.cfg #windows,默认不监控
#cfg_file=/etc/nagios/objects/switch.cfg #交换机路由器监控,默认不监控
#cfg_file=/etc/nagios/objects/printer.cfg #打印机监控,默认不监控
#cfg_dir=/etc/nagios/servers #定义了服务合集(多个使用)
#cfg_dir=/etc/nagios/printers #定义了打印机合集(多个使用)
#cfg_dir=/etc/nagios/switches #定义了交换合集(多个使用)
#cfg_dir=/etc/nagios/routers #定义了路由合集(多个使用)
resource_file=/etc/nagios/private/resource.cfg 资源变量配置文件,包括$USER1$变量(一个路径)等
status_update_interval=10 #状态更新时间,单位s
log_rotation_method=d #日志滚动,默认天
service_check_timeout=60 #服务检查超时时间
host_check_timeout=30 #主机检查超时时间
event_handler_timeout=30
notification_timeout=30
ocsp_timeout=5
perfdata_timeout=5
[root@juny-24 nagios]# vim /usr/local/nagios/etc/cgi.cfg
//此配置文件比nagios.cfg优先级高
main_config_file= /usr/local/nagios/etc/nagios.cfg #主配置文件
physical_html_path= /usr/local/nagios/share #物理路径
url_html_path=/nagios #在URL后面加上/nagios才能访问
use_authentication=1 #使用认证
use_ssl_authentication=0 #不使用ssl
authorized_for_system_information=nagiosadmin #认证用户
测试
[root@juny-24 nagios]# systemctl restart httpd
需要用户名和密码,查看vim /etc/httpd/conf.d/nagios.conf配置文件
[root@juny-24 Nagios]# vim /etc/httpd/conf.d/nagios.conf
框出来的是定义访问nagios的认证用户名和密码的相关配置 :从AuthName 开始
在Directory字段里面有Auth这三个字段,那么就可以使用htpasswd来生成用户名和密码
[root@juny-24 Nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminNew password: 123456
Re-type new password: 123456
Adding password for user nagiosadmin
# -c表示创建,二次添加用户,不能使用-c参数
重启httpd
[root@juny-24 Nagios]# systemctl restart httpd
[root@juny-24 Nagios]#
#再次测试(我创建用户名是nagiosadmin,密码123456)
#nagios 默认使用nagiosadmin来管理,如果使用其他用户名,对应的配置文件也要修改
登录以后是这样的
检查配置文件
在nagios的目录下,bin目录下有一个nagios命令,这个命令可以帮助我们对配置文件的检查工作以及指定相关配置文件
[root@juny-24 Nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-v=--verify-config 验证配置文件是否有误,着重看到下图亮点就没问题
Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL
--------------------------------------------中间省略了一些提示信息-------------------------------------------------------------
Total Warnings: 0 #警告的个数
Total Errors: 0 #错误的个数
Things look okay - No serious problems were detected during the pre-flight check
指定配置文件,以守护进程方式启动
[root@juny-24 Nagios]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
但是现在还没有做任何深入配置,所以现在只是可以登录而已!
Nagios监控本服务器
配置监控之前,我们需要做一系列的准备工作
(指定主配置文件需要加载的配置文件—定义主机—定义服务 –定义监控命令—检查配置文件—启动Nagios)
1: 原理 数据收集,数据呈现
2: Nagios主程序,插件包,nrpe
3:解决依赖(gd-devel)
4:LAP
5:创建Nagios 运行用户和组,加入我们的运行组
6:主程序安装,./configure –with-command-group=nagcmd (make all ,后面所有的的步骤)
7: htpasswd 创建 web认证用户 并测试登陆
8:安装我们的Nagios-plugins插件
监控本地NFS状态
先安装yum -y install nfs-utils
[root@juny-24 Nagios]# yum install nfs-utils -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
软件包 1:nfs-utils-1.3.0-0.48.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@juny-24 Nagios]#
备份配置文件
[root@juny-24 Nagios]# cd /usr/local/nagios/etc/objects/
[root@juny-24 objects]# cp localhost.cfg localhost.cfg.bak
在配置文件写入
[root@juny-24 objects]# vim localhost.cfg
#在使用check命令之前,要确保下/usr/local/nagios/libexec/ 目录下有没有你需要的check命令,如果有,直接调用,如果没有,检测端口来代替,检测格式: check_tcp!端口号
创建一个共享目录
[root@juny-24 objects]# vim /etc/exports
重启共享目录
[root@juny-24 objects]# systemctl restart nfs
检测NFS目前是否正常
[root@juny-24 objects]# showmount -e 192.168.1.24
Export list for 192.168.1.24:
/tmp *
检测localhost是否正常启用
[root@juny-24 objects]# grep cfg_file /usr/local/nagios/etc/nagios.cfg
#localhost默认已经启用了
检测配置文件是否有误
[root@juny-24 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL
--------------------------------------------中间省略了一些提示信息-------------------------------------------------------------
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
[root@juny-24 objects]#
重启nagios服务
[root@juny-24 objects]# /etc/init.d/nagios restart
Restarting nagios (via systemctl): [ 确定 ]
[root@juny-24 objects]#
测试网页
停止nfs再次测试
[root@juny-24 objects]# systemctl stop nfs
这里注意,一般没回立马又显示出来状态,需要一段时间,最好最快的方法就是手动强制刷新,否则你需要等待,强制刷新,点击NFS后有一个Re-schedule the next check of this service,强制刷新
修改Nagios默认的主题:把主题包解压到对应的目录下
[root@juny-24 objects]# cd /root/Nagios/
[root@juny-24 Nagios]# unzip vautour_style.zip -d /usr/local/nagios/share/
Archive: vautour_style.zip
replace /usr/local/nagios/share/images/ack.gif? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
#选择A全部覆盖
重启服务
[root@juny-24 Nagios]# /etc/init.d/nagios restart
Restarting nagios (via systemctl): [ 确定 ]
[root@juny-24 Nagios]#
原来的主题
更换后的主题
----------------------------------------------------未完待续------------------------------------------------------
后面还有和多精彩的文章 你的关注是我发文章的动力
本文暂时没有评论,来添加一个吧(●'◡'●)