ntp时间同步服务

 

  • 1、同步机器时间

  • Atomic Clock: 现在计算时间最准确的是使用 原子震荡周期 所计算的物理时钟(Atomic Clock),因此也被定义为标准时间(International Atomic Time)
  • UTC(coordinated Universal Time): 协和标准时间 就是利用 Atomic Clock 为基准定义出来的正确时间(世界统一时间,世界标准时间,国际协调时间。

 

  • 什么是硬件时钟:
  • 硬件时钟: 硬件时钟是指嵌在主板上的特殊的电路, 它的存在就是平时我们关机之后还可以计算时间的原因
  • 什么是系统时钟:
  • 系统时钟: 就是操作系统的kernel所用来计算时间的时钟. 它从1970年1月1日00:00:00 UTC时间到目前为止秒数总和的值
  • 1.安装ntp服务
  • yum install -y ntp #安装时间服务
  • ntpdate cn.pool.ntp.org #同步时间命令
  • # Use public servers from the pool.ntp.org project
  • # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  • server 1.cn.pool.ntp.org
  • server 2.cn.pool.ntp.org prefer

vi /etc/ntp.conf

restrict 192.168.80.0 mask 255.255.255.0 nomodify notrap允许192.168.80.0/24 网段的主机来进行对时,但不允许客户端来修改,登录我的NTP服务器

restrict default nomodify #允许任何IP的客户机都可以进行时间同步

实验成功的配置

restrict default kod nomodify notrap nopeer noquery #针对IPV4设置
#restrict -6 default kod nomodify notrap nopeer noquery #针对IPV6设置

# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
#NTP的默认设置

#允许本地所有操作
restrict 127.0.0.1
restrict -6 ::1

#允许的局域网络段
# Hosts on local network are less restricted.
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

使用的上层internet ntp服务器
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org prefer

 

 

3.设置同步更新本地hwclock

 

在Linux下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各自独立运行了那么既然两个时钟独自运行,那么时间久了必然就会产生误差了,而NTP默认又只更新系统时间,因此我们需要设置硬件时钟进行同步调整

1.# vim /etc/sysconfig/ntpd
2.# Drop root to id 'ntp:ntp' by default.
3.OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
4.SYNC_HWCLOCK="yes"

添加SYNC_HWCLOCK="yes"

 

启动NTP服务

1.# service ntpd start
2.Starting ntpd:                                             [  OK  ]

 

date命令的使用:

时间设定成2009年5月10日的命令如下: 
#date -s 05/10/2009 -s10:18:00

修改时间: 
将系统时间设定成上午10点18分0秒的命令如下。 
#date -s 10:18:00

修改时区: 
找到相应的时区文件 /usr/share/zoneinfo/Asia/Shanghai替换当前的/etc/localtime。 
修改/etc/sysconfig/clock文件的内容为: 
ZONE=”Asia/Shanghai” 
UTC=false 
ARC=false

同步bios时间: 
同步BIOS时钟,强制把系统时间写入CMOS,命令如下: 
#clock -w

 

转载于:https://www.cnblogs.com/xiaoyongzhuo/p/7083600.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值