位置: 编程技术 - 正文

Linux系统下NTP协议的超级配置攻略(linux的ntp服务)

编辑:rootadmin
在Linux系统中,为了避免主机时间因为在长时间运行下所导致的时间偏差,进行时间同步(synchronize)的工作是非常必要的。Linux系统下,一般使用ntp服务来同步不同机器的时间。NTP 是网络时间协议(Network Time Protocol)的简称,干嘛用的呢?就是通过网络协议使计算机之间的时间同步化。安装NTP包检查是否安装了ntp相关包。如果没有安装ntp相关包,使用rpm或yum安装,安装也非常简单方便。 复制代码代码如下:[root@localhost ~]# rpm -qa | grep ntpntpdate-4.2.6p5-1.el6.x_fontpackages-filesystem-1.-1.1.el6.noarchntp-4.2.6p5-1.el6.x_ NTP的配置A: 配置/etc/ntp.confNTP Server的主要配置文件为/etc/ntp.conf ,没有修改过的ntp.conf文件内容如下所示,配置选项都有相关注释信息(Linux 版本为Red Hat Enterprise Linux Server release 6.6 )复制代码代码如下:[root@localhost ~]# more /etc/ntp.conf# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). driftfile /var/lib/ntp/drift # Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.restrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could# be tightened as well, but to do so would effect some of# the administrative functions.restrict .0.0.1 restrict -6 ::1 # Hosts on local network are less restricted.#restrict ..1.0 mask ...0 nomodify notrap # Use public servers from the pool.ntp.org project.# Please consider joining the pool ( 0.rhel.pool.ntp.org iburstserver 1.rhel.pool.ntp.org iburstserver 2.rhel.pool.ntp.org iburstserver 3.rhel.pool.ntp.org iburst #broadcast ..1. autokey # broadcast server#broadcastclient # broadcast client#broadcast .0.1.1 autokey # multicast server#multicastclient .0.1.1 # multicast client#manycastserver ... # manycast server#manycastclient ... autokey # manycast client # Enable public key cryptography.#crypto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys # Specify the key identifiers which are trusted.#trustedkey 4 8 # Specify the key identifier to use with the ntpdc utility.#requestkey 8 # Specify the key identifier to use with the ntpq utility.#controlkey 8 # Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats[root@localhost ~]# more /etc/ntp.conf# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). driftfile /var/lib/ntp/drift # Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.restrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could# be tightened as well, but to do so would effect some of# the administrative functions.restrict .0.0.1 restrict -6 ::1 # Hosts on local network are less restricted.#restrict ..1.0 mask ...0 nomodify notrap # Use public servers from the pool.ntp.org project.# Please consider joining the pool ( 0.rhel.pool.ntp.org iburstserver 1.rhel.pool.ntp.org iburstserver 2.rhel.pool.ntp.org iburstserver 3.rhel.pool.ntp.org iburst #broadcast ..1. autokey # broadcast server#broadcastclient # broadcast client#broadcast .0.1.1 autokey # multicast server#multicastclient .0.1.1 # multicast client#manycastserver ... # manycast server#manycastclient ... autokey # manycast client # Enable public key cryptography.#crypto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys # Specify the key identifiers which are trusted.#trustedkey 4 8 # Specify the key identifier to use with the ntpdc utility.#requestkey 8 # Specify the key identifier to use with the ntpq utility.#controlkey 8 # Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats各个选项信息:#系统时间与BIOS事件的偏差记录driftfile /etc/ntp/drift restrict 控制相关权限。语法为: restrict IP地址 mask 子网掩码 参数其中IP地址也可以是default ,default 就是指所有的IP参数有以下几个:ignore :关闭所有的 NTP 联机服务nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟kod : 访问违规时发送 KoD 包。restrict -6 表示IPV6地址的权限设置。1:设定NTP主机来源(其中prefer表示优先主机),..7.是本地的NTP服务器,所以优先指定从该主机同步时间。 复制代码代码如下:server ..7. prefer server 0.rhel.pool.ntp.org iburst server 1.rhel.pool.ntp.org iburst server 2.rhel.pool.ntp.org iburst server 3.rhel.pool.ntp.org iburst2:限制你允许的这些服务器的访问类型,在这个例子中的服务器是不容许修改运行时配置或查询您的Linux NTP服务器 复制代码代码如下:restrict ..0.0 mask ...0 notrust nomodify notrap在上例中,掩码地址扩展为,因此从..0.1-..0.的服务器都可以使用我们的NTP服务器来同步时间 复制代码代码如下:#此时表示限制向从..0.1-..0.这些IP段的服务器提供NTP服务。restrict ..0.0 mask ...0 notrust nomodify notrap noquery #设置默认策略为允许任何主机进行时间同步restrict default ignore 3:确保localhost(这个常用的IP地址用来指Linux服务器本身)有足够权限.使用没有任何限制关键词的语法:复制代码代码如下:restrict .0.0.1 restrict -6 ::1 B:配置/etc/ntp/stpe-tickers文件修改/etc/ntp/stpe-tickers文件,内容如下(当ntpd服务启动时,会自动与该文件中记录的上层NTP服务进行时间校对)复制代码代码如下:[root@localhost ntp]# more /etc/ntp/step-tickers # List of servers used for initial synchronization.[root@localhost ntp]# vi /etc/ntp/step-tickers # List of servers used for initial synchronization.server ..7. preferserver 0.rhel.pool.ntp.orgserver 1.rhel.pool.ntp.org server 2.rhel.pool.ntp.org server 3.rhel.pool.ntp.org C:配置/etc/sysconfig/ntpd文件ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。复制代码代码如下:#允许BIOS与系统时间同步,也可以通过hwclock -w 命令SYNC_HWCLOCK=yes IPTABLES 配置由于NTP服务需要使用到UDP端口号,所以当系统的防火墙(Iptables)启动的情况下,必须开放UDP端口号。复制代码代码如下:[root@localhost ~]# /etc/init.d/iptables statusTable: filterChain INPUT (policy ACCEPT)num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt: 5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)num target prot opt source destination [root@localhost ~]# /sbin/iptables -I INPUT -p udp --dport -j ACCEPT[root@localhost ~]# /etc/init.d/iptables statusTable: filterChain INPUT (policy ACCEPT)num target prot opt source destination 1 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt: 2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 3 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt: 6 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)num target prot opt source destination [root@localhost ~]# 如果防火墙没有开放UDP端口号,有可能出现下面情况。复制代码代码如下:[root@localhost ~]# /usr/sbin/ntpq -c rv | grep stratumstratum=, precision=-, rootdelay=0., rootdisp=3., refid=INIT,[root@localhost~]# A stratum level of indicates that NTP is not synchronizing correctly.If a stratum level of is detected, wait minutes and issue the command again. It may take this long for the NTP server to stabilize.If NTP continues to detect a stratum level of , verify that the NTP port (UDP Port ) is open on all firewalls between the cluster and the remote machine you are attempting to synchronize to. 启动NTP服务复制代码代码如下:[root@localhost ~]# service ntpd statusntpd is stopped[root@localhost ~]# service ntpd startStarting ntpd: [ OK ][root@localhost ~]# service ntpd status #查看ntpd服务状态service ntpd start #启动ntpd服务service ntpd stop #停止ntpd服务service ntpd restart #重启ntpd服务检查ntp服务是否开机启动,将其设置为开机启动。[root@localhost ~]# chkconfig --list ntpdntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off[root@localhost ~]# runlevelN 3[root@localhost ~]# chkconfig ntpd on #在运行级别2、3、4、5上设置为自动运行[root@localhost ~]# chkconfig --list ntpdntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off[root@localhost ~]# 如果要设置在运行级别上自动运行,可以使用下面命令复制代码代码如下:chkconfig --level ntpd on可以用下面命令检测NTP服务是否运行复制代码代码如下:[root@localhost ~]# pgrep ntpd [root@localhost ~]# netstat -tlunp | grep ntp #如果看到端口,说明ntp服务成功启动。udp 0 0 ..7.: 0.0.0.0:* /ntpd udp 0 0 .0.0.1: 0.0.0.0:* /ntpd udp 0 0 0.0.0.0: 0.0.0.0:* /ntpd udp 0 0 fe:::ff:feb3:b5: :::* /ntpd udp 0 0 ::1: :::* /ntpd udp 0 0 ::: :::* /ntpd [root@localhost ~]# 查看ntp服务器有无和上层ntp连通复制代码代码如下:[root@localhost ~]# ntpstatsynchronised to NTP server (..7.) at stratum 6 time correct to within ms polling server every s[root@localhost ~]# 查看ntp服务器与上层ntp的状态remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先refid - 参考上一层ntp主机地址st - stratum阶层when - 多少秒前曾经同步过时间poll - 下次更新在多少秒后reach - 已经向上层ntp服务器要求更新的次数 delay - 网络延迟offset - 时间补偿jitter - 系统时间与bios时间差要查看 ntpd 进程的状态,请运行以下命令,按 Ctrl+C 停止查看进程。remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先refid - 参考上一层ntp主机地址st - stratum阶层when - 多少秒前曾经同步过时间poll - 下次更新在多少秒后reach - 已经向上层ntp服务器要求更新的次数 delay - 网络延迟offset - 时间补偿jitter - 系统时间与bios时间差要查看 ntpd 进程的状态,请运行以下命令,按 Ctrl+C 停止查看进程。

