-
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
1 changed file
with
56 additions
and
60 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,78 +1,74 @@ | ||
container_commands: | ||
01_create_current_directory: | ||
command: | | ||
# /var/app/current 디렉토리 생성 및 권한 설정 | ||
sudo mkdir -p /var/app/current | ||
sudo chmod -R 777 /var/app/current | ||
sudo chown ec2-user:ec2-user /var/app/current | ||
sudo chmod 755 /var/app/current | ||
|
||
01_install_docker: | ||
02_install_docker: | ||
command: | | ||
# Docker 설치 | ||
amazon-linux-extras install -y docker | ||
service docker start # Docker 서비스 시작 | ||
sudo amazon-linux-extras install -y docker | ||
sudo systemctl enable docker | ||
sudo systemctl start docker | ||
|
||
02_install_docker_compose: | ||
03_install_docker_compose: | ||
command: | | ||
# Docker Compose 설치 | ||
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 | ||
docker-compose --version # 설치된 Docker Compose 버전 확인 | ||
sudo curl -L "https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | ||
sudo chmod +x /usr/local/bin/docker-compose | ||
docker-compose --version | ||
|
||
03_create_promtail_config: | ||
04_create_promtail_config: | ||
command: | | ||
# Promtail 구성 파일 생성 | ||
cat << 'EOF' > /var/app/current/promtail-config.yml | ||
server: | ||
http_listen_port: 9080 | ||
grpc_listen_port: 0 | ||
cat << EOF > /var/app/current/promtail-config.yml | ||
server: | ||
http_listen_port: 9080 | ||
grpc_listen_port: 0 | ||
|
||
positions: | ||
filename: /tmp/positions.yaml # 동기화 작업을 이루기 위해 promtail이 읽은 마지막 로그 정보를 저장하는 곳 | ||
positions: | ||
filename: /tmp/positions.yaml | ||
|
||
clients: | ||
- url: ${LOKI_URL} | ||
clients: | ||
- url: \${LOKI_URL} | ||
|
||
scrape_configs: | ||
- job_name: all | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: all_logs | ||
__path__: /var/app/current/log/all/*.log | ||
scrape_configs: | ||
- job_name: all | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: all_logs | ||
__path__: /var/app/current/log/all/*.log | ||
|
||
- job_name: warn | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: warn_logs | ||
__path__: /var/app/current/log/warn/*.log | ||
- job_name: warn | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: warn_logs | ||
__path__: /var/app/current/log/warn/*.log | ||
|
||
- job_name: error | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: error_logs | ||
__path__: /var/app/current/log/error/*.log | ||
EOF | ||
- job_name: error | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: error_logs | ||
__path__: /var/app/current/log/error/*.log | ||
EOF | ||
|
||
04_setup_promtail: | ||
05_setup_promtail: | ||
command: | | ||
set -ex | ||
# Promtail Docker Compose 설정 파일 생성 | ||
echo "version: '3' | ||
services: | ||
promtail: | ||
image: grafana/promtail:2.5.0 | ||
environment: | ||
- LOKI_URL=${LOKI_URL} | ||
volumes: | ||
- /var/log:/var/log | ||
- /tmp/positions.yaml:/tmp/positions.yaml | ||
- /var/app/current:/var/app/current | ||
command: -config.file=/var/app/current/promtail-config.yml" > /var/app/current/promtail-docker-compose.yml | ||
|
||
# Docker Compose 실행 | ||
cat << EOF > /var/app/current/promtail-docker-compose.yml | ||
version: '3' | ||
services: | ||
promtail: | ||
image: grafana/promtail:2.5.0 | ||
environment: | ||
- LOKI_URL=\${LOKI_URL} | ||
volumes: | ||
- /var/log:/var/log | ||
- /tmp/positions.yaml:/tmp/positions.yaml | ||
- /var/app/current:/var/app/current | ||
command: -config.file=/var/app/current/promtail-config.yml | ||
EOF | ||
docker-compose -f /var/app/current/promtail-docker-compose.yml up -d |