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

猜你喜欢

转载自blog.csdn.net/u014516601/article/details/81433594