🌥️Cloud Study🌥️/TroubleShooting

[ Prometheus ] active failed 오류 해결

L_Chae 2024. 8. 9. 15:32

3티어 아키텍처에서, Private 인스턴스에 프로메테우스 설치 후 status를 확인해보면 faile 문제가 계속해서 발생했었다.

이것저것 설정 수정해보고 서비스 설정 바꾸고 별 짓을 다 하다가 지우고 재설치만 세 번째 ... GPT와 함께 문제를 해결해보았다.

혹시나 동일한 오류가 발생하는 사람들을 위해 .. ^ㅡㅜ 특히나 yaml파일은 띄어쓰기, 들여쓰기가 진짜.너무.엄청. 예민해서
GPT 사용 가능하면 그냥 얘한테 형식 맞춰달라고 하면 편하다 ....

 

오류 코드 #1

요약 : Prometheus 사용자 존재하지 않음

ubuntu@a-private-01:~$ sudo systemctl status prometheus
● prometheus.service - Prometheus
     Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-08-09 15:20:47 KST; 2min 41s ago
    Process: 8243 ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/ --web.con>
   Main PID: 8243 (code=exited, status=217/USER)

Aug 09 15:20:47 a-private-01 systemd[1]: Started Prometheus.
Aug 09 15:20:47 a-private-01 systemd[8243]: prometheus.service: Failed to determine user credentials: No such process
Aug 09 15:20:47 a-private-01 systemd[8243]: prometheus.service: Failed at step USER spawning /usr/local/bin/prometheus: No such process
Aug 09 15:20:47 a-private-01 systemd[1]: prometheus.service: Main process exited, code=exited, status=217/USER
Aug 09 15:20:47 a-private-01 systemd[1]: prometheus.service: Failed with result 'exit-code'.

 

 

  • Failed to determine user credentials: No such process
  • Failed at step USER spawning /usr/local/bin/prometheus: No such process

 

`prometheus.service`파일에서 사용자와 관련된 설정이 문제임을 나타내고 있다.

`USER`단계를 실행하려고 할 때 오류가 발생했고, 오류코드 `217/USER`는 시스템이 지정된 사용자를 찾거나 설정하는 데 문제가 있다는 것을 의미한다고 한다.

 

= prometheus.service 파일에서 정의된 사용자(User=prometheus)를 시스템에서 찾을 수 없거나, 이 사용자가 제대로 설정되지 않았음을 나타낸다.

 

# 사용자 존재 여부 확인
id prometheus

# 사용자 생성
sudo useradd --no-create-home --shell /bin/false prometheus

# 서비스 파일 확인 및 수정
sudo nano /etc/systemd/system/prometheus.service

[Service]
User=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

# 시스템 데몬 리로드 및 서비스 재시작
sudo systemctl daemon-reload
sudo systemctl restart prometheus

# 서비스 상태 확인
sudo systemctl status prometheus

`id prometheus`를 이용하여 시스템에 사용자가 존재하는지 확인해보니까 존재하지 않는다고 나와서 생성해주었다.

 


오류코드 #2

요약 : 사용자명 prometheus의 권한 문제

● prometheus.service - Prometheus
     Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-08-09 15:25:00 KST; 3s ago
    Process: 8307 ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/ --web.con>
   Main PID: 8307 (code=exited, status=2)

