[Linux] Prometheus 구성

슬터디·2023년 12월 6일
1

[YOU] 기술분석

목록 보기
10/24

Prometheus 패키지 다운

  • mkdir prometheus

  • wget ~~~.tar.gz

    • wget: 파일 다운로드
  • tar xzvf ~~~.tar.gz

    • tar: 압축 해제
    • xvf: tar 압축파일 시 사용
    • xzvf: tar.gz 압축파일 시 사용
  • 참고: wget 사용 시 파일 우측 클릭 후, 링크 주소 복사를 이용한다

Prometheus 실행파일 수정

  • cp prometheus /usr/local/bin/
    • prometheusroot/usr/local/bin/ 으로 복사
    • /를 붙이면, 현 위치가 아니라 root에서 시작하나보다.

Data와 설정파일이 위치할 디렉토리 생성

  • mkdir /var/lib/prometheus/
  • mkdir /etc/prometheus/
    • /를 붙이면, 현 위치가 아니라 root에서 시작하나보다.

다운 받은 설정파일을 복사

  • cp prometheus.yml /etc/prometheus/
  • cp -rf consoles /etc/prometheus/
  • cp -rf console_libraries/ /etc/prometheus
    • r: 복사 대상이 디렉토리이면, 하위 폴더와 파일까지 모두 복사한다
    • f: 이미 있는 경우 덮어 씌우기

프로세스 구동을 위한 계정 생성

  • useradd --no-create-home --shell /bin/false prometheus
    • useradd:
      • 리눅스는 다중 사용자 시스템 지원
      • 둘 이상의 사용자가 동시에 같은 시스템에 접근하여 상호작용 가능
      • 사용자 계정 생성을 위한 명령어
    • --no-create-home: 해당 유저의 home 디렉토리를 만들지 않음
    • --shell SHELL: 새 계정의 로그인 쉘
    • prometheus 라는 유저이다

Data 파일의 Owner와 권한 수정

  • chown -R prometheus:prometheus /var/lib/prometheus
    • chown: 파일이나 디렉토리의 소유자 변경하기
    • 소유자 + 그룹 변경
      • :를 구분자로 소유자:그룹 형식으로 사용
      • prometheus(소유자) : prometheus(그룹)
    • /var/lib/prometheus: 소유자를 변경할 디렉토리
    • -R: 하위 디렉토리까지 소유자를 변경

  • chmod 775 /var/lib/prometheus
    • chmod: 파일이나 디렉토리에 권한 부여 및 수정
    • 리눅스의 권한
      • Read, Write, eXecute
      • 앞의 한 자리를 빼고 3자리씩 끊어 읽으면 됨
    • 775: 소유자, 그룹은 모두, 다른 사람은 Read, eXecute만

설정파일의 Ip target 수정

  • vim /etc/prometheus/prometheus.yml
    static_configs:
    - targets: ["mgt01_IP:9100", "web01_IP:9100", "was01_IP:9100", "dbm01_IP:9100"]

Prometheus Service 구성

  • 설치한 파일을 기반으로 새로운 Service를 구성함
  • vim /etc/systemd/system/prometheus.service
Description=Prometheus Monitoring Server
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/ \
 --web.console.templates=/etc/prometheus/consoles \
 --web.console.libraries=/etc/prometheus/console_libraries
 
[Install]
WantedBy=multi-user.target
  • systemctl daemon-reload
  • systemctl start prometheus.service
  • systemctl enable prometheus.service
  • systemctl status prometheus.service

-ss -pltn | grep prometheus
- 9090 포트 Listen 중
- dbm01 IP:9090

profile
기억력이 맹구라 늘 기록해야해

0개의 댓글