- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2021-07-18T08:54:54+09:00","default:kuji","kuji")
#author("2022-09-16T16:42:34+09:00","default:kuji","kuji")
CONTENTS
#contents
----
Lastmodified &lastmod;
----
*pingが通らなくなると、自動的に再起動するスクリプト [#vccf0ed4]
#!/bin/sh
TARGET_IP="219.117.246.193"
STR_LOST="100.0% packet loss"
while [ 1 ]
do
PING_RESULT=`/sbin/ping -c 3 $TARGET_IP|grep "packet loss"|sed "s/^.*, //"`
if [ "$PING_RESULT" = "$STR_LOST" ]; then
echo "*** em0 connect lost ***"
date >>/var/log/ping_reboot.log
date|mail -s ping_reboot root
/sbin/reboot
else
echo "*** em connect ok ***"
fi
sleep 30
done
exit 0
【参考URL】http://www2k.biglobe.ne.jp/~motoi/ocn/ocn.cgi
/root/bin/ping_reboot.sh
#!/bin/sh
TARGET_IP="219.117.246.193"
#TARGET_IP="219.117.246.204"
STR_LOST="100.0% packet loss"
while [ 1 ]
do
if [ -e /var/run/watchdogd.pid ]; then
PING_RESULT=`/bin/ping -c 3 $TARGET_IP|grep "packet loss"|sed "s/^.*, //"`
else
PING_RESULT=$STR_LOST
fi
if [ "$PING_RESULT" = "$STR_LOST" ]; then
echo "*** em0 connect lost ***"
if [ -e /var/run/watchdogd.pid ]; then
kill -KILL `cat /var/run/watchdogd.pid`
rm -f /var/run/watchdogd.pid
sleep 2
fi
date >>/var/log/ping_reboot.log
date|mail -s ping_reboot root
/sbin/reboot
fi
sleep 30
echo "*** em connect ok ***"
done
exit 0
/etc/crontab
@reboot root /root/bin/check.sh && /root/bin/ping_reboot.sh
----
https://wiki.rookie-inc.com/os/freebsd/tips
*NICの watchdog timeout [#i6c0973e]
大量のトラフィックを流すとこんな感じでネットワークが死ぬことがあります。
msk0: watchdog timeout
msk0: link state changed to DOWN
msk0: link state changed to UP
msk0: watchdog timeout (missed Tx interrupts) -- recovering
この例ではMarvellですがre0(realtek:蟹)とかIntelでも発生します。
googleでお伺いを立ててみましたが、どうもずいぶん前から有る問題のようで、数年前から同じような質問が出ています。
で、どうも根深すぎてFixもお手上げのような雰囲気なのが…orz
で、対症療法ですが、以下の設定でとりあえずは抑えられます。
# cat /boot/loader.conf
hw.msk.msi_disable="1"
FreeBSD10でもHP G6 の内蔵 NIC等、同様のケースがあるようです
bge0: watchdog timeout -- resetting
bge0: link state changed to DOWN
bge0: link state changed to UP
# cat /boot/loader.conf
hw.bge.allow_asf="0"
----
https://forums.freebsd.org/threads/looking-for-a-network-monitoring-daemon.76550/
シェルスクリプト /root/bin/pingorrestart.sh:
Bash:
#!/bin/sh
RIP=`tail -15 /var/db/dhclient.leases.em0 | sed -n '/ option routers /{s///;s/ .*//;s/;//;p;}'`
ping -c1 -t1 $RIP > /dev/null 2>&1
if [ "$?" != "0" ] ; then
/etc/rc.d/netif restart em0 > /dev/null 2>&1
fi
cronジョブディレクティブ:
コード:
#
# ping the router every 5 minutes and restart the network interface in case the ping fails
*/5 * * * * root /root/bin/pingorrestart.sh
*em0 down [#o4b874f4]
SUN1
https://forum.opnsense.org/index.php?PHPSESSID=o4l684klodficjaef6d161pbri&topic=7580.msg34822#msg34822
https://forum.opnsense.org/index.php?topic=7601.0
EMシリーズNICのパフォーマンスと安定性を向上させるために、EMドライバー固有の調整変数を適用することもできます。これらの設定を試してみたい場合は、以下に文書化しています。保存したら、これらすべてを完全に適用するには再起動が必要です。デュアルポートEM構成の行を含めました。ポートがさらにある場合は、システムに一致するように以下の値のいくつかを調整する必要があります。
/boot/loader.conf.local内(まだ存在しない場合は、このファイルを作成する必要がある場合があります):
hw.em.num_queues=0
hw.em.txd="2048"
hw.em.rxd="2048"
net.link.ifqmaxlen="4096"
hw.em.enable_msix=1
hw.pci.enable_msix=1
dev.em.0.fc=0
dev.em.1.fc=0
hw.em.rx_process_limit="-1"
hw.em.tx_process_limit="-1"
----
https://www.google.co.jp/#lr=lang_ja&tbs=lr:lang_1ja&q=FreeBSD+%2Fetc%2Frc.conf+em0+tso
http://matsup.blogspot.jp/2012/12/freebsd-90-ipfw-natd-em.html
http://www.bsddiary.net/d/20100324.html
*DEVD [#j15b0458]
NEC Express5800/GT110b
**オンボードNIC em0 が高負荷で落ちるので、これを監視して落ちたらシステム・リブートさせたい。 [#q26ec835]
FreeBSD 10.2-Rから 11.0-CURRENTへ変更したけど、やっぱり落ちる。ということで、devdを使って見ることにした。
http://www.yosbits.com/opensonar/rest/man/freebsd/man/ja/man5/devd.conf.5.html
http://www.on-sky.net/~hs/misc/?Raspberry+Pi+HA+Server+with+FreeBSD
http://www.yosbits.com/opensonar/rest/man/freebsd/man/ja/man8/devd.8.html?l=ja
devdはシステムに初めから入っているので、
/etc/rc.conf
devd_enable="YES"
として起動するように設定。
**監視対象とアクションを設定。 [#w2f0b681]
/etc/devd/em0.conf
#system=IFNET, subsystem=fxp0, type=LINK_UP
notify 0 {
match "system" "IFNET";
match "subsystem" "em0";
match "type" "LINK_DOWN";
action "/root/bin/reboot.sh";
};
/root/bin/reboot.sh
#!/bin/sh
tail -100 /var/log/all.log | mail -s "System was Rebooted" root@localhost \
&& /sbin/reboot
リブート用のスクリプトを書いておく。改行コードがLFでないと動かないので注意。
読み込むかどうかテスト
root@blackhole:~ # devd -d
Parsing /etc/devd.conf
setting scsi-controller-regex=(aac|adv|adw|aha|ahb|ahc|ahd|aic|amd|amr|asr|bt|ciss|ct|dpt|esp|ida|iir|ips|isp|mlx|mly|mpt|ncr|ncv|nsp|stg|sym|trm|wds)[0-9]+
setting wifi-driver-regex=(ath|bwi|bwn|ipw|iwi|iwm|iwn|malo|mwl|ral|rsu|rum|run|uath|upgt|ural|urtw|urtwn|wi|wpi|wtap|zyd)[0-9]+
Parsing files in /etc/devd
Parsing /etc/devd/em0.conf
Parsing files in /usr/local/etc/devd
devd: Can't open devctl device /dev/devctl: Device busy
起動中のdevdの順番は出来るだけ遅い方がよさげ(NICがLink_UPしてからでないと無限リブートになる)なので、
/etc/rc.d/devd
# REQUIRE: netif ldconfig ntpd
を追加して
#!/bin/sh
#
# $FreeBSD: head/etc/rc.d/devd 282145 2015-04-28 13:13:23Z glebius $
#
# PROVIDE: devd
# REQUIRE: netif ldconfig ntpd ←これ 追加したntpd
# BEFORE: NETWORKING mountcritremote
# KEYWORD: nojail shutdown
: :
としてみる。
で、em0がリンクダウンすると、こんなメールがやってくる・・・
To: root@localhost.smb.net
Subject: System was Rebooted
Message-Id: <20151014012601.DFD9614A63AE@blackhole.smb.net>
Date: Wed, 14 Oct 2015 10:26:01 +0900 (JST)
From: root@blackhole.smb.net (Charlie Root)
Oct 14 10:22:00 blackhole /usr/sbin/cron[63419]: (operator) CMD (/usr/libexec/save-entropy)
Oct 14 10:25:00 blackhole /usr/sbin/cron[63432]: (root) CMD (/usr/libexec/atrun)
Oct 14 10:25:00 blackhole /usr/sbin/cron[63433]: (munin) CMD (/usr/local/bin/munin-cron)
Oct 14 10:26:01 blackhole kernel: em0: Watchdog timeout Queue[0]-- resetting
Oct 14 10:26:01 blackhole kernel: Interface is RUNNING and ACTIVE
Oct 14 10:26:01 blackhole kernel: em0: TX Queue 0 ------
Oct 14 10:26:01 blackhole kernel: em0: hw tdh = 795, hw tdt = 869
Oct 14 10:26:01 blackhole kernel: em0: Tx Queue Status = -2147483648
Oct 14 10:26:01 blackhole kernel: em0: TX descriptors avail = 949
Oct 14 10:26:01 blackhole kernel: em0: Tx Descriptors avail failure = 0
Oct 14 10:26:01 blackhole kernel: em0: RX Queue 0 ------
Oct 14 10:26:01 blackhole kernel: em0: hw rdh = 680, hw rdt = 679
Oct 14 10:26:01 blackhole kernel: em0: RX discarded packets = 0
Oct 14 10:26:01 blackhole kernel: em0: RX Next to Check = 680
Oct 14 10:26:01 blackhole kernel: em0: RX Next to Refresh = 679
Oct 14 10:26:01 blackhole kernel: em0: link state changed to DOWN
----
Total access &counter(total);:本日 &counter(today);:昨日 &counter(yesterday);
#counter([total|today|yesterday]);