hl10502的博客

CentOS7.2配置NTP服务

环境

  • CentOS Linux release 7.2.1511 (Core) Mini版

NTP服务端

设置时区

[root@ceph-210 ~]# timedatectl set-timezone Asia/Shanghai
[root@ceph-210 ~]# hwclock --systohc

安装NTP

1
2
[root@ceph-210 ~]# yum install --downloadonly --downloaddir=/tmp/ntp ntp
[root@ceph-210 ~]# yum localinstall -C -y --disablerepo=* /tmp/ntp/*.rpm

修改配置

1
[root@ceph-210 ~]# vi /etc/ntp.conf

注释或删除

1
2
3
4
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

增加

1
2
server 127.127.1.0 iburst # local clock 使用本机时间作为时间服务的标准
fudge 127.127.1.0 stratum 10 #这个值不能太高0-15,太高会报错

启动NTP服务

开机启动NTP服务

1
2
[root@ceph-210 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

启动NTP服务

1
[root@ceph-210 ~]# systemctl start ntpd

查看NTP服务

1
2
3
4
5
6
7
8
[root@ceph-210 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2017-06-12 00:45:05 EDT; 16s ago
Process: 2635 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 2636 (ntpd)
CGroup: /system.slice/ntpd.service
└─2636 /usr/sbin/ntpd -u ntp:ntp -g

验证NTP服务

1
2
3
4
[root@ceph-210 ntp]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 10 l 36 64 1 0.000 0.000 0.000

NTP客户端

设置时区

[root@ceph-211 ~]# timedatectl set-timezone Asia/Shanghai

安装ntpdate

1
2
[root@ceph-211 ~]# yum install --downloadonly --downloaddir=/tmp/ntpdate ntpdate
[root@ceph-211 ~]# yum localinstall -C -y --disablerepo=* /tmp/ntpdate/*.rpm

配置crontab

每3分钟定时同步NTP服务器192.168.217.210的时间

1
2
[root@ceph-211 ~]# crontab -e
*/3 * * * * /usr/sbin/ntpdate 192.168.217.210 >> /var/log/ntpdate.log 2>&1

重启crontab

1
[root@ceph-211 ~]# systemctl restart crond.service