集群系统时间同步(Centos7)
一、网格图示
二、同步服务的安装
注:此处用bigdata11主机做时钟同步的主节点,bigdata12和bigdata13时间都向它看齐。
2.1、监测服务器是否安装了时钟同步服务
命令:rpm -qa |grep ntpd
如果命令执行后啥也不显示则表示没安装
2.2、安装时间同步服务 (所有节点都需要执行)
命令:yum install ntp
结尾出现Complete! 则表示安装完成。
三、同步服务主节点的配置(只需要主节点bigdata11配置)
3.1、vi /etc/ntp.conf
去掉这个注释,去掉下面这行配置前面的注释符“#”,将ip改成bigdata11的网段(后面的0不要变)
restrict 192.168.108.0 mask 255.255.255.0 nomodify notrap
注释掉这几个
#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
添加一下内容
server 127.127.1.0
fudge 127.127.1.0 stratum 10
3.2、vi /etc/sysconfig/ntpd 加入下面一句话,用于配置boot时间和系统时间同步 (主节点操作)
SYNC_HWCLOCK=yes
3.3、启动服务
启动服务命令: sudo service ntpd start
检查服务状态:sudo service ntpd status
chkconfig ntpd on
chkconfig --list |grep ntpd
service ntpd status #查看ntpd服务状态
service ntpd start #启动ntpd服务
service ntpd stop #停止ntpd服务
service ntpd restart #重启ntpd服务
四、时钟同步服务从节点配置(主节点不用配置,所有从节点配置)
使用 root用户操作
输入 crontab -e 命令进入编辑状态,然后输入一下内容 (每1分钟同步一次时间)
* * * * * /usr/sbin/ntpdate bigdata11
(该任务保存在目录/var/spool/cron 下,必须用root用户才能看到 )
五、验证
设置系统时间: date -s "2020-03-26 10:23:33"
查看系统时间: date -R
可根据这2个命令来验证主节点时间改变了,一分钟后从节点时间是否改变。