From 58b15019547d5bffbfdb97c6627499c95107937f Mon Sep 17 00:00:00 2001 From: 5uhwann <5uhwann27@gmail.com> Date: Tue, 24 Sep 2024 13:23:37 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20promtail=20ebextension=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .ebextensions/02-install-promtail.config | 155 ++---------------- .../main/resources}/promtail-config.yml | 0 2 files changed, 15 insertions(+), 140 deletions(-) rename {promtail => src/main/resources}/promtail-config.yml (100%) diff --git a/.ebextensions/02-install-promtail.config b/.ebextensions/02-install-promtail.config index e7162fea..bdcb7647 100644 --- a/.ebextensions/02-install-promtail.config +++ b/.ebextensions/02-install-promtail.config @@ -1,140 +1,15 @@ -#!/bin/bash - -# 로그 파일 설정 -LOG_FILE="/var/log/promtail_install.log" - -# 로깅 함수 -log() { - echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" -} - -log "Starting Promtail installation and configuration" - -# Promtail 설치 -if [ ! -f /usr/local/bin/promtail ]; then - log "Downloading Promtail" - if curl -O -L "https://github.com/grafana/loki/releases/download/v2.8.0/promtail-linux-amd64.zip"; then - log "Promtail download successful" - else - log "Error: Promtail download failed" - exit 1 - fi - - log "Installing unzip if not present" - yum install -y unzip - - log "Unzipping Promtail" - if unzip promtail-linux-amd64.zip; then - log "Promtail unzip successful" - else - log "Error: Promtail unzip failed" - exit 1 - fi - - log "Moving Promtail to /usr/local/bin" - if sudo mv promtail-linux-amd64 /usr/local/bin/promtail; then - log "Promtail move successful" - else - log "Error: Failed to move Promtail" - exit 1 - fi - - log "Cleaning up zip file" - rm promtail-linux-amd64.zip -else - log "Promtail is already installed" -fi - -# Promtail 설정 파일 생성 -log "Creating Promtail configuration file" -cat > /etc/promtail-config.yaml << EOL -server: - http_listen_port: 9080 - grpc_listen_port: 0 - -positions: - filename: /tmp/positions.yaml - -clients: - - url: ${LOKI_URL} - -scrape_configs: - - job_name: all - static_configs: - - targets: - - localhost - labels: - job: all_logs - __path__: /var/app/current/logs/all/*.log - - - job_name: warn - static_configs: - - targets: - - localhost - labels: - job: warn_logs - __path__: /var/app/current/logs/warn/*.log - - - job_name: error - static_configs: - - targets: - - localhost - labels: - job: error_logs - __path__: /var/app/current/logs/error/*.log -EOL - -log "Promtail configuration file created" - -# Promtail 서비스 파일 생성 -log "Creating Promtail service file" -cat > /etc/systemd/system/promtail.service << EOL -[Unit] -Description=Promtail service -After=network.target - -[Service] -Type=simple -User=webapp -EnvironmentFile=/opt/elasticbeanstalk/deployment/env -ExecStart=/usr/local/bin/promtail -config.file /etc/promtail-config.yaml -Restart=always - -[Install] -WantedBy=multi-user.target -EOL - -log "Promtail service file created" - -# 로그 디렉토리 권한 설정 -log "Setting up log directories" -sudo mkdir -p /var/app/current/logs/all /var/app/current/logs/warn /var/app/current/logs/error -sudo chown -R webapp:webapp /var/app/current/logs -log "Log directories set up" - -# Promtail 서비스 시작 -log "Reloading systemd daemon" -sudo systemctl daemon-reload - -log "Enabling Promtail service" -sudo systemctl enable promtail - -log "Starting Promtail service" -if sudo systemctl start promtail; then - log "Promtail service started successfully" -else - log "Error: Failed to start Promtail service" - log "Promtail service status:" - sudo systemctl status promtail >> "$LOG_FILE" -fi - -log "Promtail installation and configuration completed" - -# 최종 상태 확인 -log "Final Promtail status:" -sudo systemctl status promtail >> "$LOG_FILE" - -log "Promtail configuration file contents:" -cat /etc/promtail-config.yaml >> "$LOG_FILE" - -log "Installation script completed" +container_commands: + 01_install_docker_compose: + command: "curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose" + + 02_setup_promtail: + command: | + echo "version: '3' + services: + promtail: + image: grafana/promtail:2.5.0 + volumes: + - /var/log:/var/log + - /tmp/positions.yaml:/tmp/positions.yaml + command: -config.file=/var/app/current/promtail-config.yml" > /var/app/current/promtail-docker-compose.yml + docker-compose -f /var/app/current/promtail-docker-compose.yml up -d diff --git a/promtail/promtail-config.yml b/src/main/resources/promtail-config.yml similarity index 100% rename from promtail/promtail-config.yml rename to src/main/resources/promtail-config.yml