频道栏目
首页 > 资讯 > 虚拟机 > 正文

在Centos7 上安装 Nagios

17-12-28        来源:[db:作者]  
收藏   我要投稿

简介

Nagios 是一款自动化运维工具,可以协助运维人员监控服务器的运行状况,并且拥有报警功能。本文将介绍其安装方法,详细的配置将在日后的文章中逐步讨论。

根据本文可以完成 Nagios 的基础安装:

Nagios 核心及插件将安装在/usr/local/nagios Nagios 核心会配置好监控当前服务器的一些基本信息 可以通过网页访问 Nagios 的 web 界面 http://ip/nagios/

准备工作

本文 Nagios 的安装将从官网获取最新的源码包进行编译,因此需要服务器拥有编译环境,同时 Nagios 的 Web界面需要有 Web 服务器和 PHP 运行环境。本文 Web 服务器使用 Apache,用户也可以自行选择使用其他 Web 服务器。

yum -y install httpd php
yum -y install httpd-devel gcc glibc glibc-common gd gd-devel perl-devel perl-CPAN fcgi perl-FCGI perl-FCGI-ProcManager unzip

安装步骤

创建系统用户

创建 nagios 用户并设置密码

/usr/sbin/useradd -m nagios
passwd nagios

创建 nagcmd 用户组,将 nagios 和 apache(web 服务器的运行用户) 用户添加至该组

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache

下载 Nagios 及其插件

可以前往获取最新的软件包,这里以 Nagios 核心 4.2.1,以及插件 2.1.2 为例:

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Nagios 核心的编译与安装

解压源码包

tar -zxvf nagios-4.2.1.tar.gz
cd nagios-4.2.1

编译配置信息

./configure --with-command-group=nagcmd

编译

make all

安装 Nagios,并初始化脚本及基础配置文件

make install
make install-init
make install-config
make install-commandmode

此时先不用启动 Nagios,安装步骤尚未完成

自定义配置信息

配置文件在目录 /usr/local/nagios/etc 下,通过这些基础配置信息可以直接启动 Nagios,现在唯一需要更改的是联系人信息,可以编辑 /usr/local/nagios/etc/objects/contacts.cfg ,将联系人邮件地址换成你自己的。

vim  /usr/local/nagios/etc/objects/contacts.cfg

配置 web 服务器

创建 Apache 的配置文件,配置文件在目录 /etc/httpd/conf.d/

[root@localhost ~]# cd nagios-4.2.1/
[root@localhost nagios-4.2.1]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***

为 Nagios 的 Web 界面创建 nagiosadmin 用户,并设置密码。

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

启动 Apache

systemctl start httpd

编译并安装 Nagios 插件包

Nagios 实际的监控脚本都是通过插件实现的,本文中的插件包是官方提供插件包(大约50个用于监控的插件),更多的插件可以去社区下载(https://exchange.nagios.org/),当然也可以自己编写插件。

解压插件包

tar -zxvf nagios-plugins-2.1.2.tar.gz
cd nagios-plugins-2.1.2

编译并安装

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

启动 Nagios 核心

将 Nagios 核心加入自动启动列表

chkconfig --add nagios
chkconfig nagios on

检查 Nagios 基础配置文件(在之后修改过配置文件后,都可以用下边的方式进行检查)

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

如果没有错误,就可以直接启动 Nagios

systemctl start nagios

SELinux 设置

Centos 系统默认 SELinux 是 Enforcing 模式,这会导致访问 Nagios CGIs 时出现 Internal Server Error 的错误。为避免这个错误可以直接关闭 SELinux 或者将其设置为 Permissive 模式。SELinux配置文件在/etc/selinux/config。注意,修改 SELinux 配置后需要重新启动操作系统。

如果不想关闭 SELinux 或者将其设置为 Permissive ,即在 enforcing/targeted 模式下可以使用如下命令进行设置

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

登录 Web 界面查看

通过 nagiosadmin 用户及刚才设置的密码登录。

点击左侧目录中的 Service,可以查看当前监控的服务。

其他配置

至此,Nagios 的基础安装就结束了。这里还要补充说明的一下,服务器的防火墙需要允许 apache 80 端口的访问,可以通过如下命令设置防火墙,允许 80 端口的访问。

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

目前,Nagios 还无法发送邮件进行报警,还没有配置用于发送邮件的程序,这部分将不在本文中进行讨论,在后续的文章中会逐步讲解。

相关TAG标签
上一篇:Linux中的Ext2文件系统详解
下一篇:CentOS 6.5安装Python2.7.14教程
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站