2019独角兽企业重金招聘Python工程师标准>>>

本文测试环境如下:

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]#
[root@localhost ~]# yum install ntp
#等待安装完成后执行
[root@localhost ~]# rpm -qa | grep "ntp"
ntpdate-4.2.6p5-28.el7.centos.x86_64
ntp-4.2.6p5-28.el7.centos.x86_64
[root@localhost ~]#

首先演示ntp 客户端安装。

#部分系统需要安装
[root@localhost ~]# yum install ntpdate

本文推荐两个ntp服务器。

#国内
ntp.aliyun.comntp1.aliyun.com
ntp2.aliyun.com
ntp3.aliyun.comtime1.aliyun.com
time2.aliyun.com#国外
cn.ntp.org.cn0.cn.ntp.org.cn
1.cn.ntp.org.cn
2.cn.ntp.org.cn
3.cn.ntp.org.cnpool.ntp.orgasia.pool.ntp.org

安装完成后即可使用 ntpdate 同步时间。

[root@localhost ~]# ntpdate ntp.aliyun.com
22 Feb 10:32:03 ntpdate[7535]: adjust time server 203.107.6.88 offset -0.005418 sec
[root@localhost ~]# 

可以将同步命令作为一个定时执行任务。命令如下

下文演示搭建ntp服务器。

#检查ntp 安装情况,不是ntpdate
[root@localhost ~]# rpm -qa |grep ntp
ntpdate-4.2.6p5-28.el7.centos.x86_64
[root@localhost ~]# 

将时间同步作为定时任务。

#10点38分(不能颠倒,否则报错) ***(每年每月每天) 命令所在位置 服务器域名或ntp服务器ip地址 输出日志
38 10 * * * /usr/sbin/ntpdate ntp.aliyun.com >>/usr/local/logs/crontab/ntpdate.log

下文演示ntp服务器搭建。

[root@localhost ~]# yum install ntp
#等待安装完成执行命令
[root@localhost ~]# rpm -qa | grep "ntp"
ntpdate-4.2.6p5-28.el7.centos.x86_64
ntp-4.2.6p5-28.el7.centos.x86_64
[root@localhost ~]# 

重启服务。

[root@localhost ~]# service ntpd restart
Redirecting to /bin/systemctl restart ntpd.service
#显示NTP服务器节点
[root@localhost ~]# ntpq -premote           refid      st t when poll reach   delay   offset  jitter
==============================================================================203.107.6.88    100.107.25.114   2 u    2   64    1   54.932   21.875   0.000106.247.248.106 141.223.182.106  2 u    2   64    1   71.810   16.884   0.000
*LOCAL(0)        .LOCL.           5 l    2   64    1    0.000    0.000   0.000
[root@localhost ~]# 

关闭防火墙或添加规则,ntp 默认使用UDP 123端口,关闭SELinux。

[root@localhost ~]# service firewalld stop
#添加规则
[root@localhost ~]# firewall-cmd --zone=public --add-port=123/udp --permanent
success
[root@localhost ~]# service firewalld restart
Redirecting to /bin/systemctl restart firewalld.service
[root@localhost ~]# service firewalld status
Redirecting to /bin/systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since 五 2019-02-22 12:23:22 CST; 3s agoDocs: man:firewalld(1)Main PID: 7888 (firewalld)CGroup: /system.slice/firewalld.service└─7888 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid2月 22 12:23:22 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
2月 22 12:23:22 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
2月 22 12:23:22 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost ~]#

使用客户端同步,客户端IP为192.168.216.136。

[root@localhost ~]# ntpdate -d 192.168.216.137
22 Feb 12:17:06 ntpdate[7901]: ntpdate 4.2.6p5@1.2349-o Fri Apr 13 12:52:28 UTC 2018 (1)
Looking for host 192.168.216.137 and service ntp
host found : 192.168.216.137
transmit(192.168.216.137)
receive(192.168.216.137)
transmit(192.168.216.137)
receive(192.168.216.137)
transmit(192.168.216.137)
receive(192.168.216.137)
transmit(192.168.216.137)
receive(192.168.216.137)
server 192.168.216.137, port 123
stratum 6, precision -25, leap 00, trust 000
refid [192.168.216.137], delay 0.02591, dispersion 0.00000
transmitted 4, in filter 4
reference time:    e019f558.93ebd55b  Fri, Feb 22 2019 12:13:12.577
originate timestamp: e019f64a.8635f3c7  Fri, Feb 22 2019 12:17:14.524
transmit timestamp:  e019f64a.8f182003  Fri, Feb 22 2019 12:17:14.558
filter delay:  0.02597  0.02600  0.02591  0.02603 0.00000  0.00000  0.00000  0.00000
filter offset: -0.03505 -0.03503 -0.03503 -0.035000.000000 0.000000 0.000000 0.000000
delay 0.02591, dispersion 0.00000
offset -0.03503522 Feb 12:17:14 ntpdate[7901]: adjust time server 192.168.216.137 offset -0.035035 sec
[root@localhost ~]# ntpdate 192.168.216.137
22 Feb 12:17:28 ntpdate[7902]: adjust time server 192.168.216.137 offset -0.035002 sec
[root@localhost ~]#
#重启防火墙
[root@localhost ~]# systemctl restart firewalld.service
[root@localhost ~]#
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since 五 2019-02-22 12:23:22 CST; 9min agoDocs: man:firewalld(1)Main PID: 7888 (firewalld)CGroup: /system.slice/firewalld.service└─7888 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid2月 22 12:23:22 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
2月 22 12:23:22 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
2月 22 12:23:22 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost ~]#

