首页 > 系统服务 > 详细

Linux时间同步

时间:2019-03-29 21:20:04      阅读:127      评论:0      收藏:0      [点我收藏+]

时间修改

1.将HKT时区修改为CST时区
cd /etc
mv localtime localtime.bak
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date
2.修改时间
date -s "2019-03-19 12:00:00"

centos6.5配置NTP时间同步

1.修改/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 notra

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 目标同步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

#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服务器
service ntpd start
3.开放防火墙端口udp123
 -I INPUT -p udp --dport 123 -j ACCEPT
4.客户端同步
ntpdate 服务器IP && hwclock -w
5.客户端同步时间显示详情
ntpdate -d 服务器IP

问题

no server suitable for synchronization found
错误
1.Server dropped:Strata too high

肯能定义的Server不可用

2.Server dropped:nodata

防火墙是否开放udp123端口,关闭防火墙尝试能否同步

查询ntp版本命令:

ntpq -c version

centos7配置NTP时间同步

1.修改/etc/ntp.conf

2.启动ntp服务

 systemctl start ntpd.service

3.开启防火墙端口

firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --reload
firewall-cmd --list-port

4.其它服务器同步时间

ntpdate 服务器IP

成功则显示

21 Mar 16:21:06 ntpdate[16681]: step time server 服务器IP offset -50.608671 sec

若显示以下问题查看当前服务器是否开启ntp服务,开启ntp需要关闭

21 Mar 16:18:05 ntpdate[16125]: the NTP socket is in use, exiting

若显示以下问题查看当前服务器是否开启udp123端口,若无需要开启

21 Mar 16:18:23 ntpdate[16264]: no server suitable for synchronization found

5.配置crond定时同步

Linux时间同步

原文:https://www.cnblogs.com/code-red-memory/p/10623815.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!