1. 选定其中一台服务器作为基准服务器,即提供时钟服务。
(1)首先确定ntp是否存在,若不存在则通过以下命令安装:
yum install ntp
(2)修改配置文件/etc/ntp.conf,在其中插入:
restrict 192.168.20.0 mask 255.255.255.0 nomodify notrap
其中:
用restrict控管权限
nomodify – 用户端不能更改ntp服务器的时间参数
noquery – 用户端不能使用ntpq,ntpc等命令来查询ntp服务器
notrap – 不提供trap远端登陆
(3)此时可以向192.168.20.0/24的机器提供时间服务了,开启ntp服务:
/etc/init.d/ntp start // 启动ntp服务
chkconfig ntpd on // 让ntp服务开机启动
(4)检查ntp端口是否已经开启:
netstat -unlnp
如果正常,应该可以看到123端口已经开启。
2. 客户端同步(使用ntpd服务)
也可以使用ntpdate手动同步,但我在这里推荐使用ntpd服务进行自动同步
(1)修改/etc/ntp.conf,在里边插入:
server 192.168.20.91
(2)使ntpd服务开启启动
chkconfig ntpd on
(3)启动客户端ntpd服务
/etc/init.d/ntpd start
13 5,9,14,19 * * * /usr/sbin/ntpdate 192.168.18.2
================刚刚在测试的时候发现有点问题
第一,时间服务器配置文件中除
restrict 192.168.207.0 mask 255.255.255.0 nomodify notrap
需要新增
server 127.127.1.0
fudge 127.127.1.0 stratum 10
第二:执行命令
clock -w
hwclock –systohc
然后再启动server,否则其它机器在同步时会出现问题,比如
1 |
Server dropped: strata too high |
(
========新增,如果出现上边的结果,可以在ntp server服务器执行如下命令:
watch ntpq -p
这个时候注意reach的值,这个值会一直变,必须大于某数值才可以正常同步,刚开始肯定会报上边的错,一会就好了,耐心等待
)
然后就是同步的命令是:
ntpdate 192.168.207.130
(服务要先停止/etc/init.d/ntpd stop )
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021