Linux下ntp时间服务器配置

大数据环境下对时间要求很高,因此集群内须要同步时间。本例子使用一台master主机同步外部时间,其他两台slave同步master的时间。服务器

时区选择

在三台机器上分别执行大数据

timedatectl set-timezone "Asia/Shanghai"

统一设置时区spa

安装ntp

三台机器上分别执行rest

yum install -y ntp
配置ntp服务
(1)master主机(192.168.21.161) 修改/etc/ntp.conf文件
restrict 192.168.21.161 nomodify notrap nopeer noquery

192.168.21.161为master主机的ip地址code

restrict 192.168.21.1 mask 255.255.255.0 nomodify notrap

网关和子网掩码server

并注释掉server 0 ~ n,添加同步时间服务器地址blog

server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst
server ntp5.aliyun.com iburst
server ntp6.aliyun.com iburst
server ntp7.aliyun.com iburst

具体内容以下
屏幕快照 2019-11-19 下午4.51.45.pngip

(2)slave1(192.168.21.162) 修改/etc/ntp.conf文件v8

restrict 192.168.21.162 nomodify notrap nopeer noquery

192.168.21.162为slave1的主机ip地址同步

restrict 192.168.21.1 mask 255.255.255.0 nomodify notrap

网关和子网掩码

并注释掉server 0 ~ n,指定master为server

server 192.168.21.161
Fudge 192.168.21.161 stratum 10

具体内容以下
屏幕快照 2019-11-19 下午8.31.46.png
(3)slave2(192.168.21.163) 修改/etc/ntp.conf文件
与slave1内容类似

restrict 192.168.21.163 nomodify notrap nopeer noquery

192.168.21.163为slave2的主机ip地址

restrict 192.168.21.1 mask 255.255.255.0 nomodify notrap

网关和子网掩码

并注释掉server 0 ~ n,指定master为server

server 192.168.21.161
Fudge 192.168.21.161 stratum 10

具体内容以下
屏幕快照 2019-11-19 下午8.35.22.png

启动ntp服务

systemctl start ntpd.service

设置开机启动

systemctl enable ntpd.service

查看状态

ntpstat
synchronised to NTP server (192.168.21.161) at stratum 4
   time correct to within 84 ms
   polling server every 1024 s

ntp服务启动后并不会立刻就同步时间,因此ntpstat状态不会立刻成为synchronised。正常过5~10分钟后会同步

PS:
查看网关命令

ip route show

关闭防火墙,不然ntp服务的端口123可能会被阻

systemctl stop firewalld

查看防火墙状态

systemctl status firewalld
相关文章
相关标签/搜索