[Prometheus] CentOS 7 에서 프로메테우스(Prometheus) 설치 및 기본 설정, 실행

2023. 3. 14. 08:44·Observability

1. 프로메테우스 설치

# 'prometheus' 유저 추가
# useradd --no-create-home --shell /sbin/nologin prometheus

# 프로메테우스 다운로드
# cd ~/Downloads
# wget https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-amd64.tar.gz
# 위 다운로드 링크는 설치하려는 프로메테우스의 버전, OS 버전에 따라 달라진다.

# 다운로드 받은 프로메테우스 tar.gz 파일 압축 풀기
# tar -xzvf prometheus-2.42.0.linux-amd64.tar.gz

# prometheus 설치 경로 변경
# mv ~/Downloads/prometheus-2.42.0.linux-amd64 /opt/prometheus

# 관리 편의를 위한 디렉토리 생성
# mkdir /opt/prometheus/bin /opt/prometheus/conf /opt/prometheus/data

# prometheus HOME 디렉토리 권한 부여
# chown -R prometheus:prometheus /opt/prometheus

 

2. 프로메테우스 실행

# 프로메테우스 설치 경로로 이동
$ cd /opt/prometheus

# 프로메테우스 서버 실행
$ ./prometheus --config.file=/opt/prometheus/conf/prometheus.yml

프로메테우스 실행 성공 출력 화면 - "Starting rule manager..." 를 확인하기

 

- 프로메테우스 접속 - default는 9090 포트

http://{프로메테우스 올라간 서버 IP 또는 DNS 호스트네임}:9090/

ex) http://10.0.2.15:9090/

위 url로 접속이 된다면 프로메테우스 서버가 정상적으로 구동된 것이다.


3. Metric 이름으로 검색해보기

http://{프로메테우스 올라간 서버 IP 또는 DNS 호스트네임}:9090/metrics 로 접속하면 프로메테우스 서버가 수집한 metric 들을 확인할 수 있다. 이러한 metric 들은 프로메테우스의 GUI 콘솔 상에서도 다음과 같이 검색이 가능하다.

/metrics 에서 확인해본 'go_memstats_alloc_bytes' 메트릭
프로메테우스 콘솔 페이지에서 metric 이름으로 검색한 화면


4. prometheus.yml (프로메테우스 configuration 파일) 의 Default 설정 살펴보기

# prometheus.yml 파일

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
 
# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

 # A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
    - job_name: "prometheus"
    
      # metrics_paht defaults to '/metrics'
      # scheme defaults to 'http'.
      
        static_configs:
          - targets: ["localhost:9090"]

5. systemctl에 service 등록하기

- service 파일 생성

# vi /usr/lib/systemd/system/prometheus.service
# /usr/lib/systemd/system/prometheus.service 파일

