본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

설치

원문 보기 위키 갱신

설치 (Installation)

프로메테우스를 설치하는 방법에는 여러 가지가 있어요. 미리 컴파일된 바이너리, 소스에서 빌드, Docker 이미지, systemd 서비스, Kubernetes 컨트롤러 등으로 실행할 수 있죠. 이 문서는 가장 흔한 설치·실행 방법들을 정리해 드려요. 어떤 환경에 배포하느냐에 따라 맞는 방법을 고르면 돼요.

시작이 반이라고, 여기 나온 Docker 한 줄 명령으로 프로메테우스를 1분 안에 띄울 수 있어요. 그 뒤에는 구성 파일 리로딩 방법과 Windows 서비스·Kubernetes 배포까지 차근차근 익혀 보세요.

출처: 문서

본문

설치 (Installation)

Prometheus는 여러 가지 방법으로 설치할 수 있어요. 가장 흔한 것들은:

  1. 미리 컴파일된 바이너리: 여러분의 플랫폼에 맞는 미리 컴파일된 바이너리를 다운로드하세요. tar.gz 같은 tarball 형식과 그것을 풀기 위한 몇 가지 커맨드라인 도구가 필요해요.

  2. 소스에서: 소스 코드에서 직접 컴파일하세요. 이를 위해 Git과 Go 툴체인이 필요해요. Go 버전 1.21+ 권장.

  3. Docker 사용: Prometheus는 Prometheus 서버 배포를 정말 쉽게 만드는 미리 빌드된 Docker 이미지를 제공해요. 이미지를 다운로드하고 아래 지침으로 실행하세요.

  4. Linux에서 systemd 서비스로 실행: 아래 섹션을 참조하세요.

  5. Kubernetes 컨트롤러로 실행: Kubernetes 섹션을 참조하세요. 미리 빌드된 Docker 이미지는 대안 소스로 quay.io에서도 다운로드할 수 있어요.

Docker로 Prometheus 실행 (Running Prometheus with Docker)

prom/prometheus Docker 이미지는 프로젝트가 제공하는 미리 빌드된 이미지예요. 이것을 실행하려면:

$ docker run -p 9090:9090 prom/prometheus

그게 전부예요! 이제 포트 9090을 노출하며 Prometheus가 머신에서 실행될 거예요. 기본적으로 이미지는 Docker 호스트의 Prometheus 프로세스 자체를 스크랩하는 구성 파일(/etc/prometheus/prometheus.yml)을 포함해요.

기본 구성은 전역 스크랩 간격이 15s예요. 그 값을 설정하는 방법에 대한 자세한 내용은 구성 문서를 참조하세요.

이미지는 /prometheus에 볼륨도 포함해요. --storage.tsdb.path 플래그를 지정해 /prometheus 볼륨을 데이터 디렉터리로 사용하세요. 보안상의 이유로 이미지는 기본적으로 비루트 사용자로 실행된다는 점에 유의하세요. 즉 볼륨은 비루트 사용자에 대해 RWO(read write owner) 권한이 있어야 해요. 예를 들어 바인드 마운트 볼륨으로:

$ docker run -p 9090:9090 -v <some-mount>:data --storage.tsdb.path=data prom/prometheus

여러분의 자체 구성과 규칙을 마운트해서 사용할 수도 있어요:

$ docker run --network host -v <some-mount>:/etc/prometheus \
  --storage.tsdb.path=/prometheus prom/prometheus

여기서 구성과 규칙 파일을 /etc/prometheus에 마운트하는데, 이것은 컨테이너에서 구성 파일의 기본 위치예요. 컨테이너의 데이터 디렉터리는 /prometheus예요. 여기서 네트워크 모드로 호스트 네트워크를 사용하므로, 컨테이너는 호스트의 localhost를 사용해요.

--network host를 사용하면 포트를 직접 제공해야 해요.

Windows에서 Prometheus 실행 (Running Prometheus on Windows)

