-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.