리눅스 와치독(linux watchdog)

와치독 타이머(watchdog timer, WDT)는, 하드웨어 또는 소프트웨어 오류가 발생하는 경우 (watchdog 타이머를 리셋하지 못하게 되는 경우), 일정 시간이 지난후 시스템을 정상화시키기 위한 조치(재부팅 등)를 수행하는 기능을 가진다.

리눅스에서는 보통 watchdog 하드웨어를 이용하거나, 하드웨어가 없는 경우에는 softdog을 통해 watchdog 기능을 이용 할 수 있다. 여기서는 kvm guest에 intel 6300esb watchdog을 설정하여 구성해 본다.

작업환경: KVM guest
OS: CentOS7 minimal(kvm guest)
watchdog device: kvm guest에서 watchdog장치 추가(intel 6300esb)

  • watchdog 설치
# yum install watchdog

설치후 /dev/watchdog 장치가 생성되었는지 확인하고, 없을 경우 재부팅후 아래 사항을 확인한다.

  • 장치확인
# dmesg | grep -i 6300
[    7.208215] i6300esb: Intel 6300ESB WatchDog Timer Driver v0.05
[    7.208603] i6300esb: initialized (0xffffc9000072c000). heartbeat=30 sec (nowayout=0)

# ls -al /dev/watchdog
crw-------. 1 root root 10, 130  1월 26 14:35 /dev/watchdog
  • 설정

설정은 /etc/watchdog.conf 화일을 수정하면 된다. 아래와 같이 ping을 이용하도록 설정했지만, 시스템 부하에 따른 설정도 가능하다.

# grep -v \# /etc/watchdog.conf | sort | uniq

file			= /var/log/messages
interface		= eth0
ping			= 192.168.100.1
ping			= 192.168.100.14
priority		= 1
realtime		= yes
watchdog-device	= /dev/watchdog

    설정후, watchdog 서비스를 실행한다.

    # systemctl start watchdog.service

    재부팅후 부팅시 watchdog 서비스를 자동으로 실행하려면 아래 명령어를 실행한다. 다만, watchdog 테스트를 충분히 진행한 후 아래 설정을 하는것을 권한다. 만약 watchdog 설정이 잘못되어 재부팅된 경우(ping 이 가지 않는 호스트를 설정했다거나 하는 경우) 재부팅후 다시 watchdog이 실행되면 또 다시 재부팅이 될 수 있기 때문이다.

    # systemctl enable watchdog.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/watchdog.service to /usr/lib/systemd/system/watchdog.service.
  • 테스트

네트워크를 절단하면 잠시후 재부팅 됨을 확인 할 수 있다. 재부팅 후 watchdog 로그를 확인해 보면 아래와 같다.

Jan 26 15:13:39 localhost systemd: Started watchdog daemon.
Jan 26 15:19:06 localhost watchdog[2040]: no response from ping (target: 192.168.100.1)
Jan 26 15:19:07 localhost watchdog[2040]: shutting down the system because of error 101
Jan 26 15:20:05 localhost kernel: NMI watchdog: disabled (cpu0): hardware events not enabled
Jan 26 15:20:10 localhost kernel: i6300esb: Intel 6300ESB WatchDog Timer Driver v0.05

아래처럼 인위적으로 커널 패닉상태를 만들어도 시스템이 재부팅 된다.

# echo c >/proc/sysrq-trigger

——-

참고: KVM guest에 watchdog 설정하는 방법

virt-manager를 사용하거나,
virt-manager -> 게스트선택 -> 열기 -> 상세정보 -> 하드웨어추가 -> watchdog

virsh edit guest_name 하여 편집하는 방법이 있음.
KVM 호스트에서(guest 아님) 아래처럼 편집.

# virsh edit watchdog_guest
.....

    <watchdog model='i6300esb' action='reset'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </watchdog>
...

——–

답글 남기기

Your email address will not be published.