查看时区
timedatectl status|grep 'Time zone'
#设置时区为上海
timedatectl set-timezone Asia/Shanghai
#设置硬件时钟调整为与本地时钟一致
timedatectl set-local-rtc 1
使用ntpdate
同步时间
#安装ntpdate
yum -y install ntpdate
#同步时间
ntpdate -u pool.ntp.org
#同步完成后,date命令查看时间是否正确
date
more /etc/redhat-release
ps -ef|grep ntp
ll /etc/|grep ntp
systemctl status ntpd
通过ansible集群安装ntp
ansible all -a "yum install -y ntp"
#批量设置 主机 时区为亚洲上海
ansible all -a "timedatectl set-timezone Asia/Shanghai"
172作为主节点
vim /etc/ntp.conf
#添加本地节点
restrict 10.9.70.172 monodify notrap nopeer noquery
166、168服务器同步主节点172的时间
#本地节点
restrict 10.9.70.166 nomodify notrap nopeer noquery
#主节点server
server 10.9.70.172 perfer iburst
#开启服务
service ntpd start
#设置为默认启动,关掉使用off
chkconfig ntpd on
#查看状态
service ntpd status