Server Web Apache (httpd)

Dokumen ini menjelaskan cara mengonfigurasi deployment Google Kubernetes Engine agar Anda dapat menggunakan Google Cloud Managed Service for Prometheus untuk mengumpulkan metrik dari Apache Web Server (httpd). Dokumen ini menunjukkan cara melakukan hal berikut:

  • Siapkan eksportir untuk Server Web Apache guna melaporkan metrik.
  • Akses dasbor di Cloud Monitoring untuk melihat metrik.

Petunjuk ini hanya berlaku jika Anda menggunakan koleksi terkelola dengan Managed Service for Prometheus. Jika Anda menggunakan pengumpulan yang di-deploy sendiri, lihat repositori sumber untuk Apache HTTP exporter guna mengetahui informasi penginstalan.

Petunjuk ini diberikan sebagai contoh dan diharapkan berfungsi di sebagian besar lingkungan Kubernetes. Jika Anda mengalami masalah saat menginstal aplikasi atau eksportir karena kebijakan keamanan atau organisasi yang ketat, sebaiknya lihat dokumentasi open source untuk mendapatkan dukungan.

Untuk mengetahui informasi tentang Server Web Apache (httpd), lihat Apache HTTP.

Prasyarat

Untuk mengumpulkan metrik dari Apache Web Server dengan menggunakan Managed Service for Prometheus dan pengumpulan terkelola, deployment Anda harus memenuhi persyaratan berikut:

  • Cluster Anda harus menjalankan Google Kubernetes Engine versi 1.28.15-gke.2475000 atau yang lebih baru.
  • Anda harus menjalankan Managed Service for Prometheus dengan koleksi terkelola yang diaktifkan. Untuk mengetahui informasi selengkapnya, lihat Mulai menggunakan koleksi terkelola.

  • Untuk menggunakan dasbor yang tersedia di Cloud Monitoring untuk integrasi Server Web Apache, Anda harus menggunakan httpd_exporter versi v1.0.0 atau yang lebih baru.

    Untuk mengetahui informasi selengkapnya tentang dasbor yang tersedia, lihat Melihat dasbor.

Menginstal eksportir Apache Web Server

Sebaiknya Anda menginstal eksportir Apache Web Server, httpd_exporter, sebagai sidecar untuk beban kerja Apache Web Server Anda. Untuk mengetahui informasi tentang cara menggunakan file bantuan, lihat Aplikasi yang diperluas di Kubernetes dengan pod multi-container.

Untuk menginstal httpd_exporter sebagai sidecar ke Apache Web Server, ubah konfigurasi Apache Web Server seperti yang ditunjukkan dalam contoh berikut:

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: v1
kind: ConfigMap
metadata:
  name: httpd
data:
  httpd.conf: |
    ...
+   <Location "/server-status">
+       SetHandler server-status
+   </Location>
+   LoadModule status_module modules/mod_status.so
    ...
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd
spec:
  replicas: 1
  selector:
    matchLabels:
+     app.kubernetes.io/name: httpd
  template:
    metadata:
      labels:
+       app.kubernetes.io/name: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.4
        ports:
        - containerPort: 80
          name: httpd
+       volumeMounts:
+       - mountPath: /usr/local/apache2/conf/httpd.conf
+         subPath: httpd.conf
+         name: httpd
+     - name: httpd-exporter
+       image: lusotycoon/apache-exporter:v1.0.0
+       ports:
+       - containerPort: 9117
+         name: prometheus
+       command: ["/bin/apache_exporter"]
+       args: ["--scrape_uri=http://localhost/server-status?auto", "--web.listen-address=:9117", "--telemetry.endpoint=/metrics"]
+     volumes:
+     - name: httpd
+       configMap:
+         name: httpd
+         items:
+         - key: httpd.conf
+           path: httpd.conf

Anda harus menambahkan baris yang diawali dengan simbol + ke konfigurasi.

Petunjuk ini mengasumsikan bahwa Anda sudah memiliki penginstalan Apache Web Server yang berfungsi dan ingin memodifikasinya untuk menyertakan eksportir. Server HTTP Apache dapat dikonfigurasi untuk menyajikan metrik di /server-status dengan mengubah konfigurasi dengan direktif Location baru dan dengan memuat status_module.

Untuk menerapkan perubahan konfigurasi dari file lokal, jalankan perintah berikut:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Anda juga dapat