./prometheus.exe --config.file=prometheus.yml

Prometheus는 Windows 서비스로 설치/실행할 수도 있어요. create a service 섹션을 참조하세요.

Linux/macOS에서 Prometheus 실행 (systemd 사용) (Running Prometheus on Linux/macOS (with systemd))

Linux/macOS에서 systemd를 통해 Prometheus를 서비스로 실행하는 것이 가능해요.

Linux/macOS에서 systemd 구성 (Configuring systemd on Linux/macOS)

아래 구성은 Linux/macOS 환경에서 Prometheus를 실행하기 위한 systemd 서비스 파일의 예예요.

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus/ \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

참고: 기본적으로 Prometheus 컨테이너 이미지는 이제 user nobody와 그룹 nobody로 실행되므로, 예를 들어 볼륨에 대한 모든 읽기/쓰기 접근은 그에 맞게 조정해야 해요.

Node Exporter로 Prometheus 실행 (Docker Compose) (Running Prometheus with Node Exporter (Docker Compose))

흔한 구성은 Node Exporter와 함께 Prometheus를 실행하는 것이에요. 이것은 Docker Compose로 할 수 있어요. 다음 내용으로 docker-compose.yml 파일을 만드세요:

services:
  prometheus:
    image: prom/prometheus
    ports:
      - "9090:9090"
    volumes:
      - prometheus-data:/prometheus

  node-exporter:
    image: quay.io/prometheus/node-exporter:latest
    ports:
      - "9100:9100"
    command:
      - --path.rootfs=/host
      - --collector.textfile


volumes:
  prometheus-data:

이 구성은 prometheus와 node-exporter 두 개의 서비스를 사용해요. prometheus 서비스는 Prometheus 데이터를 영속화하는 데 사용되는 prometheus-data 라는 이름의 볼륨을 가져요. node-exporter 서비스는 포트 9100을 노출하고, 텍스트 파일에 쓰인 커스텀 메트릭을 노출할 수 있게 하는 textfile 컬렉터를 실행해요. 참고: 이 구성은 Docker Compose가 이미 설치돼 있다고 가정해요.

구성 파일 리로딩 (Reloading config files)

구성 파일은 런타임에 안전하게 리로드할 수 있어요. 구성 파일이 런타임에 리로드될 수 있으므로, 구성을 간단한 Linux 시나리오로 바꿀 수 있고 변경되지 않은 구성 값은 영향받지 않아요.

구성을 리로드하는 두 가지 방법이 있어요:

  1. 생명주기 플래그를 설정하고 Prometheus 프로세스를 재시작하세요.

  2. -web.enable-lifecycle 커맨드라인 플래그를 사용해 /-/reload 트래픽을 보내세요.

생명주기 플래그 (Lifecycle flags)

  • -web.enable-lifecycle은 HTTP 기반 리로딩을 활성화해요.

  • SIGHUP으로 구성을 리로드하려면 kill -HUP <pid> 명령을 사용하세요.

Prometheus가 systemd로 실행 중이라면 systemctl reload prometheus를 사용할 수 있어요.

Windows 서비스 만들기 (Creating a Windows service)

Prometheus용 Windows 서비스를 만들려면 winsw(Windows Service Wrapper)나 NSSM을 사용하는 것을 권장해요. 이 도구들은 거의 모든 실행 파일을 Windows 서비스로 감쌀 수 있게 해 줘요.

# With winsw
./winsw install
./winsw start


# With NSSM
./nssm install YourServiceName C:\prometheus\prometheus.exe
./nssm start YourServiceName


# NSSM editing service parameters
done...

Kubernetes 온프레미스 Prometheus (Kubernetes on-premise Prometheus)

Kubernetes on-premise Prometheus 섹션은 Kubernetes 클러스터에서 Prometheus를 온프레미스로 배포하는 방법을 설명해요(참고로 k8s-prom도 보세요). 아래에서 권장 배포 접근 방식을 다룹니다.

더 알아보기 (Learn more)