文章只是自己操作记录,如果后期失效了欢迎留言,只是测试环境中使用,生产中,需要您自己进行测试
因多台服务器,分布式处理了数据逻辑,需要时间同步,网上资料整理后简单处理
前提离线部署,跟外网无关
简单同步,复杂同步需要参考(参考多篇文章整理):
https://blog.csdn.net/w892824196/article/details/89225639
服务端配置
# 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 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 ::1
# Hosts on local network are less restricted.
# 需要修改局域网信息 根据实际情况修改
restrict 192.168.0.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).
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
#server 1.cn.pool.ntp.org prefer
#server 2.cn.pool.ntp.org iburst
#server 3.cn.pool.ntp.org iburst
server 127.127.1.0
fudge 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.
#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
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor
客户端配置
# 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 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 ::1
# Hosts on local network are less restricted.
# 参考服务端信息配置
restrict 192.168.125.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).
# 修改服务端部署服务信息ip
server 192.168.0.8
Fudge 192.168.0.8 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.
#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
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor
执行命令
文件搜索下载地址:
例如:
根据系统自己选择相应软件哈
#!/bin/bash
#安装ntp服务
yum -y localinstall ../package/autogen-libopts-5.18-5.el7.x86_64.rpm;
yum -y localinstall ../package/ntpdate-4.2.6p5-29.el7.centos.x86_64.rpm;
yum -y localinstall ../package/ntp-4.2.6p5-29.el7.centos.x86_64.rpm;
#移除ntp.conf
rm -rf /etc/ntp.conf;
cp ntp.conf /etc;
#开启123端口
firewall-cmd --zone=public --add-port=123/udp --permanent;
firewall-cmd --reload
#设置ntp开机启动
systemctl enable ntpd;
systemctl restart ntpd;
echo "安装ntp服务成功====================";
查看状态命令
#服务端
[root@localhost etc]# ntpstat
synchronised to local net (127.127.1.0) at stratum 11
time correct to within 448 ms
polling server every 64 s
[root@localhost etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 10 l 32 64 17 0.000 0.000 0.000
#客户端
[root@localhost etc]# ntpstat
synchronised to NTP server (192.168.0.8) at stratum 12
time correct to within 1038 ms
polling server every 64 s
[root@localhost etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.0.8 LOCAL(0) 11 u 14 64 7 0.490 26.015 1.356