推荐整理分享Linux系统下NTP协议的超级配置攻略(linux的ntp服务),希望有所帮助,仅作参考,欢迎阅读内容。

Linux系统下NTP协议的超级配置攻略(linux的ntp服务)

文章相关热门搜索词:linux系统ntp服务,ntp linux,linux系统ntp服务怎么配置,linux系统ntp服务,ntp linux,linux系统ntp服务怎么配置,linux ntp client,linux系统ntp服务怎么配置,内容如对您有帮助,希望把文章链接给更多的朋友!

六款常见的Linux操作系统推荐 你可曾知道Linux的魅力或威力来自哪里?那就是,由于众多发行版百花齐放,Linux的阵营日益壮大,每一款发行版都拥有一大批用户,开发者自愿为相关

Linux下使用socktop来检测socket的通讯状况 所有的socket通讯都是通过socket接口来的,任何family的通讯包括unix域套接都要走的,所以只要截获了socket读写的几个syscall就可以了解unix域套接字的发送

Linux系统的dd命令使用教程 一、基础用法dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换。注意:指定数字的地方若以下列字符结尾,则乘以相应的数字:b=

标签: linux的ntp服务

本文链接地址:https://www.jiuchutong.com/biancheng/353292.html 转载请保留说明!

上一篇:Linux中的LVM之增加容量与删除卷的方法详解(linux的lvm扩容)

