httpd开启status模块_使用mod_status模块监控apache的状态(Ubuntu)

Apache的mod_status模块提供了一个显示web服务器状态的web页面,包括工作进程数量、活动连接等。

mod_status的输出一般被其他监控服务器状态的工具使用。这里,我们直接用它来显示一个统计状态页面,用这个页面可以方便的定位问题。

打开mod_status

Apache安装之后默认是开启mod_status模块的,但是,我们最好确认一下,使用如下命令:

ls /etc/apache2/mods-enabled/

上面列出的是打开的模块,看看有没有框起来的两个文件,如果没有,说明没有打开mod_status模块,使用下面命令打开:

sudo a2enmod status

配置server-status

在如果你没有添加过virtual host到apache default配置,编辑status.conf:

vim /etc/apache2/mods-enabled/status.conf

修改如下:

SetHandler server-status

Require local

Require ip 27.189.138.218

ip改为允许访问status统计页面的ip地址。当然你可以设置为不限制IP,任何人可以查看,为了系统安全不建议这么做。

如果你添加了多个virtual host,需要在在每个VirtualHost *:80块中添加和上面一样的代码:

SetHandler server-status

Require local

Require ip 27.189.138.218

重启apache服务:

sudo service apache2 restart

在浏览器输入:http://your_domain/server-status:

Rewrite模块

我使用的wordpress,开启了固定链接(开启rewirte模块)。默认情况下,它会把http://your_domain/server-status重定向,你会得到一个wordpress的404页面。修正方法:

进入网址根目录,.htaccess内容如下:

# BEGIN WordPress

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

# END WordPress

添加两行,修改之后如下:

# BEGIN WordPress

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteRule ^server-status$ - [L]

RewriteCond %{REQUEST_URI} !^/mod_pagespeed_[a-z_]+$

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

# END WordPress

### Apache Exporter 介绍 Apache Exporter 是一种专门设计用于监控 Apache HTTP Server 的 Prometheus Exporter 工具。它通过解析 Apache 的 `mod_status` 页面或将其他指标暴露给 Prometheus 来实现对 Apache Web 服务器性能和健康状况的全面监控。 以下是关于如何安装、配置以及使用 Apache Exporter 的详细介绍: --- #### 安装 Apache Exporter 通常情况下,Apache Exporter 可以从官方 GitHub 存储库获取最新版本。如果需要手动构建或者下载二进制文件,则可以通过以下方式完成操作[^1]: ```bash # 创建工作目录 mkdir /exporters && cd /exporters # 下载最新的 Apache Exporter 二进制文件 (假设当前稳定版为 v0.9.0) wget https://github.com/Lusitaniae/apache_exporter/releases/download/v0.9.0/apache_exporter-v0.9.0.linux-amd64.tar.gz # 解压缩文件 tar -zxvf apache_exporter-v0.9.0.linux-amd64.tar.gz # 移动解压后的文件夹至目标路径 mv apache_exporter-v0.9.0.linux-amd64 apache_exporter ``` 上述脚本展示了标准流程中的关键步骤,具体版本号可能因时间而异,请访问 [GitHub Releases](https://github.com/Lusitaniae/apache_exporter/releases) 获取最新发布信息。 --- #### 配置 Apache Server 为了使 Apache Exporter 正常工作,需确保 Apache 启用了 `mod_status` 模块,并允许外部程序访问该模块的数据。编辑 Apache 配置文件(通常是 `/etc/httpd/conf/httpd.conf` 或者 `/etc/apache2/apache2.conf`),添加如下内容: ```apache <IfModule mod_status.c> ExtendedStatus On <Location "/server-status"> SetHandler server-status Require local </Location> </IfModule> ``` > **注意**: 如果希望远程机器能够连接到此端口收集数据,应修改 `Require local` 行为更宽松的安全策略,例如指定 IP 地址范围或网络接口。 重启服务后即可生效: ```bash systemctl restart httpd # CentOS/RHEL 系统上适用 # 或者 systemctl restart apache2 # Ubuntu/Debian 系统上适用 ``` --- #### 集成到 Prometheus 中 一旦成功部署了 Apache Exporter 并确认其正常运行,下一步就是将其加入 Prometheus 的 scrape targets 列表中。打开 Prometheus 主配置文件 (`prometheus.yml`) ,增加类似下面的内容: ```yaml scrape_configs: - job_name: 'apache' static_configs: - targets: ['localhost:9117'] # 默认监听端口号为 9117, 若更改则同步调整此处设置 ``` 保存变更之后重新加载 Prometheus 实例的服务配置,从而立即应用新的 target 设置。 --- #### 数据可视化与告警规则设定 最后一步涉及 Grafana 和 Alertmanager 的配合使用,创建仪表盘展示重要 KPIs 如请求速率、错误率等;同时定义合理的阈值触发器,在异常情况发生前及时预警。更多细节可参阅官方文档链接[^2]。 --- ### 示例代码片段 启动 Apache Exporter 的简单命令行示例: ```bash ./apache_exporter --web.listen-address=":9117" ``` 验证 Pod 是否处于就绪状态(如果是 Kubernetes 环境下部署的话): ```bash kubectl get pods -n monitoring -l app=apache-exporter ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值