1.时间手动设置
设置软件【操作系统】时间:date
设置硬件【主板BIOS】时间:clock
2.时间自动同步
生产环境一般使用ntpd好点,ntpd在实际同步时间时是一点点的校准过来时间的,最终把时间慢慢的校正对。而ntpdate不会考虑其他程序是否会阵痛,直接调整时间。
(1).ntpdate
强制同步时间服务器
# ntpdate 192.168.0.1
每天12点同步时间
# vim /etc/crontab
0 12 * * * * /usr/sbin/ntpdate 192.168.0.1
(2).ntpd
ntpd同步系统时间,修改配置文件,添加时间服务器
# vim /etc/ntp.conf
ntp服务默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd 文件。在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。
3.centos7利用ntpdate搭建本地时间服务器。
时间服务器服务器端:192.168.1.10
客户端同步测试:192.168.1.13
(1).服务端配置192.168.1.10安装配置ntpdate
192.168.1.10
# yum install ntp ntpdate -y
# vim /etc/ntp.conf
1 # For more information about this file, see the man pages
2 # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
3
4 driftfile /var/lib/ntp/drift
5
6 # Permit time synchronization with our time source, but do not
7 # permit the source to query or modify the service on this system.
8 #restrict default nomodify notrap nopeer noquery
9
10 # Permit all access over the loopback interface. This could
11 # be tightened as well, but to do so would effect some of
12 # the administrative functions.
13 #restrict 127.0.0.1
14 #restrict ::1
15 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
16
# systemctl restart ntpd
(2).客户端192.168.1.13测试
# ntpdate 192.168.1.10