1、关闭firewalld防火墙
[root@localhost /]#systemctl stop firewalld #关闭防火墙
[root@localhost /]#systemctl disable firewalld #开机不自启
2、关闭selinux防火墙
[root@localhost /]vi /etc/selinux/config
更改内容如下:
SELINUX=disabled
#重启服务器生效
3、安装chrony服务
[root@localhost /]# yum install -y chrony
4、修改配置chrony文件
[root@localhost /]#vi /etc/chrony.conf
##############以下为chrony.conf配置文内容###################
##############以下为chrony.conf配置文内容###################
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#联网获取NTP时间,server全部注释
#server 0.centos.pool.ntp.org iburst
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync
# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *
# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2
# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 0.0.0.0/0
# Serve time even if not synchronized to a time source.
#获取本地服务器时间
local stratum 10
# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys
# Specify directory for log files.
logdir /var/log/chrony
# Select which information is logged.
#log measurements statistics tracking
5、启动chrony服务
[root@localhost /]#systemctl start chronyd #启动服务
[root@localhost /]#systemctl enable chronyd #设置开机自启
6、安卓端设置NTP服务器地址
abd连接安卓设备
修改:adb shell settings put global ntp_server 192.168.1.18 #192.168.1.8为NTP服务器IP
删除:adb shell settings put global ntp_server null
查看:adb shell settings get global ntp_server
说明:安卓设备会在每次重启后,重新获取网络时间。
注意:需要在安卓设备时间设置里。开启获取网络时间和网络时区。