背景
之前买了个树莓派2,闲置了很久,最近正好有NAS需求,就打算拿它装个OpenMediaVault
玩玩。
安装过程不表。
事实上是在使用过程中,遇到的某个问题比较奇葩,就拿来分享了。
林尽水源
在网页端对OMV进行配置时,经常会遇到一个弹窗monit: Cannot connect to the monit daemon. Did you start it with http support?
。
详细错误代码如下:
exception 'OMVException' with message 'Failed to execute command 'export LANG=C; monit restart collectd 2>&1': monit: Cannot connect to the monit daemon. Did you start it with http support?' in /usr/share/php/openmediavault/monit.inc:113
Stack trace:
#0 /usr/share/php/openmediavault/monit.inc(70): OMVMonit->action('restart', 'collectd', false)
#1 /usr/share/openmediavault/engined/module/collectd.inc(53): OMVMonit->restart('collectd')
#2 /usr/share/openmediavault/engined/rpc/config.inc(206): OMVModuleCollectd->startService()
#3 [internal function]: OMVRpcServiceConfig->applyChanges(Array, Array)
#4 /usr/share/php/openmediavault/rpcservice.inc(125): call_user_func_array(Array, Array)
#5 /usr/share/php/openmediavault/rpcservice.inc(158): OMVRpcServiceAbstract->callMethod('applyChanges', Array, Array)
#6 /usr/share/openmediavault/engined/rpc/config.inc(224): OMVRpcServiceAbstract->callMethodBg('applyChanges', Array, Array)
#7 [internal function]: OMVRpcServiceConfig->applyChangesBg(Array, Array)
#8 /usr/share/php/openmediavault/rpcservice.inc(125): call_user_func_array(Array, Array)
#9 /usr/share/php/openmediavault/rpc.inc(79): OMVRpcServiceAbstract->callMethod('applyChangesBg', Array, Array)
#10 /usr/sbin/omv-engined(500): OMVRpc::exec('Config', 'applyChangesBg', Array, Array, 1)
#11 {main}
ssh到OMV
终端,输入命令:monit status
,似乎错误信息也一样:
monit: error connecting to the monit daemon
在这种情况下,OMV
就无法应用配置,必须解决这问题。
初仿佛若有光
于是去google上找啊,找啊,终于找到一篇帖子,遇到了相似的问题(竟然不是StackOverflow,差评!)
Because ntpdate is installed in the image. Both ntp server and ntpdate cannot be installed at the same time. Also, the config for the ntp server does not work….
apt-get –purge remove ntpdate
Then in the OMV web gui set your timezone because after these changes you cannot set it again.
then edit /etc/ntp.conf:
remove these lines:
server 127.127.1.0 # Local clock
fudge 127.127.1.0 stratum 12
server pool.ntp.org iburst
And replace with these:
server 0.no.pool.ntp.org iburst
server 1.no.pool.ntp.org iburst
server 2.no.pool.ntp.org iburst
server 3.no.pool.ntp.org iburst
Then you can:
service ntp restart
Do not disable/enable in the OMV web gui again. The mkconf file for the ntp service will overwrite thesechanges. There need to be some updates so it works properly with the rpi 2.
Your logs files and dates at boot will be all messed up with wrong dates until you install a RTC module. After boot it takes some minutes before the ntp server will update the time/date. With a RTC module everything is perfect at boot.
总结几点就是:
Monit
的错误和系统时间有关- (检查了一下,确实系统当前时间错误)
ntpdate
与ntp server
有冲突,不能同时安装- (检查了一下,ntp服务启动失败)
OMV
自带的ntp配置/etc/ntp.conf
有错误- 你应该安装
RTC
模块
复行数十步
按照前面这位贤者的建议,我分别进行了一下几个测试:
- 测试一: 手动修改当前时间,卸载
ntpdate
,关闭ntp
服务- 重启以后,时间丢失
- 测试二: 卸载
ntpdate
,不修改ntp
配置文件ntp
服务正常启动,时间同步正确- 重启以后,
ntp
服务正常启动,时间无法同步
- 测试三: 卸载
ntpdate
,修改ntp
配置文件ntp
服务正常启动,时间同步正确- 重启以后,
ntp
服务正常启动,时间无法同步
- 测试四: 运行
ntpdate
,强制同步- 时间同步正确
- 重启以后,
ntp
服务不能正常启动,时间无法同步
测试后发现,因为树莓派本身的硬件限制,系统重启后会丢失当前时间。
尽管开启了ntp
服务,但是如果系统当前时间与真实时间跨度太大,则不会进行同步。
所以只能放弃ntp server
,转而使用ntpdate
来强制同步时间,并设置开机启动。
代码如下:
# 设置开机同步时间,注意: 添加的代码必须在`exit 0`之前
echo '/usr/sbin/ntpdate 0.cn.pool.ntp.org' >> /etc/rc.local
# 设置同步任务,每隔5分钟同步一次时间
# 编辑crontab,并保存
crontab -e
*/5 * * * * /usr/sbin/ntpdate 0.cn.pool.ntp.org
重启系统,系统时间已经正确了。
在网页端对OMV
重新进行配置。WTF,怎么还是monit
这个问题!
豁然开朗
登入终端,重新进行检查:
root@raspberrypi:~# date
Dec 16 11:12:04 CST 2015
root@raspberrypi:~# monit status
monit: error connecting to the monit daemon
到这里时,我当时确实很疑惑,明明系统时间已经正确了,为什么monit
还是报错呢。
突然灵光乍现,重新启动monit
服务,然后十几秒过后:
root@raspberrypi:~# monit status
The Monit daemon 5.4 uptime: 18m
System 'localhost'
status Running
monitoring status Monitored
load average [0.00] [0.01] [0.05]
cpu 0.0%us 0.1%sy 0.0%wa
memory usage 55424 kB [5.5%]
swap usage 0 kB [0.0%]
data collected 16 Dec 2015 11:12:17
...
Process 'collectd'
status Running
monitoring status Monitored
pid 2535
parent pid 1
uptime 18m
children 0
memory kilobytes 4224
memory kilobytes total 4224
memory percent 0.4%
memory percent total 0.4%
cpu percent 0.0%
cpu percent total 0.0%
data collected 16 Dec 2015 11:12:17
在此个人分析,在monit
服务启动时,系统时间还未同步,所以monit
初始化失败。只要保证在时间同步后,再重启monit
服务应该就可以了。
# 在强制同步时间后,再重启monit服务
echo '/etc/init.d/monit restart' >> /etc/rc.local
重启系统,一切正常。END!