반응형
AWS에서 Prometheus를 설치하는 방법은 크게 두 가지가 있습니다.
- Amazon Managed Service for Prometheus (AMP) 사용
- AWS에서 관리하는 서비스로, 직접 Prometheus를 설치할 필요 없이 사용 가능
- 자동 확장 및 유지보수가 쉬움
- 비용이 발생하지만 운영 부담이 적음
- EC2 인스턴스에 Prometheus 직접 설치
- 직접 관리해야 하지만 유연한 설정 가능
- 비용 절감 가능
- Prometheus와 Grafana를 함께 설치하여 모니터링 가능
1. Amazon Managed Service for Prometheus (AMP) 설정 방법
🔹 AMP 활성화
- AWS 콘솔에서 AMP 서비스 활성화
- AWS 콘솔에서 "Amazon Managed Service for Prometheus"로 이동
- "워크스페이스 생성" 클릭
- 이름 입력 후 "다음"을 클릭하여 생성
- 워크스페이스 URL 확인
- 생성된 Prometheus 워크스페이스의 "워크스페이스 URL"을 기록
- IAM 역할 생성
- AMP에 데이터를 전송할 IAM 역할을 생성
- IAM 정책에 아래 내용을 추가
{ "Effect": "Allow", "Action": [ "aps:RemoteWrite", "aps:QueryMetrics", "aps:GetSeries", "aps:GetLabels", "aps:GetMetricMetadata" ], "Resource": "*" }
- EC2 또는 EKS에서 Prometheus가 이 역할을 사용하도록 설정
- Prometheus 설정 파일 변경 (prometheus.yml)
- AMP의 워크스페이스 URL을 설정
global: scrape_interval: 15s scrape_configs: - job_name: 'aws-prometheus' static_configs: - targets: ['localhost:9090'] remote_write: - url: 'https://aps-workspace-endpoint.amazonaws.com/api/v1/remote_write' sigv4: region: 'us-east-1' # 사용 중인 AWS 리전 입력
- Prometheus 실행 후 데이터 전송 확인
- AWS AMP 콘솔에서 데이터가 수집되는지 확인
- prometheus --config.file=prometheus.yml
2. EC2 인스턴스에 Prometheus 설치 방법
🔹 EC2 인스턴스 설정
- EC2 인스턴스 생성
- Amazon Linux 2 또는 Ubuntu 선택
- 보안 그룹에서 포트 9090을 허용
- Prometheus 설치
- sudo useradd --no-create-home --shell /bin/false prometheus sudo mkdir /etc/prometheus sudo mkdir /var/lib/prometheus sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus
- Prometheus 바이너리 다운로드
- wget https://github.com/prometheus/prometheus/releases/latest/download/prometheus-linux-amd64.tar.gz tar xvf prometheus-linux-amd64.tar.gz cd prometheus-*/ sudo mv prometheus promtool /usr/local/bin/ sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool
- 설정 파일 생성 (/etc/prometheus/prometheus.yml)
- global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090']
- Prometheus 서비스 등록
- sudo tee /etc/systemd/system/prometheus.service <<EOF [Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus [Install] WantedBy=multi-user.target EOF
- Prometheus 실행 및 확인
- http://<EC2_PUBLIC_IP>:9090로 접속하여 Prometheus UI 확인
- sudo systemctl daemon-reload sudo systemctl enable prometheus sudo systemctl start prometheus
3. Grafana와 연동하여 데이터 시각화 (선택)
🔹 Grafana 설치
sudo yum install -y https://dl.grafana.com/oss/release/grafana-10.2.0-1.x86_64.rpm
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
🔹 Grafana에서 Prometheus 연결
- Grafana 웹 UI 접속 (http://<EC2_PUBLIC_IP>:3000)
- "Data Sources" → "Prometheus" 추가
- URL에 http://localhost:9090 입력 후 "Save & Test"
4. Prometheus 설정 변경 (필요 시)
- prometheus.yml 수정하여 추가적인 지표 수집 가능
- scrape_configs 섹션에서 여러 타겟을 모니터링하도록 설정 가능
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['192.168.1.10:9100']
5. 결론
- AWS Managed Prometheus (AMP): 관리형 서비스로 편리하지만 비용이 발생
- EC2에서 직접 Prometheus 설치: 직접 관리해야 하지만 비용 절감 가능
- Grafana와 연동하면 데이터를 시각적으로 모니터링 가능
위 방법 중 선택하여 Prometheus를 AWS 환경에서 설정하면 됩니다! 🚀
반응형