资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

linux设置ntp时间同步-创新互联

NTP时钟同步方式说明

成都创新互联技术团队10年来致力于为客户提供成都做网站、网站建设、外贸营销网站建设成都品牌网站建设成都营销网站建设、搜索引擎SEO优化等服务。经过多年发展,公司拥有经验丰富的技术团队,先后服务、推广了上千网站,包括各类中小企业、企事单位、高校等机构单位。

NTP在linux下有两种时钟同步方式,分别为直接同步和平滑同步:
直接同步
使用ntpdate命令进行同步,直接进行时间变更。如果服务器上存在一个12点运行的任务,当前服务器时间是13点,但标准时间时11点,使用此命令可能会造成任务重复执行。因此使用ntpdate同步可能会引发风险,因此该命令也多用于配置时钟同步服务时第一次同步时间时使用。
平滑同步
使用ntpd进行时钟同步,可以保证一个时间不经历两次,它每次同步时间的偏移量不会太陡,是慢慢来的,这正因为这样,ntpd平滑同步可能耗费的时间比较长。

1、安装ntp

yum install ntp

2、设置ntp服务开机启动

systemctl  restart ntp.service

3、设置服务器

3.1. vi /etc/ntp.conf,内容如下:

driftfile /var/lib/ntp/ntp.drift #草稿文件

# 允许内网其他机器同步时间

restrict 192.168.137.0(替换成自己的ip) mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# 中国这边最活跃的时间服务器 :

[http://www.pool.ntp.org/zone/cn](http://www.pool.ntp.org/zone/cn)

server 210.72.145.44 perfer   # 中国国家受时中心

server 202.112.10.36             # 1.cn.pool.ntp.org

server 59.124.196.83             # 0.asia.pool.ntp.org  

# allow update time by the upper server

# 允许上层时间服务器主动修改本机时间

restrict 210.72.145.44 nomodify notrap noquery

restrict 202.112.10.36 nomodify notrap noquery

restrict 59.124.196.83 nomodify notrap noquery  

# 外部时间服务器不可用时,以本地时间作为时间服务

server  127.127.1.0     # local clock

fudge   127.127.1.0 stratum 10

3.2 重启服务:service ntpd restart

3.3查看同步状态:netstat -tlunp | grep ntp

4、设置同步

4.1 vim /etc/ntp.conf,内容如下:

driftfile /var/lib/ntp/ntp.drift # 草稿文件

statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats

filegen loopstats file loopstats type day enable

filegen peerstats file peerstats type day enable

filegen clockstats file clockstats type day enable

#让NTP Server为内网的ntp服务器

server 192.168.137.110 (master节点ip)

fudge 192.168.137.110 stratum 5

#不允许来自公网上ipv4和ipv6客户端的访问

restrict -4 default kod notrap nomodify nopeer noquery

restrict -6 default kod notrap nomodify nopeer noquery

#Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

4.2重启服务:service ntpd restart

4.3手动同步:ntpdate -u 192.168.124.146

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:linux设置ntp时间同步-创新互联
网页URL:http://cdkjz.cn/article/dpdopj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220