下一篇:六款常见的Linux操作系统推荐(六款常见的墨水)

  • 申请A级纳税企业需具备哪些条件
  • 可供出售金融资产和长期股权投资
  • 出货一般要多久
  • 所得税可以预交吗现在
  • 固定资产与累计折旧有对应关系吗
  • 企业房产税怎么申报缴纳
  • 所有逾期未抵扣进项税额
  • 外币借款汇兑差额资本化额怎么计算
  • 汇款手续费的会计科目
  • 所得税汇算清缴报告在哪查
  • 暂估的成本跨年了怎么冲销后要调整报表吗
  • 经纪人佣金计入什么科目
  • 发票报销哪些能用专票
  • 股权转让个人交的印花税可以入账吗
  • 年终奖和当月工资合并申报税
  • 销售方未抄报税的专票购买方能抵扣吗?
  • 专票打印的时候密码区压线了能用吗
  • 税务局申请发票
  • 税务局开租赁发票
  • 如何从百旺开票系统中导出开票明细
  • 福建水利建设专业排名
  • 辞退福利税前扣除标准
  • 增值税为什么申报不了
  • 公司委托法人代收款
  • 国有资产无偿划转实施方案
  • 检查所得税发现纳税差异如何调账?
  • 产品研发费用属于固定成本吗
  • 公司买的油烟机可以抵扣进项税吗
  • 企业破产应收账款要发询证函吗
  • 转让长期股权投资怎么算
  • 在Win7系统中,文件的属性包括
  • 小微企业 记账
  • 工会经费申报的依据
  • windows已禁用
  • win11可以玩游戏吗
  • 天然气 初装费
  • mmc.exe是什么进程
  • 腾达ac9路由器怎么样
  • 税收滞纳金可以抵税吗
  • cesium加载s3m
  • 职工报工伤后用人单位还有赔偿吗
  • framework3.5怎么打开
  • joomla中文手册
  • 借应付职工薪酬贷其他应收款
  • 其他综合收益的借贷方向
  • 消费税减免规定有哪些
  • react 16.8 新特性
  • 分公司在外地,企业怎么交税
  • 分公司财务核算独立不独立
  • 小规模纳税人每月不超过10万
  • 工程施工企业的增值税税率是多少
  • 交易性金融包括哪些
  • 发票遗失要如何补办
  • MySQL的Query Cache原理分析
  • 关于种植养殖的手抄报
  • 劳务费发票是个人的吗
  • 金税盘要交税吗
  • 专职独立研发企业是指
  • 跨区域缴纳个税相关规定
  • 申报抵扣了不做账怎么处理?
  • 过期食品返厂会重新打日期吗
  • 不动产分期抵扣表数据
  • 总帐设置在哪
  • mssql导出数据库
  • 怎样让windows media player播放mkv文件
  • win10累积更新 卡住
  • 360se是什么文件夹
  • keyemain.exe是什么
  • qt绘制3d
  • linux常用shell命令
  • 用python写周字
  • unity一运行就停止工作
  • angularjs4
  • 如何用jquery
  • multiset volatile
  • 民办非企业单位登记管理暂行条例
  • 国家税务总局办税指南
  • 江西国税局电话客服热线
  • 新土地管理法37条解释
  • 融资租赁公司购入老旧租赁资产会计处理
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设