一、环境

[root@m01 tmp]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@m01 tmp]# hostname -I
10.0.0.61(外网) 172.16.1.61(内网)

二、检查服务软件是否安装

[root@m01 tmp]# rpm -qa ntp
ntp-4.2.6p5-.el6.centos..x86_64

三、修改ntp配置文件

sed -i '8c restrict default nomodify' /etc/ntp.conf替换配置文件的第8行内容,也可以使用vim
vim /etc/ntp.conf
# restrict default kod nomodify notrap nopeer noquery
restrict default nomodify#允许局域网时间同步
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#将原有的不可用的源注释,添加新的时间同步源
server ntp1.aliyun.com
server time.nist.gov

四、启动ntp服务(这台服务器是需要外网的)

[root@m01 tmp]# /etc/init.d/ntpd start
Starting ntpd: [ OK ]

注:

启动后会自动更新时间

如果原来有同步时间的任务,关闭,否则会报如下的错误。

ntpdate[118978]: the NTP socket is in use, exiting

服务端执行ntpstat结果如下证明时间已同步

[root@m01 ~]# ntpstat
synchronised to NTP server (182.92.12.11) at stratum
time correct to within ms
polling server every s

五、无外网的服务器同步时间

[root@nfs01 ~]# ntpdate 172.16.1.61
Oct :: ntpdate[]: adjust time server 172.16.1.61 offset 0.000652 sec
#时间服务器启动后,需要过几分钟才能进行同步。
ntpdate[5687]: no server suitable for synchronization found

六、把同步命令放入定时任务

[root@nfs01 ~]# crontab -l
#time sync by yanxinjiang at -10-10
*/ * * * * /usr/sbin/ntpdate 172.16.1.61 >/dev/null >&

最新文章

  1. npm常用命令
  2. PHP XML和数组互相转换
  3. 使用手机展示axure
  4. Jquery和其他库($的好处)
  5. U8Bom查询
  6. 宅男福利--利用Python简单爬图
  7. 关于CPU亲和性的测试
  8. 使用.htaccess实现apache URL重定向
  9. [git] git 分支( branch ) 的基本使用
  10. android spinner 每行字体颜色都变化
  11. Linux下获取硬盘使用情况
  12. zf-关于评价器的开关所在的配置文件,与代码如何修改。
  13. c++读取REG_MULTI_SZ类型注册表
  14. 解决win10系统以太网适配器的驱动程序可能出现问题
  15. Office 365 Connectors 的使用与自定义开发
  16. Spring Cloud学习笔记-002
  17. OO_多线程电梯_单元总结
  18. 【重磅】Spring Boot 2.1.0 权威发布
  19. hive数据导出到本地目录 抛异常
  20. 2018php最新面试题之PHP核心技术

热门文章

  1. 永久关闭Linux的防火墙
  2. Exchanger 源码分析
  3. arduino库函数1
  4. SUSTOJ_路痴的单身小涵(图中最短路的条数)
  5. 如何使用IDEA将项目上传到GitHub中
  6. [2019杭电多校第七场][hdu6646]A + B = C(hash)
  7. Python学习-第一天-函数和模块的使用
  8. A*(A_star)搜索总结
  9. kotlin和vertx和mongo写的一个服务器验证登陆功能(很简陋)
  10. Python 的 sys 模块常用方法?