百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术分析 > 正文

陈俊勇:带你部署Nagios 第一篇 云南省党政机关单位安装部署wpsoffice

liebian365 2024-10-19 08:08 19 浏览 0 评论

你的关注是我发文的动力

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]#

原来的主题

更换后的主题

----------------------------------------------------未完待续------------------------------------------------------

后面还有和多精彩的文章 你的关注是我发文章的动力

相关推荐

看黑客是如何获取你电脑最高权限的,一定要看

在渗透过程中,通过各种方式获取到一枚cmdshell,但是这个shell的权限比较低,无法让我们做我们想要做的一些操作,比如说获取系统密码,获取数据库信息,又或者比如说拿到服务器中的另一个站点的权限,...

是50个常用的Visual Basic代码示例:

以下是50个常用的VisualBasic代码示例:1.声明变量```vb...

电脑系统型号怎么看版本(如何看电脑系统型号)

有时候我们会需要进行查看电脑上安装的windows系统版本及系统版本号,但对于不懂电脑知识的小白来说要怎么查看电脑系统版本信息呢?别着急,有小编在接下来,就将查看电脑系统版本的教程来分享给你们,希望对...

dos命令systeminfo,查看系统启动时间。电脑卡慢,win10怎么了?

最近一段时间,有几个反应电脑卡慢的,都是windows10的系统。询问得知每天电脑有关机,打开任务管理器,内存使用量达到百分之九十多,而程序只打开微信、wps、360浏览器。cmd窗口运行命令syst...

systeminfo命令:全面解析系统信息!

你是否曾想过,仅凭一条简单的命令,就能深入了解计算机的"内心世界"?是不是有点不可思议?那么,让我们一起探寻这个神奇的命令,揭开它背后的奥秘吧!它能提供的信息超乎你的想象,从操作系统到硬件配置,再到驱...

电脑序列号怎么查询?只需两行命令一键查询

当我们的电脑出问题需要保修的时候,需要查询到电脑的型号和序列号才更便于进行下一步的操作,有包装盒的朋友还可以在包装盒上查询,笔记本用户可以在电脑底部标签上查询,没有包装盒和标签破损的用户就无从下手了。...

快速显示系统信息:Systeminfo命令详解

Systeminfo命令是windows系统中显示系统信息的命令,此命令可以显示出计算机的操作系统的详细配置信息,包括操作系统配置、安全信息、产品ID和硬件属性(如RAM、磁盘空间和网卡)。使用...

dos命令systeminfo图文教程,显示操作系统配置信息msinfo32

大家好,我是老盖,首先感谢观看本文,本篇文章做的有视频,视频讲述的比较详细,也可以看我发布的视频。今天我们学习systeminfo命令,该工具显示本地或远程机器(包括服务包级别)的操作系统配置的信息,...

基于uniapp+vue3跨端仿制chatgpt实例uniapp-chatgpt

#夏日生活打卡季#...

原创新作uniapp+vue3+pinia2高仿微信App聊天

前段时间有给大家分享一个flutter3.x桌面端os系统。今天再分享一款最新原创之作uniapp-vue3-wechat聊天实例。uni-vue3-wechat采用...

UniApp开发的设备适配(uniapp服务器配置)

UniApp是一个跨平台开发框架,支持多端应用(如H5、小程序、iOS、Android等)。由于不同设备的屏幕尺寸、分辨率、操作系统等存在差异,设备适配是开发过程中需要重点关注的问题。以下是Uni...

如何用服务器搭建自己的个人网站(自己服务器怎么做网站)

这篇教程主要是告诉大家如何利用TCP和HTTP协议来完成网站的搭建。首先你需要有C/C++语言基础,且有服务器、客户端概念,如果你了解TCP或者HTTP协议的话,那么将会帮助你更快的学会如何搭建个人网...

大话C语言:字符数组(c语言字符数组教学视频)

1字符数组概述C语言中没有字符串这种数据类型,可以通过char的数组来替代。数字0(和字符'\0'等价)结尾的char数组就是一个字符串,字符串是一种特殊的char的数组。...

源码分享:在pdf上加盖电子签章(pdf怎么加电子签章)

在pdf上加盖电子签章,并不是只是加个印章图片,。而是要使用一对密钥中的私钥对文件进行签字。为啥要用私钥呢?很简单,因为公钥是公开的,其他人才可以用公钥为你证明,这个文件是你签的。这就是我们常说的:私...

C语言wcstombs函数详解:宽字符字符串到多字节的「翻译官」

核心定位wcstombs是C语言中用于将宽字符字符串转换为多字节字符串的「翻译官」,它能将宽字符(wchar_t)转换为多字节字符(如UTF-8编码的中文)。就像一位翻译官,它能将一种语言(宽字符...

取消回复欢迎 发表评论: