centos系统时间同步和网络同步
ios
通常新装的centos系统服务器有的时间可能不对或者设置了错误的时区,可使用NTP从时间服务器同步。vim
1.把当前时区调整为上海+8区,想改其余时区也能够。在/usr/share/zoneinfo目录
centos
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
服务器
2.安装ntpdate
网络
yum install -y ntpdate
ide
3.使用ntpdate同步标准时间(或者同步其余的时间服务器)
测试
ntpdate us.pool.ntp.org
spa
4.把同步的时间写入到bios里面
.net
hwclock -w
rest
5.若是在没有网络的状况,可使用手动设置时间
date -s 10:00:00
6.若是上面的同步成功,则能够放在crontab里面
设置每十分钟同步一次时间
*/10 * * * * ntpdate time.nist.gov
列出几个时间服务器
us.pool.ntp.org
time.nist.gov
time.nuri.net
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org
设置本身的时间服务器
1.安装时间同步服务器ntp
yum install -y ntp
2.配置ntp
vim /etc/ntp.conf
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.启动ntp
/etc/init.d/ntpd start
chkconfig ntpd on
4.查看并测试
ntpq -pn //查看同步的服务器ip
remote refid st t when poll reach delay offset jitter ============================================================================== 50.77.217.185 .INIT. 16 u - 64 0 0.000 0.000 0.000 202.90.158.4 .INIT. 16 u - 64 0 0.000 0.000 0.000 202.71.100.89 .INIT. 16 u - 64 0 0.000 0.000 0.000 202.134.1.10 .INIT. 16 u - 64 0 0.000 0.000 0.000 *127.127.1.0 .LOCL. 10 l 18 64 377 0.000 0.000 0.001
remote:即NTP主机的IP或主机名称。注意最左边的符号,若是由“+”则表明目前正在做用钟的上层NTP,若是是“*”则表示也有连上线,不过是做为次要联机的NTP主机。
refid:参考的上一层NTP主机的地址
st:即stratum阶层
when:几秒前曾作过期间同步更新的操做
poll:下次更新在几秒以后
reach:已经向上层NTP服务器要求更新的次数
delay:网络传输过程钟延迟的时间
offset:时间补偿的结果
jitter:Linux系统时间与BIOS硬件时间的差别时间
推荐第一种方法,虽然搭建个时间服务器,仍是比较简单的,可是我以为没有这个必要。若是用别人的时间服务器,每隔10分钟同步一次,能够精确到毫秒。
5.查看同步的结果
ntpstat
6.客户端配置
安装及启动方式都同样,只是server的配置不同,把server的配置,修改为链接外网的那台 server 192.168.103.117 7.客户端上同步服务器上的时间 ntpdate -u 192.168.103.117