Aug 09 15:25:00 a-private-01 prometheus[8307]: ts=2024-08-09T06:25:00.796Z caller=query_logger.go:113 level=error component=activeQueryTracker msg="F>
Aug 09 15:25:00 a-private-01 prometheus[8307]: ts=2024-08-09T06:25:00.796Z caller=query_logger.go:91 level=error component=activeQueryTracker msg="Er>
Aug 09 15:25:00 a-private-01 prometheus[8307]: panic: Unable to create mmap-ed active query log
Aug 09 15:25:00 a-private-01 prometheus[8307]: goroutine 1 [running]:
Aug 09 15:25:00 a-private-01 prometheus[8307]: github.com/prometheus/prometheus/promql.NewActiveQueryTracker({0x7ffe09923e90, 0x14}, 0x14, {0x3aba480>
Aug 09 15:25:00 a-private-01 prometheus[8307]:         /app/promql/query_logger.go:121 +0x3cd
Aug 09 15:25:00 a-private-01 prometheus[8307]: main.main()
Aug 09 15:25:00 a-private-01 prometheus[8307]:         /app/cmd/prometheus/main.go:605 +0x6773
Aug 09 15:25:00 a-private-01 systemd[1]: prometheus.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Aug 09 15:25:00 a-private-01 systemd[1]: prometheus.service: Failed with result 'exit-code'.

Prometheus가 " mmap-ed active query log"를 생성할 수 없어서 실패하고 있음

일반적으로 Prometheus의 데이터 디렉토리 경로에 쓰기 권한이 없거나, 디렉토리가 없거나, 디스크 공간이 부족할 때 발생할 수 있다.

 

# 디렉토리 경로 및 권한 확인
sudo ls -ld /var/lib/prometheus/

# 디렉토리가 없을 경우 다음 명령어로 생성
sudo mkdir -p /var/lib/prometheus/

# 디렉토리가 존재하지만 권한 문제가 있는 경우 prometheus 사용자에게 적절한 권한 부여
sudo chown -R prometheus:prometheus /var/lib/prometheus/
sudo chmod -R 775 /var/lib/prometheus/

# 서비스 재시작
sudo systemctl restart prometheus

# 로그 확인
sudo journalctl -u prometheus -f

이 방법으로 private02에서는 문제를 해결했는데, private01에서는 또 status를 조회했을 때 failed가 떴다(대체왜?....)

 


오류코드 #3

요약 : `listen tcp 0.0.0.0:9090: bind: address already in use` = Prometheus가 사용하려는 포트 9090이 이미 다른 프로세스에 의해 사용 중이어서 포트 바인딩 불가함

ubuntu@a-private-01:~$ sudo journalctl -u prometheus -f
-- Logs begin at Thu 2024-08-08 16:39:46 KST. --
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.806Z caller=main.go:499 level=info msg="No time or size retention was set so using the default time retention" duration=15d
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.807Z caller=main.go:543 level=info msg="Starting Prometheus Server" mode=server version="(version=2.39.1, branch=HEAD, revision=dcd6af9e0d56165c6f5c64ebbc1fae798d24933a)"
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.807Z caller=main.go:548 level=info build_context="(go=go1.19.2, user=root@273d60c69592, date=20221007-15:57:09)"
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.807Z caller=main.go:549 level=info host_details="(Linux 5.4.0-177-generic #197-Ubuntu SMP Thu Mar 28 22:45:47 UTC 2024 x86_64 a-private-01 (none))"
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.807Z caller=main.go:550 level=info fd_limits="(soft=524288, hard=524288)"
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.808Z caller=main.go:551 level=info vm_limits="(soft=unlimited, hard=unlimited)"
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.812Z caller=web.go:559 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090
Aug 09 15:26:47 a-private-01 prometheus[8342]: ts=2024-08-09T06:26:47.814Z caller=main.go:794 level=error msg="Unable to start web listener" err="listen tcp 0.0.0.0:9090: bind: address already in use"
Aug 09 15:26:47 a-private-01 systemd[1]: prometheus.service: Main process exited, code=exited, status=1/FAILURE
Aug 09 15:26:47 a-private-01 systemd[1]: prometheus.service: Failed with result 'exit-code'.

(그래도 얘는 다행히 address already in use 오류였다)

 

# 포트 사용 중인 프로세스 확인
sudo lsof -i :9090

# 포트를 점유한 프로세스 종료
sudo kill <PID>

# Prometheus의 포트 변경(옵션)
sudo nano /etc/systemd/system/prometheus.service
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus/ \
  --web.listen-address=":9091"  # 9091 : 사용할 새로운 포트 번호
  
# 시스템 데몬 리로드, Prometheus 서비스 재시작
sudo systemctl daemon-reload
sudo systemctl restart prometheus

# 서비스 상태 확인
sudo systemctl status prometheus

이 방식으로 성공적으로 프로메테우스 active status 를 띄울 수 있었다 . . . ㅎㅎ