1)服务端部署
安装所需软件包
[root@test ~]# yum -y install ntp ntpdate 服务端自己先手工同步一次时间。
[root@test ~]# ntpdate ntp.sjtu.edu.cn
21 Jun 16:48:54 ntpdate[10781]: the NTP socket is in use, exiting 或者使用阿里云的时间服务器进行在线同步
[root@test ~]# ntpdate ntp2.aliyun.com
[root@test ~]# ntpdate ntp1.aliyun.com 编辑NTP主配置文件,添加NTP服务器(对于大陆地区的服务器)并同步BIOS时间。
对于位于中国大陆地区IDC机房的服务器,由于CentOS/RHEL默认的ntp服务器无法访问,因此要设置中国大陆地区自己的ntp服务器;
对于位于中国大陆地区以外的IDC机房的服务器,可以使用CentOS/RHEL默认的ntp服务器(但一定要检查确保可以访问);
修改如下:
[root@test ~]# cp /etc/ntp.conf /etc/ntp.conf.bak
[root@test ~]# vim /etc/ntp.conf
restrict default nomodify notrap noquery restrict 127.0.0.1
restrict 192.168.0.0 mask 255.255.0.0 nomodify #只允许192.168.0.0网段的客户机进行时间同步。如果允许任何IP的客户机都可以进行时间同步,就修改为"restrict default nomodify" server ntp1.aliyun.com
server ntp2.aliyun.com
server time1.aliyun.com
server time2.aliyun.com server time-a.nist.gov
server time-b.nist.gov server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10 driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys [root@test ~]# service ntpd start
Starting ntpd: [ OK ] [root@test ~]# netstat -tulnp | grep ntp
udp 0 0 182.48.115.233:123 0.0.0.0:* 10023/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 10023/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 10023/ntpd
udp 0 0 fe80::5054:ff:feab:db19:123 :::* 10023/ntpd
udp 0 0 ::1:123 :::* 10023/ntpd
udp 0 0 :::123 :::* 10023/ntpd 设置开机自启动
[root@test ~]# /sbin/chkconfig --level=2345 ntpd on 查看现有连接客户端
[root@test ~]# watch ntpq -p 服务端可以设置定期在线同步一次时间
[root@test ~]# crontab -l
#服务器时间同步
0 * * * * /usr/sbin/ntpdate ntp1.aliyun.com; /sbin/hwclock -w 2)客户端配置 (记住要关闭客户端机器的ntpd服务, 否则使用nepdate的时候, 会报错"ntpdate[14431]: the NTP socket is in use, exiting"; 或者开启ntpd服务前提下, 使用ntpdate -u ip就不会有那个报错了)
命令行手动执行一次验证是否可用:
[root@test2 ~]# ntpdate 182.148.15.33 #182.148.15.33是上面ntp服务器的ip地址
21 Jun 16:45:35 ntpdate[2323]: adjust time server 182.148.15.33 offset 0.319548 sec 配置自动同步
[root@test2 ~]# crontab -l
#服务器时间同步
*/5 * * * * /usr/sbin/ntpdate 182.148.15.33; /sbin/hwclock -w

最新文章

  1. “会”和 "好”纯粹是两个概念
  2. “玲珑杯”ACM比赛 Round #7 B -- Capture(并查集+优先队列)
  3. ios如何一个证书多台设备测试
  4. IOS简单的字串替换方法stringByTrimmingCharactersInSet 和空格的替换 ()
  5. Linux内核启动
  6. phpstorm 8 license key
  7. poj2429 大数分解+dfs
  8. 【python,排序】几种常用的排序算法,使用python实现
  9. DDD的好文章
  10. UVa 1583 Digit Generator(数学)
  11. c语言各类问题 代码
  12. 对比React Native、dcloud、LuaView三个框架技术(内部)
  13. java 在实例化异常的时候做的事情
  14. Keras和tensorflow的区别
  15. django-celery 创建多个broker队列 异步执行任务时指定队列
  16. SpringMybatis 整合JavaWeb
  17. xdoj 1146 (逆向01背包)
  18. C# ArrayList的使用方法小总结
  19. ARC下block使用情况
  20. Codeforces 225C Barcode(矩阵上DP)

热门文章

  1. 模拟开户接口,使用python脚本实现批量用户开通
  2. zookeeper-01 概述
  3. JDBC lesson 1
  4. Activiti工作流搭建---初始化数据库
  5. Vue项目兼容IE浏览器
  6. 习题 6 字符串(string)和文本
  7. windows下安装ElasticSearch的Head插件
  8. go标准库的学习-crypto/sha256
  9. python3 练习题 day01
  10. k8s部署失败原因