1 date命令:
#date
显示系统时间
2hwclock命令 (即hardwareclock系统硬件时间)
#hwclock
显示硬件时间
#hwclock -w
将系统时间写入到系统硬件当中
3ntpdate
ntpdate 是一个linux时间同步服务软件,具体的详细资料请参考下百度,有很多详细的资料
第二、查看本机是否安装ntpdate服务,如果没有安装,请 yum install -y ntpdate
第三、同步时间
1 输入ntpdate timenistgov同步网络时间
结果:3 Jun 15:42:39 ntpdate[4721]: adjust time server 21111519421 offset -0005885 sec
出现上述结果代表时间同步成功,上面的大致意思为调整时间为服务器21111519421的时间,相差-0005885秒的时间
如果上面timenistgov服务器同步不了,可以换下面几个时间服务器试试:
timenistgov
timenurinet
0asiapoolntporg
1asiapoolntporg
2asiapoolntporg
3asiapoolntporg
2同步时间成功后调整硬件时间
#hwclock -w
执行成功后, 查看系统硬件时间(不出意外的话,现在date和hwclock现实的时间均为internet时间)
#date
#hwclock
执行上述命令,显示的时间应该一样的
四、定时执行时间同步任务,所以我们利用crontab -e 来添加定时任务
# 1/ root ntpdatetimenurinet;hwclock -w
即:每隔一个小时同步一下internet时间。多台linux主机同步时间需要设置时间服务器
以下是方法:
多台linux服务器时间同步
1,设置A机时间服务器:
a,修改 /etc/ntpconf,如下:
# Undisciplined Local Clock This is a fake driver intended for backup
# and when no outside source of synchronized time is available
server 12712710 # local clock
#fudge 12712710 stratum 10
b,
/etc/initd/ntpd start #启动时间服务器
service ntpd status
service ntpd start
c,
[root@cardapp1 etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
LOCAL(0) LOCL 5 l 59 64 377 0000 0000 0000
d,chkconfig ntpd on #设置自启动
2,设置需同步的客户端机:
a,
修改 /etc/ntpconf,如下:
# Undisciplined Local Clock This is a fake driver intended for backup
# and when no outside source of synchronized time is available
server 2004040 # local clock 时间同步服务器A机
fudge 2004040 stratum 10
b,
service ntpd status
service ntpd start
c,(只有开了/etc/initd/ntpd start,才能看到下面信息)
[root@webcard2 etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
2004040 LOCAL(0) 6 u 5 64 1 1377 -70778 0000
d,chkconfig ntpd on #设置自启动
e, ntpdate -d 2004040
windows的时间可以在“日期和时间”属性里调,并开启windows time服务,如图。
Linux可以用ntp,如在/etc/crontab里添加:
sudo vim /etc/crontab
10 5 root /usr/sbin/ntpdate ntpfudaneducn && /sbin/hwclock -w
但服务器建议编辑ntp的配置文件,设置三个时间服务器。
如果只需要这两台服务器时间一样,而不必与北京时间相等,可以把其中一台配置为ntp服务器。
ntp使用udp的123端口。
关于ntp的更多知识,说来就话长了,可以写好几页。这里不讲了。
在图图形化界面输入下面命令~# system-config-date
就会出现一个图形化的界面,我相信图形化的东西你应该看得懂的,设置NTP就可以了,需要的是,时间服务器的主机名
然后运行
~# service ntpd restart
~# chkconfig ntpd on
解答如下,以Centos为例:
1,修正本地时区及ntp服务
#yum -y install ntp
#rm -rf /etc/localtime
#ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#/usr/sbin/ntpdate -u poolntporg
2,自动同步时间
#添加下面一段
#表示每10分钟同步一次
#crontab -e/10 /usr/sbin/ntpdate -u poolntporg >/dev/null 2>&1
#service crond restartLinux自带了ntp服务 -- /etc/initd/ntpd,这个服务不仅可以设置让本机和某台/某些机器做时间同步,他本身还可以扮演一个time server的角色,让其他机器和他同步时间。
配置文件就是/etc/ntpconf。
为了测试,设置让node2 -- 1921681102和node1 -- 1921681101做时间同步。第一步,node1做time server,node1本身不和其他机器时间同步,就是取本地时间。所以,先把node1机器的时间调准了:
[root@node1 ~]date -s 08/03/2011
[root@node1 ~]date -s 11:12:00
[root@node1 ~]clock -w[root@node1 ~]hwclock --systohc
后两个命令是把设置的时间写到硬件时间中去(也就是CMOS里面的时间)。
第二步,然后将node1配置成一个time server,修改/etc/ntpconf,[root@node1 ~]vi /etc/ntpconf其他的配置不怎么需要改,只需要关注restrict的配置:
1 注释掉原来的restrict default ignore这一行,这一行本身是不响应任何的ntp更新请求,其实也就是禁用了本机的ntp server的功能,所以需要注释掉。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)