ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
> 192.168.56.10 (作为内网时间同步服务器) > 192.168.56.11 ## 1. server端安装ntp服务 192.168.56.10 ``` yum -y install ntp ``` ## 2. 修改server配置 ``` vi /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 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.1.0 mask 255.255.255.0 nomodify notrap # 1. 网其他机器同步时间 restrict 192.168.1.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). # 2. 中国这边最活跃的时间服务器() 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 # # 3. 允许上层时间服务器主动修改本机时间 restrict 210.72.145.44 nomodify notrap noquery restrict 202.112.10.36 nomodify notrap noquery restrict 59.124.196.83 nomodify notrap noquery # 4、外部时间服务器不可用时,以本地时间作为时间服务 server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 ``` **重启ntp服务** ``` systemctl start ntpd ``` 此时,两台时间不一样 ``` [root@localhost ~]# date Mon May 13 20:47:12 EDT 2019 [root@localhost ~]# date Mon May 13 08:45:44 EDT 2019 ``` ## 3. client同步server时间 让client(192.168.56.11)去时间服务器上同步时间,ntpdate命令用于同步更新互联网时间,或者NTP服务器时间 安装ntpdate 命令 ``` yum install ntpdate -y ``` 与时间服务器同步时间 ``` ntpdate 192.168.56.10 ``` ## 4. 定时任务 ``` 30 5 * * * root /usr/sbin/ntpdate -u pool.ntp.org && /sbin/clock --systohc ``` 每天5点半同步时间,clock --systohc是硬盘时间同步系统时间的意思。 ## 5. client与server同步的另一种方式 这种方式麻烦 1、客户端安装ntp服务 2、配置客户端去同步时间服务器的时间