客户端添加自动执行任务。


[root@localhost ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@localhost ~]#
#规则
0 0 * * * /usr/sbin/ntpdate 192.168.216.137 >>/data/logs/ntp.log 2>&1

转载于:https://my.oschina.net/u/1011130/blog/3013507

CentOS7 NTP客户端和服务器安装和使用相关推荐

  1. centos7源码安装ntp_如何安装和配置 Chrony 作为 NTP 客户端?

    NTP 服务器和 NTP 客户端可以让我们通过网络来同步时钟.之前,我们已经撰写了一篇关于 NTP 服务器和 NTP 客户端的安装与配置 的文章. 如果你想看这些内容,点击上述的 URL 访问. Ch ...

  2. 【Centos7 NTP 服务器和客户端配置(含离线状态) 附赠手动配置系统时间】

    Centos7 NTP 服务器和客户端配置(含离线状态)附赠手动配置系统时间 一.搭建NTP服务器 1.查看服务器.客户端操作系统版本 2.查看服务器是否安装ntp,系统默认安装ntpdate: 3. ...

  3. centos 6.5手动同步ntp时钟_如何安装和配置 Chrony 作为 NTP 客户端? | Linux 中国

    Chrony 是 NTP 客户端的替代品.它能以更精确的时间和更快的速度同步时钟,并且它对于那些不是全天候在线的系统非常有用.-- Magesh Maruthamuthu NTP 服务器和 NTP 客 ...

  4. NTP客户端通过脚本一键配置

    在上一篇博文NTP时间服务器安装配置详解中我已经讲解了如何配置NTP的服务端和客户端,但当进行集群的大规模配置时,一台一台的去手动配置NTP客户端会浪费我们很大的时间,所以这里我做了一个简单的脚本来实 ...

  5. Centos7 NTP时钟同步配置

    Centos7 NTP时钟同步配置 NTP在Linux下有两种时钟同步方式:直接同步(也称跳跃同步)和平滑同步(也称微调同步). 直接同步 使用ntpdate命令进行同步,直接进行时间变更. 如果服务 ...

  6. ntp协议客户端服务器模式,思科配置NTP客户端服务器模式

    思科配置NTP客户端服务器模式 内容精选 换一换 该操作指导安装工程师安装MRS集群所有服务(不包含Flume)的客户端.MRS针对不同服务提供了Shell脚本,供开发维护人员在不同场景下登录其对应的 ...

  7. centos7 ntp设置 时间同步

    一 应用场景 公司分配给你两台服务器,要求你使他们时间同步,有人问为什么要时间同步?如果一个集群中,时间相差很大,那么会出现很多诡异的问题,你也不想在一个无法解决的问题上浪费几天时间吧!总之,设置服务 ...

  8. CentOS7 NTP server + keepalived

    NTP安装 yum -y install ntp systemctl enable ntpd 首先同步一次时间 ntpdate time.windows.com ntp配置(Host1 Host2) ...

  9. windows ntp客户端配置,连接linux npt服务。

    服务器操作系统使用的centos系统.服务器之间通过NTP服务进行时间同步,客户端使用的window,需要同步服务端的时间. 配置windows ntp客户端步骤如下: 运行gpedit.msc 点击 ...

最新文章

  1. Win10 新版又悲剧了!老外神评论
  2. 【JavaScript基础笔记】模块化、立即执行函数应用、闭包应用
  3. spring boot + vue + element-ui全栈开发入门——前后端整合开发
  4. tkinter笔记:画布canvas
  5. Charles学习(四)之使用Map local代理本地静态资源以及配置移动端代理在真机上调试iOS和Android客户端...
  6. 协同过滤—基于图的方法
  7. mysql定义shell变量_shell 变量的定义,赋值,运算
  8. 线程同步-事件内核对象
  9. 数据库名、实例名、数据库域名、全局数据库名、服务名 我也迷糊了
  10. linux打开python3_Python3 执行Linux Bash命令的方法
  11. 佐藤hiroko-爱拯救了我(步之物语)
  12. apache ii评分怎么评_APACHE-II评分表.doc
  13. OpenV$P$N服务器添加客户端
  14. 非同帆响-得帆信息发布全新高生产力PaaS平台,重新定义企业软件生产力
  15. trie图:Computer Viruses in Planet Pandora
  16. Thingworx自定义扩展开发(三)- echarts集成
  17. 学校宿舍天翼校园网构建路由器
  18. 【win技巧】Windows10支持快捷键右键菜单新建文本文档
  19. 利用eda函数对文本数据进行增强
  20. 安装Python(绿色版)

热门文章

  1. 多迪新手学UI设计,拿高薪必须掌握的几个小技巧?
  2. rtmp Chunk stream ID 说明
  3. locate,find
  4. 蓝桥学院2019算法题1.7
  5. Apache Flink 漫谈系列(12) - Time Interval(Time-windowed) JOIN...
  6. 最简单的启动Docker实例Mesos Golang Framework
  7. Zip Slip目录遍历漏洞已影响多个Java项目
  8. WIN2008系统的IIS7.0配置REWRITE伪静态环境
  9. async [ə'zɪŋk] 函数
  10. 新手搭建阿里云FTP服务器