首页 > 技术文章 > Centos7 Ntp 时间服务器

jksbaduen 2017-11-15 17:08 原文

Centos7 Ntp 时间服务器

安装环境

  1. [root@m02 ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.4.1708 (Core)

安装时间服务器

yum -y install ntp

修改时间服务器配置文件

vim /etc/ntp.conf

修改时间权限

修改时间服务器

  1. [root@m02 ~]# sed -i.org '8s#restrict.*noquery#restrict default nomodify#;21,24d;20a server ntp1.aliyun.com\nserver time.nist.gov' /etc/ntp.conf
  2. [root@m02 ~]# vim /etc/ntp.conf

Ntp服务与ntpdate有冲突!删除定时任务

启动时间服务器前修改时间

  1. [root@m02 ~]# date -s 201001010
  2. date: cannot set date: Invalid argument
  3. Sun Oct 10 00:00:00 CST 20100
  1. 启动时间服务器

systemctl start ntpd.service

查看时间服务器状态

  1. [root@m02 ~]# ntpq -p
  2.      remote refid st t when poll reach delay offset jitter
  3. ==============================================================================
  4.  time5.aliyun.co 10.137.38.86 2 u 32 64 3 5.193 4.852 1.151
  5.  time-c-b.nist.g .INIT. 16 u - 64 0 0.000 0.000 0.000

ntpstat查看时间同步状态

  1. [root@m02 ~]# ntpstat
  2. unsynchronised
  3.   time server re-starting
  4.    polling server every 8 s

查看时间有没有改回来

  1. [root@m02 ~]# date
  2. Wed Nov 15 16:53:40 CST 2017

客户端配置

写入定时任务

echo "*/5 * * * * /usr/sbin/ntpdate ntp 172.16.1.71 &>/dev/null"

推荐阅读