본문 바로가기
프로그래밍

sevice 로그 확인하기

by choihyuunmin 2023. 4. 7.

apache 웹서버 설치후 기동하는데 실패 로그를 확인할 일이 생겼다. 보통 어플리케이션이라면 로그 경로를 따로 지정해주고 찾아들어가면 되지만, 시스템 service로 등록해놓은 동작이기 때문에 system로그를 확인하는 방법을 사용했다.

 

1. systemctl status 서비스

[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2023-04-06 18:28:36 KST; 16h ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 15323 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 15304 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 15304 (code=exited, status=1/FAILURE)

Apr 06 18:28:36 epis-iris systemd[1]: Starting The Apache HTTP Server...
Apr 06 18:28:36 epis-iris httpd[15304]: [Thu Apr 06 18:28:36.697765 2023] [core:error] [pid 15304] (EAI 2)Name or service not known: AH00547: Could not resolve host name IP -- ignoring!
Apr 06 18:28:36 epis-iris httpd[15304]: [Thu Apr 06 18:28:36.701160 2023] [core:error] [pid 15304] (EAI 2)Name or service not known: AH00547: Could not resolve host name IP -- ignoring!
Apr 06 18:28:36 epis-iris httpd[15304]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
Apr 06 18:28:36 epis-iris systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Apr 06 18:28:36 epis-iris kill[15323]: kill: cannot find process ""
Apr 06 18:28:36 epis-iris systemd[1]: httpd.service: control process exited, code=exited status=1
Apr 06 18:28:36 epis-iris systemd[1]: Failed to start The Apache HTTP Server.
Apr 06 18:28:36 epis-iris systemd[1]: Unit httpd.service entered failed state.
Apr 06 18:28:36 epis-iris systemd[1]: httpd.service failed.

 

systemctl status 를 통해 서비스의 현재 상태를 확인할 수 있다.

현재 상태를 간략하게 확인할 수 있고, 로그도 실패 부분만 찍어주기 때문에 한눈에 볼 수 있다는 장점이 있지만, 자세한 로그를 볼 수 없다는 단점이 있다.

 

2. journalctl -xe

Apr 07 10:58:00 localhost kubelet[15980]: E0407 10:58:00.011015   15980 manager.go:1123] Failed to create existing container: /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-poda593bc
Apr 07 10:58:00 localhost kubelet[15980]: E0407 10:58:00.012089   15980 manager.go:1123] Failed to create existing container: /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod575dfa
lines 1030-1100/1100 (END)

service로 등록해놓은 프로세스들의 로그를 마지막 부분만 볼 수 있다. 맨 밑의 lines를 통해 지금 보고 있는 위치를 확인할 수 있다. 최근 실행한 프로세스들의 로그를 확인할 수 있고, 문제가 생긴 부분을 빠르게 확인할 수 있다는 장점이 있지만, 서비스로 등록해놓은 여러 프로세스들의 로그가 뒤섞여 있기 때문에 특정 프로세스의 로그를 찾기 어렵다는 단점이 있다.

 

3. journalctl -u 서비스

[root@localhost ~]# journalctl -u httpd
-- Logs begin at Sun 2023-03-05 10:39:36 KST, end at Fri 2023-04-07 11:00:00 KST. --
Apr 05 11:00:01 epis-iris systemd[1]: Starting The Apache HTTP Server...
Apr 05 11:00:01 epis-iris httpd[29367]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.106.50. Set the 'ServerName' directive globally to sup
Apr 05 11:00:01 epis-iris httpd[29367]: httpd (pid 28661) already running
Apr 05 11:00:01 epis-iris kill[29441]: kill: cannot find process ""
Apr 05 11:00:01 epis-iris systemd[1]: httpd.service: control process exited, code=exited status=1
Apr 05 11:00:01 epis-iris systemd[1]: Failed to start The Apache HTTP Server.
Apr 05 11:00:01 epis-iris systemd[1]: Unit httpd.service entered failed state.
Apr 05 11:00:01 epis-iris systemd[1]: httpd.service failed.
Apr 05 11:01:00 epis-iris systemd[1]: Starting The Apache HTTP Server...
Apr 05 11:01:00 epis-iris httpd[32553]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.106.50. Set the 'ServerName' directive globally to sup
Apr 05 11:01:00 epis-iris httpd[32553]: httpd (pid 28661) already running
Apr 05 11:01:00 epis-iris kill[32562]: kill: cannot find process ""
Apr 05 11:01:00 epis-iris systemd[1]: httpd.service: control process exited, code=exited status=1
Apr 05 11:01:00 epis-iris systemd[1]: Failed to start The Apache HTTP Server.
Apr 05 11:01:00 epis-iris systemd[1]: Unit httpd.service entered failed state.
Apr 05 11:01:00 epis-iris systemd[1]: httpd.service failed.
Apr 05 11:04:10 epis-iris systemd[1]: Starting The Apache HTTP Server...
Apr 05 11:04:11 epis-iris httpd[11017]: httpd (pid 28661) already running
Apr 05 11:04:11 epis-iris kill[11019]: kill: cannot find process ""
Apr 05 11:04:11 epis-iris systemd[1]: httpd.service: control process exited, code=exited status=1
Apr 05 11:04:11 epis-iris systemd[1]: Failed to start The Apache HTTP Server.
Apr 05 11:04:11 epis-iris systemd[1]: Unit httpd.service entered failed state.
Apr 05 11:04:11 epis-iris systemd[1]: httpd.service failed.
Apr 05 11:04:48 epis-iris systemd[1]: Starting The Apache HTTP Server...
Apr 05 11:04:48 epis-iris httpd[13067]: httpd (pid 28661) already running
Apr 05 11:04:48 epis-iris kill[13069]: kill: cannot find process ""
Apr 05 11:04:48 epis-iris systemd[1]: httpd.service: control process exited, code=exited status=1
Apr 05 11:04:48 epis-iris systemd[1]: Failed to start The Apache HTTP Server.
Apr 05 11:04:48 epis-iris systemd[1]: Unit httpd.service entered failed state.
Apr 05 11:04:48 epis-iris systemd[1]: httpd.service failed.
Apr 05 11:11:09 epis-iris systemd[1]: Starting The Apache HTTP Server...
Apr 05 11:11:09 epis-iris httpd[1716]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Apr 05 11:11:09 epis-iris httpd[1716]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Apr 05 11:11:09 epis-iris httpd[1716]: no listening sockets available, shutting down
Apr 05 11:11:09 epis-iris httpd[1716]: AH00015: Unable to open logs
Apr 05 11:11:09 epis-iris systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Apr 05 11:11:09 epis-iris kill[1718]: kill: cannot find process ""
Apr 05 11:11:09 epis-iris systemd[1]: httpd.service: control process exited, code=exited status=1
Apr 05 11:11:10 epis-iris systemd[1]: Failed to start The Apache HTTP Server.

특정 유닛의 로그만 확인할 수 있다. journalctl -xe 와 systemctl status 서비스 의 기능을 합친 것 같은 화면을 볼 수 있다. 위 명령어를 통해 문제가 생긴 특정 프로세스의 로그를 확인하여 문제를 해결하면 된다.

 

 

그래도 가장 간편한건 해당 프로그램이 찍어주는 로그를 확인하는게 편리하다