NTP时间服务

来源:互联网 发布:mac qq群文件在哪 编辑:程序博客网 时间:2024/06/01 08:25

  • NTP时间服务搭建
    • NTP时间服务安装
    • NTP时间服务配置
    • NTP快速时间同步命令
    • NTP时间同步状态查询
    • NTP服务

NTP时间服务搭建

  • NTP时间服务:主要功能用于同步服务器之间的时间,因为有很多服务,如hadoop集群,结点之间的时间必须一致,否则服务会出错。

NTP时间服务安装

  • NTP安装比较简单,一般系统都可以直接安装,这里以CentOS为例
  • 安装命令:yum install ntp

NTP时间服务配置

  • 一般NTP服务分为服务端和客户端,程序上是没有区别的,只是配置上的区别。为什么要有服务端,主要是为了方便内网服务器进行时间同步,一个内网只需要配置一台时间服务器,用于同步网络时间,然后内网所有机器就可以同步这台服务器的时间,从而实现快速时间同步
    1. 服务端配置:这里直接给出示例,假设这台服务器的IP:192.168.11.11
# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.restrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could# be tightened as well, but to do so would effect some of# the administrative functions.restrict 127.0.0.1 restrict -6 ::1# Hosts on local network are less restricted.restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).# ntp服务器配置# 中国国家受时中心,并没有什么用#server 210.72.145.44# 第三方ntp时间服务器,比较稳定,如果大家有钱也可以给这个组织捐款,支持他们server cn.ntp.org.cn# allow update time by the upper server # 允许上层时间服务器主动修改本机时间restrict cn.ntp.org.cn nomodify notrap noquery# Undisciplined Local Clock. This is a fake driver intended for backup# and when no outside source of synchronized time is available. # 外部时间服务器不可用时,以本地时间作为时间服务server  127.127.1.0     # local clockfudge   127.127.1.0 stratum 10#broadcast 192.168.1.255 autokey    # broadcast server#broadcastclient            # broadcast client#broadcast 224.0.1.1 autokey        # multicast server#multicastclient 224.0.1.1      # multicast client#manycastserver 239.255.254.254     # manycast server#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys# Specify the key identifiers which are trusted.#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.#requestkey 8# Specify the key identifier to use with the ntpq utility.#controlkey 8# Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats
  1. 客户端配置:这里直接给出示例
# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.restrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could# be tightened as well, but to do so would effect some of# the administrative functions.restrict 127.0.0.1 restrict -6 ::1# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).# ntp客户端配置server 192.168.11.11# 允许这台机器修改本机时间restrict 192.168.11.11 nomodify notrap noquery# 同步服务不存在时,使用本地时间server  127.127.1.0     # local clockfudge   127.127.1.0 stratum 10#broadcast 192.168.1.255 autokey    # broadcast server#broadcastclient            # broadcast client#broadcast 224.0.1.1 autokey        # multicast server#multicastclient 224.0.1.1      # multicast client#manycastserver 239.255.254.254     # manycast server#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys# Specify the key identifiers which are trusted.#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.#requestkey 8# Specify the key identifier to use with the ntpq utility.#controlkey 8# Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats

NTP快速时间同步命令

  • 因为NTP服务启动后,需要很长的时间才会去同步,所以需要先使用命令来快速同步
  • 注意:有发现,在两台服务器之间,如果时间相差太大,时间同步服务会出现异常,所以最好先使用命令做一次时间同步。另外,如果同步地址不可用,也会出现时间无法同步的情况,所以使用同步命令还可以测试地址是否可用
  • 时间同步命令: ntpdate -u 192.168.11.11

NTP时间同步状态查询

  • 有时间需要知道当前同步的时间来自那个时间服务器,或配置了多个时间服务器时,那个服务器是最稳定的等,这时就需要使用命令来查询同步状态
  • 状态查询命令: ntpq -p
  • 注意: 状态的属性有点多,需要详细了解的,见http://www.cnblogs.com/kerrycode/archive/2015/08/20/4744804.html

NTP服务

  • 当服务配置完成,时间同步地址正常,就可以启动时间同步服务来定时同步服务器时间
  • 服务启动: systemctl start ntpd
    开机自启动:systemctl enable ntpd
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手机设置路由器打不开了怎么办 手机打不开登录路由器的网址怎么办 按了光猫复位后怎么办 按了猫的复位键怎么办 望远镜的镜片小水雾是怎么办 坚果r1不断重启怎么办 忘记Wi-Fi密码了怎么办 魅蓝手机null锁住了怎么办 红米手机锁屏了怎么办 不记得锁屏密码怎么办 小米手机音量键坏了怎么办 小米6音量键坏了怎么办 小米2s开不开机怎么办 小米4不充电了怎么办 小米2开不开机怎么办 手机开机键开不了机怎么办 三星s4反复重启怎么办 小米5反复重启怎么办 电脑系统奔溃了怎么办 电脑开机后屏幕出现英文怎么办 小米4开不开机了怎么办 小米4一直显示mi怎么办 小米手机开关键失灵怎么办 小米手机开机键失灵怎么办 小米6不断重启怎么办 小米6一直重启怎么办 小米6自动重启怎么办 手机的开机键坏了怎么办 小米6频繁重启怎么办 小米6安装xp卡米怎么办 刷机失败反复重启怎么办 红米手机很卡怎么办啊 红米2a显示图标怎么办 手机一直处于开机状态怎么办 vivo手机进水开不了机怎么办 魅蓝s6锁了怎么办 pos机刷卡刷多了怎么办 红米5a开不机怎么办 魅族双亲要密码怎么办? 苹果wi-fi网速慢怎么办 腾达宽带用户名密码忘了怎么办