大数据环境下对时间要求很高,所以集群内需要同步时间。本例子使用一台master主机同步外部时间,其余两台slave同步master的时间。
时区选择
在三台机器上分别执行
timedatectl set-timezone "Asia/Shanghai"
统一设置时区
安装ntp
三台机器上分别执行
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地址
restrict 192.168.21.1 mask 255.255.255.0 nomodify notrap
网关和子网掩码
并注释掉server 0 ~ n,添加同步时间服务器地址
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
具体内容如下
(2)slave1(192.168.21.162) 修改/etc/ntp.conf文件
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
具体内容如下
(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
具体内容如下
启动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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。