diff --git a/conteneur/Dockerfile b/conteneur/Dockerfile new file mode 100644 index 0000000..541fa35 --- /dev/null +++ b/conteneur/Dockerfile @@ -0,0 +1,43 @@ +FROM debian:bullseye-slim + +# Installation des dépendances +RUN apt-get update && apt-get install -y \ + apache2 \ + supervisor \ + wget \ + curl \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +# Installation Apache Exporter +RUN wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.10/apache_exporter-1.0.10.linux-amd64.tar.gz \ + && tar xzf apache_exporter-1.0.10.linux-amd64.tar.gz \ + && mv apache_exporter-1.0.10.linux-amd64/apache_exporter /usr/local/bin/ \ + && rm -rf apache_exporter-* + +# Installation Promtail +RUN wget https://github.com/grafana/loki/releases/download/v2.9.0/promtail-linux-amd64.zip \ + && unzip promtail-linux-amd64.zip \ + && mv promtail-linux-amd64 /usr/local/bin/promtail \ + && chmod +x /usr/local/bin/promtail \ + && rm promtail-linux-amd64.zip + +# Copie des configurations +COPY configs/apache/httpd.conf /etc/apache2/sites-available/000-default.conf +COPY configs/promtail/config.yaml /etc/promtail/config.yaml +COPY configs/supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +# Configuration Apache pour server-status +RUN echo '\n\ + SetHandler server-status\n\ + Require all granted\n\ +' > /etc/apache2/conf-available/server-status.conf \ + && a2enconf server-status \ + && a2enmod status + +# Création des répertoires de logs +RUN mkdir -p /var/log/apache2 /var/log/promtail + +EXPOSE 80 9117 9080 + +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/conteneur/configs/apache/httpd.conf b/conteneur/configs/apache/httpd.conf new file mode 100644 index 0000000..7c987f6 --- /dev/null +++ b/conteneur/configs/apache/httpd.conf @@ -0,0 +1,27 @@ +# Configuration Apache de base +ServerRoot "/etc/apache2" +#Listen 80 + +# Modules (déjà chargés par défaut dans debian/ubuntu) + +ServerAdmin admin@localhost +ServerName localhost + +DocumentRoot "/var/www/html" + + Options Indexes FollowSymLinks + AllowOverride None + Require all granted + + +ErrorLog /var/log/apache2/error.log +LogLevel warn + +LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined +CustomLog /var/log/apache2/access.log combined + +# Server status pour apache_exporter + + SetHandler server-status + Require all granted + diff --git a/conteneur/configs/promtail/config.yaml b/conteneur/configs/promtail/config.yaml new file mode 100644 index 0000000..fcfb2a7 --- /dev/null +++ b/conteneur/configs/promtail/config.yaml @@ -0,0 +1,26 @@ +server: + http_listen_port: 9080 + grpc_listen_port: 0 + +positions: + filename: /tmp/positions.yaml + +clients: + - url: http://192.168.56.61:3100/loki/api/v1/push + +scrape_configs: + - job_name: apache_access + static_configs: + - targets: [localhost] + labels: + job: apache_access + host: apache_all_in_one + __path__: /var/log/apache2/access.log + + - job_name: apache_error + static_configs: + - targets: [localhost] + labels: + job: apache_error + host: apache_all_in_one + __path__: /var/log/apache2/error.log diff --git a/conteneur/configs/supervisord/supervisord.conf b/conteneur/configs/supervisord/supervisord.conf new file mode 100644 index 0000000..9f19fc9 --- /dev/null +++ b/conteneur/configs/supervisord/supervisord.conf @@ -0,0 +1,31 @@ +[supervisord] +nodaemon=true +user=root +logfile=/var/log/supervisor/supervisord.log +pidfile=/var/run/supervisord.pid + +[program:apache2] +command=/usr/sbin/apache2ctl -D FOREGROUND +autostart=true +autorestart=true +stdout_logfile=/var/log/apache2/access.log +stderr_logfile=/var/log/apache2/error.log +priority=1 + +[program:apache_exporter] +command=/usr/local/bin/apache_exporter --scrape_uri=http://localhost/server-status?auto +autostart=true +autorestart=true +stdout_logfile=/var/log/apache_exporter.log +stderr_logfile=/var/log/apache_exporter_error.log +priority=2 +startsecs=5 + +[program:promtail] +command=/usr/local/bin/promtail -config.file=/etc/promtail/config.yaml +autostart=true +autorestart=true +stdout_logfile=/var/log/promtail/promtail.log +stderr_logfile=/var/log/promtail/promtail_error.log +priority=3 +startsecs=5 diff --git a/conteneur/docker-compose.yml b/conteneur/docker-compose.yml new file mode 100644 index 0000000..100d531 --- /dev/null +++ b/conteneur/docker-compose.yml @@ -0,0 +1,23 @@ +services: + apache-observability: + build: + context: . + dockerfile: Dockerfile + container_name: apache_all_in_one + ports: + - "8080:80" + - "9117:9117" + - "9080:9080" + volumes: + - apache-logs:/var/log/apache2 + networks: + - centre_observabilite_observability + restart: unless-stopped + +volumes: + apache-logs: + +networks: + centre_observabilite_observability: + external: true + name: centre_observabilite_observability