[comment]: # translation:outdated

[comment]: # ({8182ffcb-ecf9c397})
# 3 通过HTTP监控Apache

[comment]: # ({/8182ffcb-ecf9c397})

[comment]: # ({d75c48d2-10fb7eeb})
## 介绍

本页展示了一种快速而简单的方法，
无需安装任何其他软件即可开始监视 Apache Web 服务器。

[comment]: # ({/d75c48d2-10fb7eeb})

[comment]: # ({36b7cfe4-faa6dcc9})

**本指南适用于谁**

本指南专为Zabbix新用户设计，包含启用Apache基本监控所需的最少步骤集。
如果您正在寻找深度自定义选项或需要更高级的配置，
请参阅Zabbix手册的 [配置](/manual/config) 部分。

[comment]: # ({/36b7cfe4-faa6dcc9})

[comment]: # ({8fc6c74e-3b4f784a})

**先决条件**

在继续本安装指南之前，您必须根据您操作系统对应的说明 [下载并安装](https://www.zabbix.com/download) 
Zabbix server 和 Zabbix 前端。  

[comment]: # ({/8fc6c74e-3b4f784a})

[comment]: # ({370c51ab-f10ccc2e})

## 准备 Apache

1\. 检查您使用的是哪个 Apache 版本：

在基于 RHEL的系统上，运行：

    httpd -v

在 Debian/Ubuntu系统上，运行：

    apache2 -v

2\. 确保在 Apache 实例中启用了 [Status module](https://httpd.apache.org/docs/2.4/mod/mod_status.html) 。

在基于 RHEL 的系统上，运行：

    httpd -M | grep status
    status_module (shared)
    
在 Debian/Ubuntu 系统上，运行：
    
    apache2ctl -M | grep status
    status_module (shared)

如果列表中未看到status_module，
请通过运行以下命令启用该模块：

在基于 RHEL 的系统上，运行：

    LoadModule status_module /usr/lib/apache2/modules/mod_status.so
   
在 Debian/Ubuntu 系统上，运行：

    sudo /usr/sbin/a2enmod status

3\. 编辑Apache配置文件，允许从Zabbix server IP访问状态报告。

在基于 RHEL 的系统：`/etc/httpd/conf.modules.d/status.conf`:

    sudo vi /etc/httpd/conf.modules.d/status.conf

在 Debian/Ubuntu 上： `/etc/apache2/mods-enabled/status.conf`:

    sudo vi /etc/apache2/mods-enabled/status.conf

将以下行添加到文件中 (**替换 198.51.100.255** 为您 Zabbix server 的IP 地址):

* 对于 Apache 2.2:
\
    <Location /server-status>
    SetHandler server-status

    Order Deny,Allow
    Deny from all
    Allow from 198.51.100.255
    </Location>

- 对于 Apache 2.4:
\
    <Location "/server-status">
    SetHandler server-status
    Require ip 198.51.100.255
    </Location>

4\. 重启 Apache

在基于 RHEL 的系统上，运行：

    sudo systemctl restart httpd
   
在 Debian/Ubuntu 上，运行：

    sudo systemctl restart apache2 

5\. 检查， 如果一切配置正确，请运行 (将**198.51.100.255** 替换为您的 Zabbix server IP 地址):

    curl 198.51.100.255/server-status

响应应包含 Apache Web 服务器统计信息。

[comment]: # ({/370c51ab-f10ccc2e})

[comment]: # ({2e98c579-1c8f60ff})

## 配置 Zabbix 进行监控

1\. 登录Zabbix前端。

2\. 在Zabbix Web界面中 [创建主机](/manual/config/hosts/host) 。

此主机将代表您的 Apache 服务器。

3\. 在 *接口* 参数中，添加 *Agent* 类型接口并指定您的 Apache 实例 IP 地址。
**您无需在机器上安装Zabbix agent** ，该接口将仅用于解析 {HOST.CONN} 宏。
这个宏在模板项中用于查找 Apache 实例。 

4\. 在 *模板* 参数中，键入或选择 *Apache by HTTP* 。

![](../../../assets/en/manual/guides/apache_host.png)

5\. 切换到 **宏** 选项卡，然后选择 *继承和主机宏* 模式。 检查宏的值
{$APACHE.STATUS.PORT} 和 {$APACHE.STATUS.SCHEME} 适配您的安装设置。
默认情况下，端口为 80，方案为 http。如果使用不同的端口和/或方案，请更改宏值。

![](../../../assets/en/manual/guides/apache_host_macros.png){width="600"}

[comment]: # ({/2e98c579-1c8f60ff})

[comment]: # ({412d1d55-478d88e2})
## 查看收集的指标

恭喜！此时，Zabbix已经在监视您的Apache Web服务器。

要查看收集的指标，请打开 *监测->主机* 
[菜单部分](/manual/web_interface/frontend_sections/monitoring/hosts) ，然后单击主机旁边的 *仪表盘*。 

![](../../../assets/en/manual/guides/apache_hosts.png){width="600"}

This ac此操作将带您进入主机仪表板，其中包含从 Apache /server-status 页面收集的最重要指标。

![](../../../assets/en/manual/guides/apache_dashboard.png){width="600"}

或者，在 *监测->主机* 中，您可以单击 *最新数据* 以查看列表中所有最新收集的指标。

![](../../../assets/en/manual/guides/apache_latest_data.png){width="600"}

[comment]: # ({/412d1d55-478d88e2})

[comment]: # ({86f39343-59785b62})
## 设置问题告警

Zabbix可以使用多种方法通知您有关基础架构的问题。
本指南提供了发送电子邮件警报的配置步骤。

1\. 转到 *用户设置 -> 配置*，切换到 *媒介* 选项卡并 [添加您的电子邮件](/manual/quickstart/login#adding-user)。

![](../../../assets/en/manual/quickstart/new_media.png){width="600"}

2\. 按照 [接收问题通知](/manual/quickstart/notification)的指南进行操作。

下次，当Zabbix检测到问题时，您应该会通过电子邮件收到告警。

[comment]: # ({/86f39343-59785b62})

[comment]: # ({c6fb646c-21fefdf9})
## 测试配置

要模拟实际问题并接收测试问题告警，请执行以下操作：

1\. 在Zabbix中打开 *Apache server* 主机配置。

2\. 切换到 宏 选项卡，然后选择 *继承和主机宏* 。

3\. 点击{$APACHE.STATUS.PORT}宏旁边的 *更改* 并设置一个不同的端口。 

4\. 点击 更新 保存主机配置。

5\. 几分钟之后， Zabbix 将监测到问题 *Apache service is down*， 因为现在它无法连接到实例。 
它将显示在 监测->问题 部分中。

![](../../../assets/en/manual/guides/apache_problem.png){width="600"}

如果您 [配置](#set-up-problem-alerts)了告警，您还将收到问题通知。

6\. 将宏值复原，以解决问题并继续监视 Apache。

[comment]: # ({/c6fb646c-21fefdf9})

[comment]: # ({8b9c06a8-fe48fbbc})
**另请参阅：**

- [Web 服务器加固](/manual/installation/best_practices/web_server) - 建议设置以提高 Web 服务器安全性。
- [创建监控项](/manual/config/items/item) - 如何开始监控其他指标。
- [HTTP 监控项](/manual/config/items/itemtypes/zabbix_agent) - 如何使用 HTTP agent 监控自定义指标。
- [问题升级](/manual/config/notifications/action/escalations) - 如何创建多步骤警报场景（例如，首先向系统管理员发送消息，然后，如果问题在 45 分钟内未解决，则向数据中心经理发送消息）。

[comment]: # ({/8b9c06a8-fe48fbbc})
