linux实时更新时间

来源:互联网 发布:狮王手柄编程软件 编辑:程序博客网 时间:2024/06/12 00:53

linux中更新时间是用的是ntp,更新服务器自己去找个

看看有没有安装ntp:rpm -q ntp

没有安装的话,yum安装或者rpm安装:yum install -y ntp

设置当前时区:cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

网上传说只要看:cat /etc/sysconfig/clock文件就能知道现在是什么时区,我自己操作修改了好像没用,也许是要重启之后才能生效吧。不重启就直接改上面那个吧,呵呵。顺便把这问题改过来,以免重启之后出问题。也可以用tzselect 选择时区,但是不知道更新到哪里去了。用strings /etc/localtime可以看到现在使用的是哪个时区。

在cornd里配置*/30 * * * * /usr/sbin/ntpdate 210.72.145.44就能每半小时更新一次时间了(这个ip为中国的时间服务器)。

xenserver要通过ntpdate来更新时间要把ntpd服务关掉。ntpd本来也是更新时间的,但是好像一直没有更新成功,还是用命令配置在conrd里面吧。

配置好之后还要用clock -w把时间写入bios不然重启有可能丢失时间。clock -r或者hwclock -r可以查看硬件时间,linux中分系统时间和硬件时间。

最后还有一个问题没有解决:

用date -s修改时间后显示时间还是错误的,然后尝试clock -w写入bios报错如下:

Cannot access the Hardware Clock via any known method.
Use the --debug option to see the details of our search for an access method.

网上说与内核有关http://hi.baidu.com/imake/blog/item/10e6b0defe3f5a5fcdbf1ad0.html