1、时间同步的重要性 时间同步可以保证业务的正常运行,比如数据同步,比如系统计划任务的批量执行。等。
2、查看自己的系统时间。 [root@localhost ~]# date
3、系统修改时间
# date -s "2015-10-17 19:00:00"
4、硬件时间的设置 查看:[root@localhost ~]#clock --show 将系统时间同步到硬件时间:[root@localhost ~]# clock -w 立刻将网络时间源的时间同步到系统时间:[root@localhost ~]# ntpdate 网络上时间服务器的IP 时区修改:[root@localhost ~]# tzselect
可以直接对时间文件修改: [root@localhost ~]# /etc/sysconfig/clock
将硬件时间同步到系统时间: [root@localhost ~]# hwclock -s
5、网络同步 ntpdate操作以后,只是强制性的将系统时间设置为ntp服务器时间。cpu tick可能会有问题。一般需要crontab命令,来进行定期同步设置。比如,在crontab中添加:(记得管理好计划任务) 0 12 * * * * /usr/sbin/ntpdate 时间源的IP 12点一次同步。
6、NTP相关配置和文件目录 /etc/ntp.conf ntp的配置文件。 /usr /share/zoneinfo/ 各时区文件的目录 /etc/sysconfig/clock Linux开机启动会在这里读取要使用的时间。 /etc /localtime 本地时间的调用,会去读取时区的配置,然后把对应时区的时间copy来。 /etc/timezone 修改系统时区
配置:
[root@linux ~]# vi /etc/ntp.conf
# notrust :该 Client 除非通过认证,否则该 Client 来源将被视为不信任网域 # notrap :不提供trap这个远程事件登入 # 如果 paramter 完全没有设定,那就表示该 IP (或网域)“没有任何限制”
restrict default nomodify notrap noquery # 关闭所有的 NTP 要求封包 server 1.pool.ntp.org server 2.pool.ntp.org server cn.pool.ntp.org prefer #其他设置值,以系统默认值即可 server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift restrict用来设置访问权限,server用来设置上层时间服务器,driftfile用来设置保存漂移时间的文件。
记得查看一下ntpd有没有开启。 [root@linux ~] # netstat -ln|grep 123 ntp的端口123
ntpstat查看同步状态。 开启服务以后,需要等一会才会同步。
ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd 文件。 在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。
ntpd是平滑的。ntpdate是果断的。 如果觉得ntpd好慢。那就保证业务不会因为你的果断down掉的情况下。手工修改时间或者ntpdate果断的同步一下。 (责任编辑:IT) |