ntp-实现时间同步

一背景介绍

已经安装好crontab和ntp,系统centos6.5,一般不是最小化安装都会有哈。集群一定要搭建时间同步机制,不然运行久了,job运行会非常慢。
这里写图片描述

二搭建内网NTP服务器,通过此服务器进行时间同步

1修改配置文件

vim /etc/ntp.conf

# 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 noquery
restrict -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

#restrict 是允许单个IP地址访问本ntp服务器,或者允许网段中的服务器访问本ntp服务器进行时间同步
restrict 192.168.247.* mask 255.255.255.0
#允许192.168.247网段的ip可以访问本ntp服务器

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#增加server 210.72.145.44 表示指定本ntp服务器的上游ntp服务器为210.72.145.44,并且设置为首先服务器。同步时间为:从上到下,写的越靠上,优先级越高。(此服务器同步不了时间,寻找下一个ntp服务器)。此IP地址是中国国家授时中心ntp服务器。
#增加server 133.100.11.8     #当上面服务器同步不了,则寻找第二个。此IP地址是日本福冈大学ntp服务器。
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 192.168.247.132         
#local clock 如果上面的服务器都无法同步时间,就和本地系统时间同步。192.168.247.132 在这里是一个IP地址,不是网段。

#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.
#crypto

includefile /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

2开启ntp服务

/etc/init.d/ntpd start
这里写图片描述
使用如下命令,查看是否启动,123是ntp服务的端口哈
netstat -ln | grep 123
这里写图片描述

3客户端同步时间

这个命令,一般用户没有权限哦,只有root有,可以授权也可以用root,所以创建crontab的时候使用root用户。
ntpdate master
这里写图片描述
这个不是一个错误,一般ntp服务启动的时候,需要几分钟才能建立联系,所以耐心等待几分钟再试试。
这里写图片描述

4最后一步,使用crontab

定时同步时间,零点1分同步,且创建crontab的时候使用root用户,如果给其他用户赋予了ntpdate的运行权限也可以使用其他用户创建
crontab -e
01 00 * * * ntpdate mater
这里写图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫二哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值