首先设置时区:
将对应时区文件拷贝一个副本为/etc/localtime
1 |
<SHELL># cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
然后配置参数文件,设置为/etc/localtime对应的时区
1 2 3 4 5 |
vim /etc/sysconfig/clock # The time zone file under /usr/share/zoneinfo that /etc/localtime is a copy of. ZONE="Asia/Shanghai" # The hardware clock is set to local time instead of Universal Time. UTC 使用localtime而不是universal time UTC=no |
为了方便某些应用程序,也要将TZ环境变量写入/etc/profile中:
1 |
export TZ="Asia/Shanghai" |
使用ntpdate连接测试:
1 2 |
<SHELL># ntpdate ntp.api.bz 5 May 19:53:18 ntpdate[11340]: step time server 61.153.197.226 offset 2.531909 sec |
将当前时间设置为硬件时钟(Set the Hardware Clock to the current System Time.)
1 |
<SHELL># /sbin/hwclock --systohc |
node02节点作为ntp server,其他节点通过该节点来同步时间。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@node02 Desktop]# vim /etc/ntp.conf #drift and keys driftfile /var/lib/ntp/drift includefile /etc/ntp/crypto/pw keys /etc/ntp/keys #access control restrict 127.0.0.1 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap server ntp.api.bz prefer server 127.127.1.0 fudge 127.127.1.0 stratum 10 |
下层ntpd的配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@node01 Desktop]# vim /etc/ntp.conf #drift and keys driftfile /var/lib/ntp/drift includefile /etc/ntp/crypto/pw keys /etc/ntp/keys #access control restrict 127.0.0.1 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap server node02 prefer server ntp.api.bz # service ntpd restart Shutting down ntpd: [FAILED] Starting ntpd: [ OK ] |
查看两边的时间同步信息:
1 2 3 4 5 6 7 8 9 10 11 |
[root@node02 Desktop]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== 114.80.81.1 .INIT. 16 u - 64 0 0.000 0.000 0.000 *LOCAL(0) .LOCL. 5 l 56 64 3 0.000 0.000 0.000 # ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *OSTack02 LOCAL(0) 6 u 47 64 177 0.843 -0.058 0.528 114.80.81.1 .STEP. 16 u - 256 0 0.000 0.000 0.000 |
最后设置ntpd服务开机启动
1 |
<SHELL># chkconfig ntpd --level 35 on |
下面的一些资料更全面的介绍了时区和NTP的配置:
鸟哥Linux私房菜:http://linux.vbird.org/linux_server/0440ntp.php#ntpq
http://en.linuxreviews.org/NTP_-_Howto_make_the_clock_show_the_correct_time
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-sysconfig-clock.html
我的是 自己买的 西雅图机房~! 不过 博客 快荒废了 呵呵 ~!
@马克吐温:说政客全都是贼!!!儒生们却说,它们有仁爱,天天为政客辩解!!!…