centos 系统时间的同步

时间:2023-03-08 23:31:23
centos 系统时间的同步

1.当你的网站架构涉及到多台服务器的时候,服务器之间的时间必须得同步,这样就涉及到了程序的时间的准确性问题,特别是跟时间相关的操作和系统本身的定时任务。

2.时间同步工具:ntpdate,安装方式:yum install -y ntpdate

3.使用方法:ntpdate time.windows.com,同步你想同步的那台服务器的时间

可以同步的服务器:

time.nist.gov
time.nuri.net
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org

4.同步时间的方法:

1):第一种就是设置定时任务,定时的去运行ntpdate命令更新时间 */10 * * * * ntpdate time.nist.gov

2):配置/etc/ntp.conf 文件:运行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 time.nist.gov prefer //设置时间服务器,加prefer表示优先
server 0.asia.pool.ntp.org 
server 1.asia.pool.ntp.org 
server 2.asia.pool.ntp.org 
server 127.127.1.0 # local clock 
fudge 127.127.1.0 stratum 10 
driftfile /var/lib/ntp/drift 
keys /etc/ntp/keys

3)配置完成后就启动服务: /etc/init.d/ntpd start

4)查看同步情况:ntpq -pn