10月16日PingCAP正式发布了TiDB 1.0版本,作为数据库的爱好者第一时间感受一下。在部署8节点的TiDB时,TiDB会precheck所有节点的时钟同步,而precheck的方式是only ntpd,由于OS来源于克隆模板,模板中采用了crontab的ntpdate & hwclock -w方式来同步时间,so the question is coming, which one and why?
The ntpd program is an operating system daemon which sets and maintains the system time of day in synchronism with Internet standard time servers. NTP provides a smooth time correction.
ntpdate does not keep any state to perform this service for you so will not provide the same kind of accuracy. ntpdate corrects the system time instantaneously, which can cause problems with some software (Especially similar to database transactions, the time can’t jump back). ntpdate can be run manually as necessary to set the host clock, or it can be run from the host startup script to set the clock at boot time. It is also possible to run ntpdate from a cron script.
NTP daemon uses sophisticated algorithms to maximize accuracy and reliability while minimizing resource use. Finally, since ntpdate does not discipline the host clock frequency as does ntpd, the accuracy using ntpdate is limited.
server time1.aliyun.com server time2.aliyun.com server time3.aliyun.com server time4.aliyun.com server time5.aliyun.com server time6.aliyun.com prefer server time7.aliyun.com
includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
启动NTP并检查
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ sudo systemctl start ntpd $ ntpstat **synchronised** to NTP server (115.28.122.198) at stratum 3 time correct to within 75 ms polling server every 1024 s
$ ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *time6.aliyun.co 10.137.38.86 2 u 383 1024 377 24.056 -0.829 0.594 +time4.aliyun.co 10.137.38.86 2 u 721 1024 377 20.286 -0.590 0.809 -time5.aliyun.co 10.137.38.86 2 u 229 1024 373 34.518 -4.825 2.597 +120.25.115.19 10.137.38.86 2 u 678 1024 337 18.701 -0.811 1.965
$ sudo systemctl enable ntpd
配置NTP Client
安装NTP包
修改系统时区
修改/etc/ntp.conf
1 2 3 4 5 6 7 8 9 10 11
$ sudo vi /etc/ntp.conf restrict 127.0.0.1 server 192.168.1.118
$ sudo systemctl start ntpd $ sudo ntpdate 192.168.1.118 #由于client/server之间的误差不允许超过 1000 秒,可能需要先手动同步 $ ntpstat synchronised to NTP server (192.168.1.118) at stratum 4 time correct to within 79 ms polling server every 64 s $ sudo systemctl enable ntpd