NTP 时区+时间同步

一台主机作为server(时间服务器),其它机架作为client(客户机)从server同步时间

  • 准备

安装ntp和ntpdate
yum install -y ntpdate
yum install -y ntp

server

  1. 选一天机器作为server
  • 修改 /etc/ntp.conf,添加如下
# 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn
server 0.cn.pool.ntp.org
server 0.asia.pool.ntp.org
server 3.asia.pool.ntp.org

# allow update time by the upper server 
# 允许上层时间服务器主动修改本机时间 
restrict 0.cn.pool.ntp.org nomodify notrap noquery 
restrict 0.asia.pool.ntp.org nomodify notrap noquery 
restrict 3.asia.pool.ntp.org nomodify notrap noquery

# Undisciplined Local Clock. This is a fake driver intended for backup 
# and when no outside source of synchronized time is available. 
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock 
fudge 127.127.1.0 stratum 10
  • 启动服务
service ntpd start
  • 查看
ntpdstat 

Client

  • 定时从server端同步时间
  • 添加如下定时任务,保存
[root@hadoop003 .ssh]# crontab -e

*/5 * * * * /usr/sbin/ntpdate 192.168.52.131

注意: NTP服务只需在server端开启,Client端不需要开启

猜你喜欢

转载自blog.csdn.net/huonan_123/article/details/87983313