linux设置ntp时间同步

1.安装ntp

 ntp yum –y install ntp

2.设置ntp服务开机启动

 chkconfig ntpd on

3.将master节点设置为主服务器(在master节点操作)

3.1. vi /etc/ntp.conf,内容如下:

    driftfile /var/lib/ntp/ntp.drift #草稿文件

    # 允许内网其他机器同步时间

    restrict 192.168.137.0(替换成自己的ip) mask 255.255.255.0 nomodify notrap

    # Use public servers from the pool.ntp.org project.

    # 中国这边最活跃的时间服务器 :

    [http://www.pool.ntp.org/zone/cn](http://www.pool.ntp.org/zone/cn)

    server 210.72.145.44 perfer   # 中国国家受时中心

    server 202.112.10.36             # 1.cn.pool.ntp.org

    server 59.124.196.83             # 0.asia.pool.ntp.org  

    # allow update time by the upper server

    # 允许上层时间服务器主动修改本机时间

    restrict 210.72.145.44 nomodify notrap noquery

    restrict 202.112.10.36 nomodify notrap noquery

    restrict 59.124.196.83 nomodify notrap noquery  

    # 外部时间服务器不可用时,以本地时间作为时间服务

    server  127.127.1.0     # local clock

    fudge   127.127.1.0 stratum 10

3.2 重启服务:service ntpd restart

3.3查看同步状态:netstat -tlunp | grep ntp

4.设置slave到master的同步(slave节点操作)

4.1. vi /etc/ntp.conf,内容如下:

   driftfile /var/lib/ntp/ntp.drift # 草稿文件

   statsdir /var/log/ntpstats/

   statistics loopstats peerstats clockstats

   filegen loopstats file loopstats type day enable

   filegen peerstats file peerstats type day enable

   filegen clockstats file clockstats type day enable

   # 让NTP Server为内网的ntp服务器

   server 192.168.137.110 (master节点ip)

   fudge 192.168.137.110 stratum 5

   # 不允许来自公网上ipv4和ipv6客户端的访问

   restrict -4 default kod notrap nomodify nopeer noquery

   restrict -6 default kod notrap nomodify nopeer noquery

   # Local users may interrogate the ntp server more closely.

   restrict 127.0.0.1

   restrict ::1

4.2重启服务:service ntpd restart

4.3手动同步:ntpdate -u 192.168.137.110

 

  • 2
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值