재기동 (1)

안녕하세요, 케이치입니다.


오늘은 리눅스 서버의 재부팅/재기동 또는 언제 shutdown이 됐었는지를 확인하는 방법을 배웠습니다.


그다지 많이 쓸 일은 없는 명령어이긴 한데 웹사이트에 접속이 안되서 확인해보다가 알게되었네요.


우선 웹서버로 접속을 하는데 아래와 같은 메시지가 떴습니다.

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.


뭔소린가 봤더니 점검 중이거나 용량문제로 인해서 접속할 수 없다라는 말이네요.


그래서 서버에 접속해서 혹시 디렉토리 용량이 부족한가 봤는데 아니었습니다.


그럼 왜 안되는지 에러로그부터 확인해야겠죠.


웹서버의 에러로그를 봤는데 에러가 없습니다 ㄷㄷ;;;;; 뭐지 이건;;;


이제 실제 웹앱이 올라가있는 WAS 기동상태를 확인합니다.


두둥!!!! WAS가 죽었네요 ㅜㅜ


뭐지 난 죽인적이 없는데....그래서 다시 WAS의 에러로그를 확인하는데 헐;;;; 여기도 에러로그는 없습니다. 마지막까지 열심히 사람들의 요청에 부응한 흔적밖에 없네요.


뭐지? 서버가 재부팅 됐나? 어떻게 확인하지?


리눅스 서버의 재기동 상태를 확인하는 명령어는 두 가지가 있습니다.


첫째, last 명령어.

둘째, who 명령어.


[keichee@server1 ~]$ last reboot

reboot   system boot  3.10.0-514.16.1. Thu Jun 22 17:13 - 11:32 (140+18:19)

reboot   system boot  3.10.0-327.36.3. Wed Jan  4 22:14 - 17:11 (168+18:57)

reboot   system boot  3.10.0-327.36.3. Thu Nov 17 14:41 - 17:11 (217+02:30)

reboot   system boot  3.10.0-327.36.3. Thu Nov 17 15:06 - 17:11 (217+02:04)

reboot   system boot  3.10.0-327.36.3. Thu Nov 17 11:01 - 17:11 (217+06:09)


last reboot 명령어는 마지막으로 재기동한 시간이 언제인지를 desc 정렬하여 출력합니다. 즉, 제일 위에 있는게 가장 최근에 재기동한 시간을 말합니다.


last reboot 말고도 last shutdown 명령어로 언제 셧다운됐었는지 확인이 가능합니다. 


last -x 는 어떤 사용자가 서버에 접속해서 얼마나 있었는지 확인이 가능합니다. run level이 어떻게 바뀌었는지도 확인이 가능하죠.


[keichee@server1 ~]$ last -x

keichee    pts/0        210.145.229.14   Fri Nov 10 11:09   still logged in

keichee    pts/0        210.145.229.14   Tue Nov  7 09:17 - 14:14  (04:57)

keichee    pts/0        210.145.229.143   Mon Nov  6 09:19 - 18:27  (09:07)

keichee    pts/2        204.130.143.176  Thu Nov  2 22:04 - 00:26  (02:21)

keichee    pts/1        103.170.103.116  Thu Nov  2 22:04 - 00:26  (02:22)

runlevel (to lvl 3)   3.10.0-514.16.1. Thu Jun 22 17:13 - 11:35 (140+18:22)
reboot   system boot  3.10.0-514.16.1. Thu Jun 22 17:13 - 11:35 (140+18:22)
shutdown system down  3.10.0-327.36.3. Thu Jun 22 17:11 - 17:13  (00:01)


그럼 두 번째 명령어였던 who는 어떻게 쓸까요?


기본적으로 who를 쓸 때는 현재 내가 어떤 사용자로 접속을 했는지 확인하기 위해서 사용할 수 있죠.


[keichee@server1 ~]$ who

keichee    pts/0        2017-11-10 11:09 (118.145.269.124)


help 옵션으로 어떤 옵션을 추가로 줄 수 있는지 한번 볼까요?


[keichee@server1 ~]$ who  --help

Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]

Print information about users who are currently logged in.


  -a, --all         same as -b -d --login -p -r -t -T -u

  -b, --boot        time of last system boot

  -d, --dead        print dead processes

  -H, --heading     print line of column headings

  -l, --login       print system login processes

      --lookup      attempt to canonicalize hostnames via DNS

  -m                only hostname and user associated with stdin

  -p, --process     print active processes spawned by init

  -q, --count       all login names and number of users logged on

  -r, --runlevel    print current runlevel

  -s, --short       print only name, line, and time (default)

  -t, --time        print last system clock change

  -T, -w, --mesg    add user's message status as +, - or ?

  -u, --users       list users logged in

      --message     same as -T

      --writable    same as -T

      --help     display this help and exit

      --version  output version information and exit


옵션 중에 -b 옵션이 마지막 시스템 부팅 시간을 출력한다는 것을 확인할 수 있습니다.


그럼 한 번 써보죠.

[keichee@server1 ~]$ who -b

         system boot  2017-06-22 17:13

17년 6월 22일 17시 13분에 시스템이 기동됐음을 알 수 있습니다.


이상입니다.


오늘은 여기까지~