1.1 ntp
ntp服务端口是123
服务端:
rpm -qa ntp
rpm -qa chrony
yum -y install ntp
cp /etc/ntp.conf{,.bak}
vim /etc/ntp.conf
8 #restrict default nomodify notrap nopeer noquery
9 restrict default nomodify
21 #server 0.centos.pool.ntp.org iburst
22 #server 1.centos.pool.ntp.org iburst
23 #server 2.centos.pool.ntp.org iburst
24 #server 3.centos.pool.ntp.org iburst
25 server ntp1.aliyun.com
[root@m02 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
time5.aliyun.co 10.137.38.86 2 u 52 64 1 34.532 139.579 0.000
##显示你的上级ntp服务器情况
ntpstat
##查看ntp服务的状态,是否可以使用
[root@m02 ~]# ntpstat
synchronised to NTP server (182.92.12.11) at stratum 3
time correct to within 958 ms
polling server every 64 s
##出现类似这样的输出,就表示ntp服务可以使用了
客户端:
yum -y install ntpdate
ntpdate NTP服务器
##测试好使之后把同步ntp服务器的命令放到计划任务,并每五分钟执行一次
至此,ntp Over~~
1.2 chrony
服务端:
systemctl stop ntpd.service
yum -y install chrony
cp /etc/chrony.conf{,.bak}
vim /etc/chrony.conf
3 #server 0.centos.pool.ntp.org iburst
4 #server 1.centos.pool.ntp.org iburst
5 #server 2.centos.pool.ntp.org iburst
6 #server 3.centos.pool.ntp.org iburst
7 server ntp2.aliyun.com
27 allow 172.16.1.0/24
systemctl start chronyd
tailf /var/log/messages
Mar 13 11:40:04 m02 chronyd[1649]: Selected source 120.25.115.19
##出现上面这一条的话就代表这个服务可以使用了
客户端:
也是一样用ntpdate命令