给树莓派安装看门狗的两种方法

树莓派的CPU是保护有硬件看门狗的,可以通过安装模块和值守程序来实现看门狗防止树莓派死机。

安装方法一:

watchdog.sh的源码:

#!/usr/bin/env bash echo “[+] Activating Temperature Sensor” modprobe bcm2708_wdog echo “bcm2708_wdog” >> /etc/modules echo “[+]Installing Watchdog” apt-get -y install watchdog chkconfig echo “[+]Setting Up Watchdog” chkconfig watchdog on sed -i ‘s/#max-load-1[^5]/max-load-1\ /g’ /etc/watchdog.conf sed -i ‘s/#\(watchdog-device\t[\ ]*\)\=/\1\t\=/g’ /etc/watchdog.conf sed -i ‘s/#\(temperature-device[\ ]*\)\=/\1\ \= \/sys\/class\/thermal\/thermal\_zone0\/temp/g’ /etc/watchdog.conf sed -i ‘s/#\(max-temperature[\ ]*\)\=\ 120/\1\ \=\ 75000/g’ /etc/watchdog.conf sed -i ‘s/#\(interval[\ ]*\)\=\ 1/\1\ \=\ 10 /g’ /etc/watchdog.conf /etc/init.d/watchdog start

运行:

sudo sh watchdog.sh

安装方法二:

1.加载看门狗模块,编辑/etc/modules文件,添加一行“bcm2708_wdog”

sudo modprobe bcm2708_wdog sudo nano /etc/modules

添加一行”bcm2708_wdog”

2.安装系统配置软件和看门狗程序

sudo apt-get install chkconfig watchdog

3.配置看门狗程序,编辑“/etc/watchdog.conf”文件

sudo nano /etc/watchdog.conf

去掉 watchdog-device = /dev/watchdog 前的#号,让看门狗设备对应树莓派的硬件看门狗

去掉 max-load-1 = 24 前的#号,当1分钟load进程超过24个的时候就会重启

还可以设置高温复位:

去掉

temperature-device =

max-temperature = 120

前的#号,改为

temperature-device = /sys/class/thermal/thermal_zone0/temp

max-temperature = 80000

温度超过80度就会引起重启,保护CPU。

配置完后,保存(Ctrl+O),退出(ctrl+x)。

4.配置看门狗程序,开机自动运行

chkconfig watchdog on

5.启动看门狗

sudo /etc/init.d/watchdog start