[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
EnvironmentFile=/etc/sysconfig/prometheus
PIDFile=/var/run/prometheus.pid

User=prometheus
Group=prometheus
Restart=on-failure

WorkingDirectory=/opt/prometheus
RuntimeDirectory=prometheus
RuntimeDirectoryMode=0750

ExecStart=/opt/prometheus/bin/prometheus                                \
  --config.file=${CONF_FILE}                                            \
  --storage.tsdb.path=${DATA_DIR}										\
  --web.console.templates=${PROMETHEUS_HOME}/consoles                   \
  --web.console.libraries=${PROMETHEUS_HOME}/cconsole_libraries         \
  --web.enable-admin-api
  --storage.tsdb.retention.time=30d    # prometheus에서 수집한 데이터 보관 주기를 30일로 지정

[Install]
WantedBy=multi-user.target

- service 파일 작성시 깔끔하게 작성하기 위한, /etc/sysconfig/prometheus 작성

# vi /etc/sysconfig/prometheus 로 파일 생성

# /etc/sysconfig/prometheus 파일

PROMETHEUS_USER=prometheus

PROMETHEUS_GROUP=prometheus

PROMETHEUS_HOME=/opt/prometheus

LOG_DIR=/opt/prometheus/logs

DATA_DIR=/opt/prometheus/data

CONF_DIR=/opt/prometheus/conf

CONF_FILE=/opt/prometheus/conf/prometheus.yml

# Only used on systemd systems
PID_FILE_DIR=/var/run/prometheus

 

- 새로 작성한 .service 파일을 systemctl 에 인식시키기

# systemctl daemon-reload

 

- 프로메테우스를 systemctl 로 구동하기

# systemctl start prometheus

 

- 부팅시 자동으로 서비스 시작하도록 하기

# systemctl enable prometheus.service

참고

https://sanggi-jayg.tistory.com/91

 

[CentOS 7] Prometheus + Grafana 설치

CentOS 7 에 Prometheus + Grafana 설치 메뉴얼 프로메테우스 설치 https://prometheus.io/ # 유저 추가 useradd -m -s /bin/bash prometheus su - prometheus # 다운로드 cd /home/prometheus wget https://github.com/prometheus/prometheus/releases

sanggi-jayg.tistory.com

 

패스트캠퍼스 - '한 번에 끝내는 데이터 엔지니어링 초격차 패키지 Online' 중 Part.5 Observability - Ch 02_02.

'Observability' 카테고리의 다른 글

[Prometheus] node_exporter와 Windows_exporter 에 적용시키는 샘플 rules.yml  (0) 2023.03.31
[Prometheus] Metric의 Threshold를 지정하고 AlertManager로 메일 통해 알람 받기  (0) 2023.03.18
[Prometheus] Node Exporter 를 CentOS 7 서버에 설치하기  (0) 2023.03.16
[Grafana] CentOS 7 에서 Grafana(Prometheus 데이터를 시각화해주는 서버) 설치하고 프로메테우스와 연동하기  (0) 2023.03.16
'Observability' 카테고리의 다른 글
  • [Prometheus] node_exporter와 Windows_exporter 에 적용시키는 샘플 rules.yml
  • [Prometheus] Metric의 Threshold를 지정하고 AlertManager로 메일 통해 알람 받기
  • [Prometheus] Node Exporter 를 CentOS 7 서버에 설치하기
  • [Grafana] CentOS 7 에서 Grafana(Prometheus 데이터를 시각화해주는 서버) 설치하고 프로메테우스와 연동하기
코_노
코_노
일상의 불편함을 기술로서 해결하기 위해 노력하는 IT 엔지니어입니다. Contact point) jjh3706@gmail.com
  • 코_노
    코딩하는 주노 이야기
    코_노
  • 전체
    오늘
    어제
    • 코딩 이야기 (121)
      • DB (35)
        • SQL Server (MSSQL) (27)
        • MongoDB (2)
        • Hadoop Ecosystem (0)
        • SQLP 공부 (2)
      • 데이터 엔지니어링 (0)
        • Spark (0)
      • Middleware (21)
        • 웹서버 (7)
        • WAS (6)
        • WSGI (3)
        • 기타 (5)
      • OS (10)
        • Linux (7)
        • Windows (3)
      • Network (8)
      • Cloud (1)
        • AWS (1)
      • DevOps (8)
        • Container & K8S (0)
        • Github (3)
        • Ansible (2)
        • Terraform (3)
      • Security (3)
      • Observability (5)
      • CS 지식 | 기초 용어,개념 (7)
      • Python (1)
        • Flask (0)
      • Java (7)
        • JPA (0)
      • 안드로이드 (1)
      • 알고리즘 공부 (14)
  • 블로그 메뉴

    • 홈
    • 코딩 이야기
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    백준
    db
    MSSQL
    MongoDB Sharding
    SQL Server
    SSMS
    jvm 실행 옵션
    DBA
    SQL Server 2019
    SAS 아키텍처
    백준 골드4
    백준 알고리즘
    SQL Server 2019 Restore
    Windows AD
    백준 골드2
    SAS
    백준 골드 2
    SAS Intelligence Platform
    백준 python
    백준 파이썬
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
코_노
[Prometheus] CentOS 7 에서 프로메테우스(Prometheus) 설치 및 기본 설정, 실행
상단으로

티스토리툴바