NTP

参考:http://blog.sina.com.cn/s/blog_75c7ccf40101hg5l.html
客户端:

  1. yum install ntp -y
  2. # 配置
  3. vim /etc/ntp.conf
  4. #server 0.centos.pool.ntp.org iburst
  5. #server 1.centos.pool.ntp.org iburst
  6. #server 2.centos.pool.ntp.org iburst
  7. #server 3.centos.pool.ntp.org iburst
  8. server 192.100.3.221 iburst
  9. # 设置开启服务后自动同步上级ntp server时间
  10. vim /etc/ntp/step-tickers
  11. 192.100.3.221
  12. # 启动
  13. systemctl restart ntpd
  14. systemctl enable ntpd
  15. # 开启同步
  16. ntpdate 192.100.3.221
  17. # 查看
  18. [root@node-1 conf]# ntpq -p
  19. remote refid st t when poll reach delay offset jitter
  20. ==============================================================================
  21. *yum_repository 192.100.3.221 11 u 42 64 377 0.167 0.667 0.123
  22. 前面有*说明同步成功
  23. # 查看是否开启 NTP synchronized: yes
  24. timedatectl
  25. ntpstat

服务端:

  1. #1.备份配置文件
  2. cp /etc/ntp.conf /etc/ntp.conf.bak
  3. #2.添加参数
  4. vim /etc/ntp.conf
  5. server controller iburst
  6. restrict -4 default kod notrap nomodify
  7. restrict -6 default kod notrap nomodify
  8. #3.注释以下参数
  9. #restrict default nomodify notrap nopeer noquery
  10. #restrict 127.0.0.1
  11. #restrict ::1
  12. #4.启动ntp服务
  13. systemctl enable ntpd.service
  14. systemctl start ntpd.service
  15. 配置文件中一般有restrict default语句,#掉后选择,以下2种的一种
  16. restrict default nomodify notrap noquery # 默认允许所有可连接客户端ntpdate到本机
  17. restrict default ignore # 默认所有客户端禁止ntpdate到本机
  18. #与上级服务端连续性同步时间,prefer表示优先,如无可不设置
  19. server 上级ntp服务器IP或者域名 [prefer]
  20. #当之前设置了restrict default ignore的情况下,可以设置哪些客户可以ntpdate到本机
  21. restrict 192.168.1.88 mask 255.255.255.255 nomodify notrap

chrony

  1. #安装
  2. yum install chrony -y
  3. #控制节点:vim /etc/chrony.conf
  4. server controller iburst
  5. # Serve time even if not synchronized to a time source.
  6. #打开注释,本机不同步任何主机的时间,本机作为时间源
  7. local stratum 10
  8. #允许访问的网段
  9. allow 10.0.0.0/24
  10. #其他节点:vim /etc/chrony.conf
  11. server controller iburst
  12. #启动
  13. systemctl enable chronyd.service
  14. systemctl restart chronyd.service
  15. ntpdate controller
  16. #验证
  17. chronyc sources
  18. chronyc sources -v 查看状态说明
  19. timedatectl