Linux 時區修改以及時間同步

1.修改時區

[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime服務器

2.用ntpdate從時間服務器更新時間

[root@localhost ~]# yum -y install ntp
[root@localhost ~]# ntpdate 192.168.26.11
 6 Sep 16:26:07 ntpdate[65736]: adjust time server 192.168.26.11 offset -0.001832 sec
#可加入Crontab定時任務,每隔十分鐘同步一次
*/10 * * * * ntpdate 192.168.26.11spa

3.用ntp搭建本身的時間服務器

[root@localhost ~]# yum -y install ntp
[root@localhost ~]# cat /etc/ntp.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
restrict default ignore   #默認不容許修改或者查詢ntp,而且不接收特殊封包
restrict 127.0.0.1           #給於本機全部權限
restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify  #給於局域網機的機器有同步時間的權限
server 192.168.26.11 prefer   #設置時間服務器,加prefer表示優先
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
[root@localhost ~]# service ntpd restart
關閉 ntpd:[失敗]
正在啓動 ntpd:[肯定]
#查看時程
[root@localhost ~]# netstat -upnl |grep ntpd
udp        0      0 192.168.211.238:123          0.0.0.0:*                               65760/ntpd          
udp        0      0 127.0.0.1:123                     0.0.0.0:*                               65760/ntpd          
udp        0      0 0.0.0.0:123                         0.0.0.0:*                              65760/ntpd          
udp        0      0 ::1:123                     :::*                                                    65760/ntpd          
udp        0      0 fe80::eabd:d1ff:fefc:f16:123 :::*                                     65760/ntpd          
udp        0      0 fe80::eabd:d1ff:fefc:f16:123 :::*                                     65760/ntpd          
udp        0      0 :::123                      :::*                                                     65760/ntpd          
#查看同步結果
[root@localhost ~]# ntpstat
synchronised to NTP server (192.168.26.11) at stratum 5 
   time correct to within 8202 ms
   polling server every 64 s
#設置開機啓動
[root@localhost ~]# chkconfig ntpd on.net

4.ntpd系統日誌

/var/log/messagesrest

相關文章
相關標籤/搜索