OracleLinux NTP时间服务器配置同步方案
linux时间同步

linux时间同步1. 与一个已知的时间服务器同步2. 配置网络时间协议(ntp)1. 让linux自动同步时间#crontab -e加上一句:00 0 1 * * root rdate -s 是一个时间服务器.2. 时间服务器配置(192.168.0.10)2.1 # rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm2.2 # vi /etc/ntp.conf注释一行restrict default ignore加入一行restrict 192.168.0.10 mask 255.255.255.0 notrust nomodify notrap2.3 # vi /etc/ntp/step-tickers加入一行 这样每次ntpd启动时,会自动连接该国际标准时间服务器;2.4 # service ntpd start2.5 # netstat -an |grep 123 确保该端口以udp方式开放时间客户端配置(192.168.0.10)1)# ntpdate 192.168.10.2 应该显示同步成功2)# crontab -e加入0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1表示每隔10分钟同步一次时间如果你的linux client是加入到windows域内,且你的网络内已经设置了time server 你可以直接运行2)# crontab -e加入0-59/10 * * * * /usr/sbin/ntpdate time server 的FDN比如我的就是: 0-59/10 * * * * /usr/sbin/ntpdate 。
linux下NTPserver配置及AVAYA同步NTP

linux下NTPserver配置及AVAYA同步NTPlinux下NTP server配置及CM同步NTP1.ntp包安装ntp安装包在安装光盘的Server文件目录下;2.Linux NTP Server 配置使用root帐号登录liunx,输入vi /etc/ntp.conf在配置文档中加入restrict IP地址段(此处输入NTP client端的IP地址段,例如10.130.154.0)如果需要将此NTP Server同步与其他NTP Server,再加入Server IP地址(同步的NTP Server 地址)。
保存配置文件后,输入service ntpd start用以启用ntp服务。
3.CM6设置同步NTP打开VSP Console的web管理页面,使用管理员帐号登录。
在左侧导航栏中选择Server Management——Date/time Configuration在Manage Time Servers——Time server中填入Linux NTP Server的IP地址,点击Add,完成后此IP会显示在Added Servers 中。
然后点击Set Date and Time中的Start ntpd即可启用。
NTP—配置说明(ntp.conf设置)一、NTP服务的设置1.NTP软件包的结构NTP服务的配置文件:/etc/ntp.conf :这个是NTP 服务的主要配置文件,不同的Linux 版本文件所在的目录可能会不同!与NTP服务有关的Linux 系统文件及目录:/usr/share/zoneinfo:这是个目录,在这个目录下是规定了各主要时区的时间设定文件,例如中国大陆地区的时区设置文件是/usr/share/zoneinfo/Asia/Shanghai 。
/etc /sysconfig/clock:这个文件是Linux 的主要时区设定文件。
每次启动后,Linux 会自动读取这个文件来设定系统预设要显示的时间!比如这个文件内容为“ZONE=Asia/Shanghai”,这表示我们的时间设定使用/usr/share/zoneinfo/Asia/Shanghai 这个文件!/etc/localtime:这个文件是本地系统的时间设定文件!假设clock 文件里面规定了使用的时间设定文件为/usr/share/zoneinfo/Asia/Shanghai,Linux 系统就会将Shanghai 那个文件复制一份为/etc/localtime ,所以系统的时间显示就会以Shanghai 那个时间设定文件为准。
Linux的时间设置和同步(NTP)

Linux的时间设置和同步(NTP)Network Time Protocol (NTP) 也是RHCE新增的考试需求. 学习的时候也顺便复习了⼀下怎么设置Linux的时间,⽬前拿出来和⼤家分享设置NTP服务器不难不过NTP本⾝是个⾮常复杂的协议. 这⾥只是简要地介绍⼀下实践⽅法和上次相同,下⾯的实验都在RHEL5上运⾏1. 时间和时区如果有⼈问你说⽬前⼏点? 你看了看表回答他说晚上8点了. 这样回答看上去没有什么问题,不过如果问你的这个⼈在欧洲的话那么你的回答就会让他⾮常疑惑,因为他那⾥还太阳当空呢.这⾥就有产⽣了⼀个怎么定义时间的问题.因为在地球环绕太阳旋转的24个⼩时中,世界各地⽇出⽇落的时间是不相同的.所以我们才有划分时区(timezone)的必要,也就是把全球划分成24个不同的时区. 所以我们能把时间的定义理解为⼀个时间的值加上所在地的时区(注意这个所在地能精确到城市)地理课上我们都学过格林威治时间(GMT), 他也就是0时区时间. 不过我们在计算机中经常看到的是UTC. 他是CoordinatedUniversal Time的简写.虽然能认为UTC和GMT的值相等(误差相当之⼩),不过UTC已被认定为是国际标准,所以我们都应该遵守标准只使⽤UTC那么如果⽬前中国当地的时间是晚上8点的话,我们能有下⾯两种表⽰⽅式20:00 CST12:00 UTC这⾥的CST是Chinese Standard Time,也就是我们通常所说的北京时间了. 因为中国处在UTC+8时区,依次类推那么也就是12:00 UTC了.为什么要说这些呢(呵呵这⾥不是地理论坛吧...)?第⼀,不管通过所有渠道我们想要同步系统的时间,通常提供⽅只会给出UTC+0的时间值⽽不会提供时区(因为他不知道你在哪⾥).所以当我们设置系统时间的时候,设置好时区是⾸先要做的⼯作第⼆,⾮常多国家都有夏令时(我记得⼩时候中国也实⾏过⼀次),那就是在⼀年当中的某⼀天时钟拨快⼀⼩时(⽐如从UTC+8⼀下变成UTC+9了),那么同理到时候还要再拨慢回来.如果我们设置了正确的时区,当需要改动时间的时候系统就会⾃动替我们调整⽬前我们就来看⼀下怎么在Linux下设置时区,也就是time zone2. 怎么设置Linux Time Zone在Linux下glibc提供了我们事先编译好的许多timezone⽂件, 他们就放在/usr/share/zoneinfo这个⽬录下,这⾥基本涵盖了⼤部分的国家和城市代码:# ls -F /usr/share/zoneinfo/Africa/ Chile/ Factory Iceland Mexico/ posix/ UniversalAmerica/ CST6CDT GB Indian/ Mideast/ posixrules US/Antarctica/ Cuba GB-Eire Iran MST PRC UTCArctic/ EET GMT iso3166.tab MST7MDT PST8PDT WETAsia/ Egypt GMT0 Israel Navajo right/ W-SUAtlantic/ Eire GMT-0 Jamaica NZ ROC zone.tabAustralia/ EST GMT+0 Japan NZ-CHAT ROK ZuluBrazil/ EST5EDT Greenwich Kwajalein Pacific/ SingaporeCanada/ Etc/ Hongkong Libya Poland TurkeyCET Europe/ HST MET Portugal UCT在这⾥⾯我们就能找到⾃⼰所在城市的time zone⽂件. 那么如果我们想查看对于每个time zone当前的时间我们能⽤zdump命令代码:# zdump HongkongHongkong Fri Jul 6 06:13:57 2007 HKT那么我们⼜怎么来告诉系统我们所在time zone是哪个呢? ⽅法有⾮常多,这⾥举出两种第⼀个就是修改/etc/localtime这个⽂件,这个⽂件定义了我么所在的local time zone.我们能在/usr/share/zoneinfo下找到我们的time zone⽂件然后拷贝去到/etc/localtimezone(或做个symbolic link)假设我们⽬前的time zone是BST(也就是英国的夏令时间,UTC+1)代码:# dateThu Jul 5 23:33:40 BST 2007我们想把time zone换成上海所在的时区就能这么做代码:# ln -sf /usr/share/zoneinfo/posix/Asia/Shanghai /etc/localtime# dateFri Jul 6 06:35:52 CST 2007这样时区就改过来了(注意时间也做了相应的调整)第⼆种⽅法也就设置TZ环境变量的值. 许多程式和命令都会⽤到这个变量的值. TZ的值能有多种格式,最简单的设置⽅法就是使⽤tzselect命令代码:# tzselect...TZ=’America/Los_Angeles’;export TZtzselect会让你选择所在的国家和城市(我省略了这些步骤),最后输出相应的TZ变量的值.那么如果你设置了TZ的值之后时区就⼜会发⽣变化代码:# dateThu Jul 5 15:48:11 PDT 2007通过这两个例⼦我们也能发现TZ变量的值会override /etc/localtime.也就是说当TZ变量没有定义的时候系统才使⽤/etc/localtime来确定time zone. 所以你想永久修改time zone的话那么能把TZ变量的设置写⼊/etc/profile⾥好了⽬前我们知道怎么设置时区了,下⾯我们就来看看怎么设置Linux的时间吧3. Real Time Clock(RTC) and System Clock说道设置时间这⾥还要明确另外⼀个概念就是在⼀台计算机上我们有两个时钟:⼀个称之为硬件时间时钟(RTC),更有⼀个称之为系统时钟(System Clock)硬件时钟是指嵌在主板上的特别的电路, 他的存在就是平时我们关机之后还能计算时间的原因系统时钟就是操作系统的kernel所⽤来计算时间的时钟. 他从1970年1⽉1⽇00:00:00 UTC时间到⽬前为⽌秒数总和的值在Linux下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各⾃独⽴运⾏了那么既然两个时钟独⾃运⾏,那么时间久了必然就会产⽣误差了,下⾯我们来看⼀个例⼦代码:# dateFri Jul 6 00:27:13 BST 2007# hwclock --showFri 06 Jul 2007 12:27:17 AM BST -0.968931 seconds通过hwclock --show命令我们能查看机器上的硬件时间(always in local time zone), 我们能看到他和系统时间还是有⼀定的误差的, 那么我们就需要把他们同步如果我们想要把硬件时间设置成系统时间我们能运⾏以下命令代码:# hwclock --hctosys反之,我们也能把系统时间设置成硬件时间代码:# hwclock --systohc那么如果想设置硬件时间我们能开机的时候在BIOS⾥设定.也能⽤hwclock命令代码:# hwclock --set --date="mm/dd/yy hh:mm:ss"如果想要修改系统时间那么⽤date命令就最简单了代码:# date -s "dd/mm/yyyy hh:mm:ss"⽬前我们知道了怎么设置系统和硬件的时间. 但问题是如果这两个时间都不准确了怎么办?那么我们就需要在互连⽹上找到⼀个能提供我们准确时间的服务器然后通过⼀种协议来同步我们的系统时间,那么这个协议就是NTP了.注意接下去我们所要说的同步就都是指系统时间和⽹络服务器之间的同步了4. 设置NTP Server前的准备其实这个标题应该改为设置"NTP Relay Server"前的准备更加合适.因为不论我们的计算机设置多好运⾏时间久了都会产⽣误差,所以不⾜以给互连⽹上的其他服务器做NTP Server.真正能够精确地测算时间的还是原⼦钟. 但由于原⼦钟⼗分的昂贵,只有少部分组织拥有, 他们连接到计算机之后就成了⼀台真正的NTP Server.⽽我们所要做的就是连接到这些服务器上同步我们系统的时间,然后把我们⾃⼰的服务器做成NTP RelayServer再给互连⽹或是局域⽹内的⽤户提供同步服务好了,前⾯讲了⼀⼤堆理论,⽬前我们来动⼿实践⼀下吧. 架设⼀个NTP Relay Server其实⾮常简单,我们先把需要的RPM包装上代码:# rpm -ivh ntp-4.2.2p1-5.el5.rpm那么第⼀步我们就要找到在互连⽹上给我们提供同步服务的NTP Server是NTP的官⽅⽹站,在这上⾯我们能找到离我们城市最近的NTP Server. NTP建议我们为了保障时间的准确性,最少找两个个NTP Server那么⽐如在英国的话就能选择下⾯两个服务器他的⼀般格式都是第⼆步要做的就是在打开NTP服务器之前先和这些服务器做⼀个同步,使得我们机器的时间尽量接近标准时间. 这⾥我们能⽤ntpdate命令代码:# ntpdate 6 Jul 01:21:49 ntpdate[4528]: step time server 213.222.193.35 offset -38908.575181 sec# ntpdate 6 Jul 01:21:56 ntpdate[4530]: adjust time server 213.222.193.35 offset -0.000065 sec如果你的时间差的⾮常离谱的话第⼀次会看到调整的幅度⽐较⼤,所以保险起见能运⾏两次. 那么为什么在打开NTP服务之前先要⼿动运⾏同步呢?1. 因为根据NTP的设置,如果你的系统时间⽐正确时间要快的话那么NTP是不会帮你调整的,所以要么你把时间设置回去,要么先做⼀个⼿动同步2. 当你的时间设置和NTP服务器的时间相差⾮常⼤的时候,NTP会花上较长⼀段时间进⾏调整.所以⼿动同步能减少这段时间5. 设置和运⾏NTP Server⽬前我们就来创建NTP的设置⽂件了, 他就是/etc/ntp.conf. 我们只需要加⼊上⾯的NTP Server和⼀个driftfile就能了代码:# vi /etc/ntp.confserver server driftfile /var/lib/ntp/ntp.drift⾮常的简单. 接下来我们就启动NTP Server,并且设置其在开机后⾃动运⾏代码:# /etc/init.d/ntpd/start# chkconfig --level 35 ntpd on6. 查看NTP服务的运⾏状况⽬前我们已启动了NTP的服务,不过我们的系统时间到底和服务器同步了没有呢? 为此NTP提供了⼀个⾮常好的查看⼯具: ntpq (NTP query)我建议⼤家在打开NTP服务器后就能运⾏ntpq命令来监测服务器的运⾏.这⾥我们能使⽤watch命令来查看⼀段时间内服务器各项数值的变化代码:# watch ntpq -pEvery 2.0s: ntpq -p Sat Jul 7 00:41:45 2007remote refid st t when poll reach delay offset jitter============================================================================== +193.60.199.75 193.62.22.98 2 u 52 64 377 8.578 10.203 289.032*mozart.musicbox 192.5.41.41 2 u 54 64 377 19.301 -60.218 292.411⽬前我就来解释⼀下其中的含义remote: 他指的就是本地机器所连接的远程NTP服务器refid: 他指的是给远程服务器(e.g. 193.60.199.75)提供时间同步的服务器st: 远程服务器的级别. 由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端. 所以服务器从⾼到低级别能设定为1-16. 为了减缓负荷和⽹络堵塞,原则上应该避免直接连接到级别为1的服务器的.t: 这个.....我也不知道啥意思^_^when: 我个⼈把他理解为⼀个计时器⽤来告诉我们更有多久本地机器就需要和远程服务器进⾏⼀次时间同步poll: 本地机和远程服务器多少时间进⾏⼀次同步(单位为秒). 在⼀开始运⾏NTP的时候这个poll值会⽐较⼩,那样和服务器同步的频率也就增加了,能尽快调整到正确的时间范围.之后poll值会逐渐增⼤,同步的频率也就会相应减⼩reach: 这是个⼋进制值,⽤来测试能否和服务器连接.每成功连接⼀次他的值就会增加delay: 从本地机发送同步需求到服务器的round trip timeoffset: 这是个最关键的值, 他告诉了我们本地机和服务器之间的时间差别. offset越接近于0,我们就和服务器的时间越接近jitter: 这是个⽤来做统计的值. 他统计了在特定个连续的连接数⾥offset的分布情况. 简单地说这个数值的绝对值越⼩我们和服务器的时间就越精确那么⼤家细⼼的话就会发现两个问题: 第⼀我们连接的是为什么和remote server不相同? 第⼆那个最前⾯的+和*都是什么意思呢?第⼀个问题不难理解,因为NTP提供给我们的是个cluster server所以每次连接的得到的服务器都有可能是不相同.同样这也告诉我们了在指定NTP Server的时候应该使⽤hostname⽽不是IP第⼆个问题和第⼀个相关,既然有这么多的服务器就是为了在发⽣问题的时候其他的服务器还能正常地给我们提供服务.那么怎么知道这些服务器的状态呢? 这就是第⼀个记号会告诉我们的信息*他告诉我们远端的服务器已被确认为我们的主NTP Server,我们系统的时间将由这台机器所提供+他将作为辅助的NTP Server和带有*号的服务器⼀起为我们提供同步服务. 当*号服务器不可⽤时他就能接管-远程服务器被clustering algorithm认为是不合格的NTP Serverx远程服务器不可⽤了解这些之后我们就能实时监测我们系统的时间同步状况了7. NTP安全设置运⾏⼀个NTP Server不必占⽤⾮常多的系统资源,所以也不⽤专门设置独⽴的服务器,就能给许多client提供时间同步服务, 不过⼀些基本的安全设置还是⾮常有必要的那么这⾥⼀个⾮常简单的思路就是第⼀我们只允许局域⽹内⼀部分的⽤户连接到我们的服务器. 第⼆个就是这些client不能修改我们服务器上的时间在/etc/ntp.conf⽂件中我们能⽤restrict关键字来设置上⾯的需求⾸先我们对于默认的client拒绝所有的操作代码:restrict default kod nomodify notrap nopeer noquery然后允许本机地址⼀切的操作代码:restrict 127.0.0.1最后我们允许局域⽹内所有client连接到这台服务器同步时间.不过拒绝让他们修改服务器上的时间代码:restrict 192.168.1.0 mask 255.255.255.0 nomodify把这三条加⼊到/etc/ntp.conf中就完成了我们的简单设置. NTP还能⽤key来做authenticaiton,这⾥就不周详介绍了8. NTP client的设置做到这⾥我们已有了⼀台⾃⼰的RelayServer.如果我们想让局域⽹内的其他client都进⾏时间同步的话那么我们就都应该照样再搭建⼀台RelayServer,然后把所有的client都指向这两台服务器(注意不要把所有的client都指向Internet上的服务器).只要在client的ntp.conf加上这你⾃⼰的服务器就能了代码:server server 9. ⼀些补充和拾遗1. 设置⽂件中的driftfile是什么?我们每⼀个system clock的频率都有⼩⼩的误差,这个就是为什么机器运⾏⼀段时间后会不精确. NTP会⾃动来监测我们时钟的误差值并予以调整.但问题是这是个冗长的过程,所以他会把记录下来的误差先写⼊driftfile.这样即使你重新开机以后之前的计算结果也就不会丢失了2. 怎么同步硬件时钟?NTP⼀般只会同步system clock. 不过如果我们也要同步RTC的话那么只需要把下⾯的选项打开就能了代码:# vi /etc/sysconfig/ntpdSYNC_HWCLOCK=yes10. 参考资料1./cgi/man.cgi?q...conf&sektion=5不知为什么Redhat没有ntp.conf的man page.费了好⼤劲才从FreeBSD上找到了.2./~mills/ntp/html/index.html官⽅的NTP⽂件3./HOWTO/TimePrecision-HOWTO/index.htmlThe Linux Documentation Project上的NTP HOWTO4./全球NTP服务器提供站中国。
linuxNTP配置和检查服务,时间同步

linuxNTP配置和检查服务,时间同步背景:由于Hbase等应⽤服务器对集群服务器间的时间极为严格,在⽹络不好的时候会出现抖动,或集群服务器之间存在时间差,固使⽤局域⽹的授时服务器对集群或局域⽹内的Linux进⾏时间⾃动同步,解决⼀些异常问题参考⽂档:其他具体操作步骤:1、修改ntp.conf#编辑ntp配置⽂件vim /etc/ntp.conf#添加或替换以下内容driftfile /var/lib/ntp/drift#下⾯两⾏默认是拒绝所有来源的任何访问restrict default nomodify notrap nopeer noquery#开放本机的任何访问restrict 127.0.0.1restrict ::1#下⾯两⾏为配置⽂件默认开启includefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor#指定受授时服务器server iburstserver iburst2、编写DNS客户端配置⽂件vim /etc/resolv.conf#在已有的Nameserver后⾯继续增加⼀⾏nameserver 169.254.0.293、重启ntp及检查ntp#重启ntpdsystemctl restart ntpd#检查ntpq -p更多详情了解/etc/resolv.conf它是DNS客户机配置⽂件,⽤于设置DNS服务器的IP地址及DNS域名,还包含了主机的域名搜索顺序。
该⽂件是由域名解析器(resolver,⼀个根据主机名解析IP地址的库)使⽤的配置⽂件。
它的格式很简单,每⾏以⼀个关键字开头,后接⼀个或多个由空格隔开的参数。
resolv.conf的关键字主要有四个,分别是:nameserver //定义DNS服务器的IP地址domain //定义本地域名search //定义域名的搜索列表sortlist //对返回的域名进⾏排序下⾯我们给出⼀个/etc/resolv.conf的⽰例:domainsearchnameserver 202.102.192.68nameserver 202.102.192.69最主要是nameserver关键字,如果没指定nameserver就找不到DNS服务器,其它关键字是可选的。
Linux NTP时间同步设置

设置NTP Server前的准备其实这个标题应该改为设置"NTP Relay Server"前的准备更加合适.因为不论我们的计算机设置多好运行时间久了都会产生误差,所以不足以给互连网上的其他服务器做NTP Server.真正能够精确地测算时间的还是原子钟. 但由于原子钟十分的昂贵,只有少部分组织拥有, 他们连接到计算机之后就成了一台真正的NTP Server.而我们所要做的就是连接到这些服务器上同步我们系统的时间,然后把我们自己的服务器做成NTP Relay Server再给互连网或是局域网内的用户提供同步服务1.安装需要的RPM包# rpm -ivh ntp-4.2.2p1-5.el5.rpm那么第一步我们就要找到在互连网上给我们提供同步服务的NTP Server是NTP的官方网站,在这上面我们能找到离我们城市最近的NTP Server. NTP建议我们为了保障时间的准确性,最少找两个个NTP Server2. 时间同步第二步要做的就是在打开NTP服务器之前先和这些服务器做一个同步,使得我们机器的时间尽量接近标准时间. 这里我们能用ntpdate命令代码:# ntpdate 再执行一次看看结果# ntpdate 3. 设置和运行NTP CLIENTNTP的设置文件是/etc/ntp.conf. 我们只需要加入上面的NTP Server# vi /etc/ntp.confserver server server 启动NTP Server,并且设置其在开机后自动运行代码:# /etc/init.d/ntpd/start# chkconfig --level 35 ntpd on4. 查看NTP服务的运行状况# watch ntpq -pEvery 2.0s: ntpq -p Sat Jul 7 00:41:45 2007remote refid st t when poll reach delay offset jitter============================================================================== +193.60.199.75 193.62.22.98 2 u 52 64 377 8.578 10.203 289.032*mozart.musicbox 192.5.41.41 2 u 54 64 377 19.301 -60.218 292.4115. 怎么同步硬件时钟?NTP一般只会同步system clock. 不过如果我们也要同步RTC的话那么只需要把下面的选项打开就能了代码:# vi /etc/sysconfig/ntpdSYNC_HWCLOCK=yes如果我们想要把硬件时间设置成系统时间我们能运行以下命令代码:# hwclock --hctosys反之,我们也能把系统时间设置成硬件时间代码:# hwclock --systohc。
linux ntp时间同步

linux ntp时间同步一、搭建时间同步服务器1、编译安装ntp serverrpm -qa | grep ntp若没有找到,则说明没有安装ntp包,从光盘上找到ntp包,使用rpm -Uvhntp***.rpm进行安装2、修改ntp.conf配置文件vi /etc/ntp.conf①、第一种配置:允许任何IP的客户机都可以进行时间同步将“restrict default nomodifynotrapnoquery”这行修改成:restrict default nomodifynotrap配置文件示例:/etc/ntp.conf②、第二种配置:只允许192.168.211.***网段的客户机进行时间同步在restrict default nomodifynotrapnoquery(表示默认拒绝所有IP的时间同步)之后增加一行:restrict 192.168.211.0 mask 255.255.255.0 nomodifynotrap3、启动ntp服务service ntpd start开机启动服务chkconfigntpd on4、ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。
二、配置时间同步客户机手工执行ntpdate<ntp server>来同步或者利用crontab来执行crontab -e0 21 * * * ntpdate 192.168.211.22 >> /root/ntpdate.log 2>&1每天晚上9点进行同步附:当用ntpdate -d 来查询时会发现导致no server suitable for synchronization found 的错误的信息有以下2个:错误1.Server dropped: Strata too high在ntp客户端运行ntpdateserverIP,出现no server suitable for synchronization found 的错误。
linux系统时间同步方法

linux系统时间同步方法在Linux系统中,时间同步是非常重要的,因为正确的时间对于许多系统和应用程序是至关重要的。
在Linux中,有几种方法可以实现时间同步,下面我将从多个角度来介绍这些方法。
1. NTP(Network Time Protocol),NTP是一种用于同步计算机系统时钟的协议,它可以通过互联网或局域网同步系统的时间。
在Linux系统中,可以安装NTP客户端并配置为定期从NTP服务器同步时间。
常见的NTP客户端包括ntpd和chronyd。
你可以使用命令行工具如ntpd或者chronyc来配置NTP客户端并手动启动同步。
2. 使用timedatectl命令,timedatectl是一个用于配置系统时间和日期的工具,它可以用来设置时区、手动调整时间、启用或禁用网络时间同步等。
你可以使用timedatectl命令来启用NTP时间同步,例如,`sudo timedatectl set-ntp true`。
3. 使用ntpdate命令,ntpdate命令可以用来手动从NTP服务器同步时间。
你可以使用`sudo ntpdate <NTP服务器地址>`来手动同步时间。
然而,需要注意的是,ntpdate已经被弃用,推荐使用ntpd或chronyd进行时间同步。
4. 使用GUI工具,一些Linux发行版提供了图形化的工具来配置时间和日期,例如Ubuntu上的“时间和日期”设置。
通过这些图形化工具,你可以方便地配置时区、启用NTP时间同步等。
总的来说,Linux系统时间同步的方法有很多种,你可以选择适合你的需求和习惯的方法来进行时间同步。
无论使用哪种方法,都要确保系统的时间是准确的,以避免对系统和应用程序造成不必要的问题。
Linux同步网络时间的方法

Linux自带了ntp服务 -- /etc/init.d/ntpd,没有可以yum install ntp可以选择2种方法同步时间一下操作使用root用户进行:①安装ntp后不运行ntpd服务,通过命令 ntpdate 来实现时间同步具体操作为:为网络时间服务器通过命令 ntpdate 可以使服务器的时间与这台服务器的时间同步输入命令后如果提示成功则可以把命令添加到定时任务中如:执行命令:crontab -e然后加入*/30 * * * * /usr/sbin/ntpdate 表示每30分钟同步一次时间。
该种方法需要服务器能连接网络测试时间是否同步的方法:先修改时间例如:date -s 12:30:00然后手动执行命令,或把同步时间的脚步设置为1分钟执行一次及*/1,然后使用命令 date 查看时间是否有变化。
②如果多台服务器需要同步成一致时间或自己创建一台时间服务器,使其他服务器与改服务器进行时间同步设时间服务器的IP为192.168.1.1 ;客户端服务器IP为192.168.20.50 ;需要使客户端服务器自动通过时间服务器的时间,时间服务器自动与网络时间服务器同步时间。
首先设置时间服务器安装完ntp后修改/etc/ntp.confvi /etc/ntp.conf注释掉原来的restrict default ignore这一行,这一行本身是不响应任何的ntp更新请求,其实也就是禁用了本机的ntp server的功能,所以需要注释掉。
加入:restrict 192.168.0.0 mask 255.255.0.0 ##表示192.168.0.0~192.168.254.254段的IP都可以连接该服务器进行同步时间如果需要时间服务器与网络时间服务器进行时间同步需加入以下设置:restrict 202.118.1.81 mask 255.255.255.255 nomodify notrap noquery ##可能不需要条server 202.118.1.81#### 202.118.1.81 为时间服务器IP也可以添加server xxx.xxx.xxx.xxx,让他和其他的time server 时间同步。
Linux下ntpdate时间同步

Linux下ntpdate时间同步Ntp服务器配置时间同步方法同步命令 # ntpdate ntp服务器域名或IP例:# ntpdate 192.168.1.10自动运行同步时间脚本设定# crontab –e添加脚本例子如下:*/20 * * * * /usr/sbin/ntpdate 192.168.1.10 ;/sbin/hwclock -w > /dev/null #2>&1 //每20分钟执行一次30 5 * * * /usr/sbin/ntpdate 192.168.1.10 ;/sbin/hwclock -w > /dev/null #2>&1 //每天早晨5点半执行※前面五个*号代表五个数字,数字的取值范围和含义如下:分钟(0-59)小時(0-23)日期(1-31)月份(1-12)星期(0-6)//0代表星期天设定完毕后,可使用# crontab –l 查看上面的设定。
同步互联网上的时间服务器ntpdate ntpdate Linux系统时间日期手动修改查看当前时间 # date修改时间命令 # date –s 12:12:00修改日期命令 # date –s 01/12/2008Linux系统时区修改查看当前时区 # vi /etc/sysconfig/clock修改时区命令# tzselect 或# timeconfig如果知道时区名称也可以直接使用命令如:# TZ='Asia/Shanghai'; export TZ //改为+8中国上海时区或使用新的时区文件覆盖系统默认时区例# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime //亚洲上海时区替换系统时区同步BIOS时钟,强制将系统时间写入CMOS,使之永久生效,避免系统重启后恢复成原时间。
# clock -w查看BIOS时间命令:# hwclock -rcentos7系统修改时区ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime。
NTP服务器建立以及时间同步配置

Linux下的ntp软件不但能自动与互联网上的时钟保持同步,同时本身已经是一台SNTP服务器了,可以供局域网内的电脑校对时间。
默认情况下生产安装系统时是已经安装NTP服务,可以使用一下命令查看是否已经安装NTP服务:
# rpm –qa | grep ntp
ntp-4.2.2p1-9.el5
chkfontpath-1.10.1-1.1
上面表示已经安装了ntp服务
【设置NTP服务】
配置文件在/etc/ntp.conf
对该文件内容的修改如下:
把restrict default kod nomodify notrap nopeer noquery注释掉。
添加允许的访问的ntp client,添加如下内容:
restrict 192.168.1.0 mask 255.255.255.0 nomodify //允许一个网段访问 restrict 192.168.1.100 //允许某一个主机访问 chkconfig –level on ntpd 35 开机自动启动
【设置NTP Client】
在NTP Client端只需要安装ntp服务就可以,不过不要启动该服务。
使用ntpdate [ntp server 地址] 命令就可以
把该命令写入crontab计划任务中,让ntp client定时和server端校时就可以。
05 1 * * * ntpdate 12.56.0.31
编码器修改方法:
echo "timeserver 192.168.11.9">/proc/nvram/boot
echo "saveall">/proc/nvram/boot
reboot。
OracleLinux NTP时间服务器配置同步方案

OracleLinux NTP时间服务器配置同步方案目标环境,Oracle linux6,作为内网的NTP时间服务器,局域网内的其他机器与这台服务做时间同步。
2、安装配置Oracle linux6系统已经自带了NTPD服务,一般默认是安装了的,如果没有安装,先检查下,然后配置好yum仓库,yum方式安装下就OK,具体如下:# rpm -q ntpntp-4.2.4p8-2.el6.x86_64 // 这表示已安装了,如果没有安装,这是空白。
如果没有安装,我们按照下# yum install ntp......按上面的安装方式在内网每台服务器上都安装好NTP软件包。
完成后,都需要配置NTP服务为自启动# chkconfig ntpd on# chkconfig --list ntpdntpd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭在配置前,先使用ntpdate手动同步下时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步。
# ntpdate -u 202.112.10.3622 Dec 16:52:38 ntpdate[6400]: adjust time server 202.112.10.36 offset 0.012135 sec配置内网NTP-Server下面主要是配置内网的NPTD服务器, NTPD服务配置核心就在/etc/ntp.conf文件,配置好了就OK。
先上配置文件再说,红色部分是修改部分,注意红色修改部分。
# 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 127.0.0.1restrict -6 ::1# Hosts on local network are less restricted.# 允许内网其他机器同步时间restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the project.# Please consider joining the pool (/join.html). # 中国这边最活跃的时间服务器: /zone/cn server 210.72.145.44 perfer # 中国国家受时中心server 202.112.10.36 # server 59.124.196.83 # #broadcast 192.168.1.255 autokey # broadcast server#broadcastclient # broadcast client#broadcast 224.0.1.1 autokey # multicast server#multicastclient 224.0.1.1 # multicast client#manycastserver 239.255.254.254 # manycast server#manycastclient 239.255.254.254 autokey # manycast client# allow update time by the upper server# 允许上层时间服务器主动修改本机时间restrict 210.72.145.44 nomodify notrap noqueryrestrict 202.112.10.36 nomodify notrap noqueryrestrict 59.124.196.83 nomodify notrap noquery# Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available.# 外部时间服务器不可用时,以本地时间作为时间服务server 127.127.1.0 # local clockfudge 127.127.1.0 stratum 10# Enable public key cryptography.#cryptoincludefile /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 42# 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配置文件修改完成,保存退出。
Linux配置NTP时间同步

Linux配置NTP时间同步Linux配置NTP时间同步⼀、ntp和ntpdate区别两个服务都是centos⾃带的(centos7中不⾃带ntp)ntp守护进程为ntpd,配置⽂件是/etc/ntp.confntpdate⽤于客户端的时间矫正,⾮NTP服务器可以不启动NTP。
⼆、搭建NTP(network time protocol ⽹络时间协议)⽤于同步计算机和⽹络设备的内部的时间⼀种协议NTP Server服务器IP:192.168.1.111NTP Client客户端IP:192.168.1.1122.1、搭建NTP服务器yum install -y ntp2.1.1、修改配置⽂件[root@master ~]# vim /etc/ntp.conf把配置⽂件下⾯四⾏注释掉:server iburstserver iburstserver iburstserver iburst然后在下⾯添加这⼏⾏:server iburstserver iburstserver iburstserver iburst2.2.2、启动ntp服务,并开机⾃启动启动ntp服务,并开机⾃启动[root@master ~]# systemctl start ntpd[root@master ~]# systemctl enable ntpd2.2.3、查询ntp是否同步【命令】ntpq -premote:本机和上层ntp的ip或主机名,“+”表⽰优先,“*”表⽰次优先refid:参考上⼀层ntp主机地址st:stratum阶层when:多少秒前曾经同步过时间poll:下次更新在多少秒后reach:已经向上层ntp服务器要求更新的次数delay:⽹络延迟offset:时间补偿jitter:系统时间与bios时间差[root@master ~]# dateTue Nov 17 21:24:24 CST 2020[root@master ~]# ntpq -premote refid st t when poll reach delay offset jitter============================================================================== time.cloudflare .STEP. 16 u - 64 0 0.000 0.000 0.000ntp7.flashdance .STEP. 16 u - 64 0 0.000 0.000 0.000202.118.1.130 .STEP. 16 u - 64 0 0.000 0.000 0.000*ntp5.flashdance 194.58.202.20 2 u 11 64 1 372.035 -17.860 28.092[root@master ~]# ntpstatsynchronised to NTP server (193.182.111.14) at stratum 3time correct to within 244 mspolling server every 64 s[root@master ~]# timedatectlLocal time: Tue 2020-11-17 22:37:02 CSTUniversal time: Tue 2020-11-17 14:37:02 UTCRTC time: Tue 2020-11-17 14:37:03Time zone: Asia/Shanghai (CST, +0800)NTP enabled: yesNTP synchronized: yesRTC in local TZ: noDST active: n/a[root@master ~]# ntpdate -u 193.182.111.1417 Nov 22:38:10 ntpdate[7787]: adjust time server 193.182.111.14 offset 0.039557 sec2.3、NTP客户端配置yum install -y ntp2.3.1、修改配置⽂件[root@slave1 ~]# vim /etc/ntp.conf#配置允许NTP Server时间服务器主动修改本机的时间restrict 192.168.1.111 nomodify notrap noquery#配置时间服务器为本地搭建的NTP Server服务器server 192.168.1.111 iburst#配置允许上游时间服务器主动修改本机的时间restrict 192.168.1.111 nomodify notrap noquery#注释掉其他时间服务器#server iburst#server iburst#server iburst#server iburst2.3.2、启动ntp服务,并开机⾃启动启动ntp服务,并开机⾃启动systemctl start ntpdsystemctl enable ntpd2.3.3、查看同步的主服务器,显⽰如下表⽰成功# 启动后查看[root@slave1 ~]# ntpq -pnremote refid st t when poll reach delay offset jitter============================================================================== 192.168.1.111 202.12.97.45 2 u 20 64 0 0.000 0.000 0.000。
linux系统之时间同步方法

linux系统之时间同步方法Linux系统中的时间同步是确保系统时间准确性的重要任务之一。
在计算机系统中,时间的准确性对于许多应用程序和系统操作都至关重要。
本文将介绍Linux系统中的时间同步方法,包括使用NTP(Network Time Protocol)和使用Chrony两种常用的时间同步方法。
一、使用NTP进行时间同步NTP是一种用于同步计算机系统时间的协议。
在Linux系统中,可以通过安装和配置NTP服务器来进行时间同步。
下面是使用NTP 进行时间同步的步骤:1. 安装NTP软件包在Linux系统中,可以使用包管理器来安装NTP软件包。
例如,在Ubuntu系统中,可以使用以下命令安装NTP软件包:```sudo apt-get install ntp```2. 配置NTP服务器在安装完成NTP软件包后,需要对NTP服务器进行配置。
NTP服务器的配置文件通常位于`/etc/ntp.conf`。
可以使用文本编辑器打开该文件,并根据需要进行配置。
配置文件中包含了NTP服务器的各种参数和选项,可以根据实际需求进行调整。
3. 启动NTP服务配置完成后,可以启动NTP服务。
在大多数Linux系统中,可以使用以下命令启动NTP服务:```sudo systemctl start ntp```还可以使用以下命令来设置NTP服务在系统启动时自动启动:```sudo systemctl enable ntp```4. 同步时间NTP服务器启动后,系统会自动与NTP服务器进行时间同步。
可以使用以下命令手动进行时间同步:```sudo ntpdate server```其中,`server`是NTP服务器的地址,可以根据实际情况进行替换。
二、使用Chrony进行时间同步Chrony是另一种常用的时间同步工具,与NTP类似,都是基于网络时间协议。
下面是使用Chrony进行时间同步的步骤:1. 安装Chrony软件包在Linux系统中,可以使用包管理器来安装Chrony软件包。
Linux时间同步,ntpd,ntpdate-简单设置

linux时间同步,ntpd、ntpdate在Windwos中,系统时间的设置很简单,界面操作,通俗易懂。
而且设置后,重启,关机都没关系。
系统时间会自动保存在Bios的时钟里面,启动计算机的时候,系统会自动在Bios里面取硬件时间,以保证时间的不间断。
但在Linux下,默认情况下,系统时间和硬件时间,并不会自动同步。
在Linux运行过程中,系统时间和硬件时间以异步的方式运行,互不干扰。
硬件时间的运行,是靠Bios电池来维持,而系统时间,是用CPU tick来维持的。
在系统开机的时候,会自动从Bios中取得硬件时间,设置为系统时间。
一.Linux系统时间的设置在Linux中设置系统时间,可以用date命令://查看时间[root@localhost ~]# date2008年12月12日星期五14:44:12 CST//修改时间[root@localhost ~]# date --set "1/1/09 00:01" <== (月/日/年时:分:秒)2009年01月01日星期四00:01:00 CST//date 有几种时间格式可接受,这样也可以设置时间:[root@localhost ~]# date 012501012009.30 <== 月日时分年.秒2009年01月25日星期日01:01:30 CST二.Linux硬件时间的设置硬件时间的设置,可以用hwclock或者clock命令。
其中,clock和hwclock用法相近,只用一个就行,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件体系。
//查看硬件时间可以是用hwclock ,hwclock --show 或者hwclock -r[root@localhost ~]# hwclock --show2008年12月12日星期五06时52分07秒-0.376932 seconds//设置硬件时间[root@localhost ~]# hwclock --set --date="1/25/09 00:00" <== 月/日/年时:分:秒[root@localhost ~]# hwclock2009年01月25日星期日00时00分06秒-0.870868 seconds三.系统时间和硬件时间的同步同步系统时间和硬件时间,可以使用hwclock命令。
linux系统NTP时间同步

在主节点上做如下操作:
1.安装时间服务器ntp
yum install ntp
2.vim /etc/ntp.conf
3 开启
sevrice ntpd start
4 检查状态
Ntpstat
5 查看同步的服务器ip
ntpq -pn
成功后,在其他节点上分别做如下操作:
scp /etc/ntp.conf 192.168.1.167(ip):/etc/
至此ntp时间同步完成
remote:即NTP主机的IP或主机名称。
注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。
refid:参考的上一层NTP主机的地址
st:即stratum阶层
when:几秒前曾做过时间同步更新的操作
poll:下次更新在几秒之后
reach:已经向上层NTP服务器要求更新的次数
delay:网络传输过程钟延迟的时间
offset:时间补偿的结果
jitter:Linux系统时间与BIOS硬件时间的差异时间。
Linux时区设置及NTP时间同步

Linux时区设置及NTP时间同步一、背景机器装的是busybox,使用的是最小集合的linux。
硬件时钟是本地时间,而内核时钟是UTC时间,没有设置时区,也没有任何时区设置的选项。
二、需求这台机器需要定时进行NTP时间同步。
同步之后显示给用户的是本地时间。
三、过程1.时区的支持(1)hwclock为了查看硬件时钟是否为本地时间,运行命令hwclock –r。
结果系统提示:“Could not open RTC: No such file or directory”,即找不到RTC文件。
(2)/dev/rtc由于内核在编译过程中没有提供RTC支持,需要重新编译内核(或为内核增加一个module)。
方法为,在make menuconfig阶段,选中“Character device”的“Enhanced Real Time Clock Support”一项的支持。
为内核增加了该模块后,目录/proc/drive/下已出现了rtc文件,cat也能查看到正常的内容。
但/dev/目录下仍没有rtc文件。
于是通过mknod命令在/dev目录下增加rtc文件。
通过man rtc 可以得知,RTC为只读字符设备,主10,从135。
因此命令为“mknod /dev/rtc c 10 135”。
命令执行完毕后,/dev下成功生成了rtc文件。
运行hwclock –r,能够看到硬件时间为本地时间。
通过date命令查看系统时间,却为UTC时间。
这说明系统没有进行本地时间的设置。
(3)/etc/localtimeLinux的系统时区是通过符号连接/etc/localtime来得到的。
可以通过tzset命令来设置时区。
如果没有该命令,可以通过命令“ln –s /etc/localtime /usr/share/zoneinfo/Asia/Shanghai”来将时区设置为亚洲的上海。
由于最初构建系统的时候没有包含zoneinfo信息,因此/usr/share目录下不存在zoneinfo目录及其文件。
LinuxNTP服务器搭建部署与NTP时间同步配置

LinuxNTP服务器搭建部署与NTP时间同步配置Linux系统时区设置timedatectl set-timezone Asia/Shanghai (这⾥是设置亚洲上海上海)Linux NTP服务器部署安装及配置⼀、linux NTP服务器部署安装1、验证服务器端NTP服务是否已安装[root@vm ~]# rpm -qa ntp*ntpdate-4.2.6p5-12.el6.centos.2.x86_64ntp-4.2.6p5-12.el6.centos.2.x86_642、若系统为安装ntp服务,可通过rpm或yum进⾏安装[root@vm ~]# yum install ntp -y[root@vm ~]# rpm -ql ntp/etc/ntp.conf # ntp服务器的主配置⽂件/etc/rc.d/init.d/ntpd # 开机启动ntpd脚本⽂件3、国内稳定NTP时间同步服务器域名4、使⽤ntpdate同步时间服务器[root@vm ~]# ntpdate 17 Oct 10:05:27 ntpdate[26878]: step time server 120.25.115.19 offset 4.115593 sec⼆、linux NTP服务配置1、NTP服务 ntp.conf 参数详解默认ntp.conf内容如下[root@vm ~]# vi /etc/ntp.conf#系统时间与BIOS事件的偏差记录driftfile /var/lib/ntp/driftrestrict default kod nomodify notrap nopeer noquery # 拒绝所有IPv4的client连接此NTP服务器restrict -6 default kod nomodify notrap nopeer noquery # 拒绝所有IPv6的client连接此NTP服务器restrict 127.0.0.1 # 放⾏本机localhost对NTP服务的访问restrict -6 ::1# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # 放⾏192.168.1.0⽹段主机与NTP服务器进⾏时间同步# Use public servers from the project.# Please consider joining the pool (/join.html).server iburst # 代表的同步时间服务器server iburstserver iburstserver iburst#broadcast 192.168.1.255 autokey # broadcast server#broadcastclient # broadcast client#broadcast 224.0.1.1 autokey # multicast server#multicastclient 224.0.1.1 # multicast client#manycastserver 239.255.254.254 # manycast server#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography.keys /etc/ntp/keys----各项参数详解利⽤restrict 来管理权限控制Restrict [IP] mask [netmask_IP] [parameter]Parameter 的ignore :拒绝所有类型的NTP联机。
NTP(时间同步服务器)配置

NTP(时间同步服务器)配置NTP(网络时间协议)是一种用于网络中计算机时间同步的协议。
它通过一组服务器,称为时间同步服务器,将准确的时间信息传递给其他计算机,以确保整个网络中的时间一致性。
配置NTP服务器是很重要的,本文将介绍如何进行NTP服务器的配置。
首先,安装并配置NTP服务器软件。
在大多数Linux发行版中,可以使用以下命令来安装NTP服务器软件:```sudo apt-get install ntp```1.配置服务器的参考时间源。
NTP服务器需要一个可靠的时间源来同步时间。
可以从多个公共NTP服务器选择一个参考时间源。
可以在配置文件中添加以下行来指定参考时间源:``````2.配置其他NTP服务器。
可以选择指定其他NTP服务器作为备用时间源。
这些服务器将在参考时间源不可用时使用。
可以添加以下行来指定其他NTP服务器:``````3. 配置允许访问NTP服务器的客户端。
可以通过使用`restrict`命令来限制可以访问NTP服务器的客户端。
可以添加以下行来指定允许访问的客户端:```restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap```其中,`192.168.0.0`应替换为允许访问的客户端的IP地址范围。
4.配置NTP服务器的日志记录。
可以通过添加以下行来配置NTP服务器的日志记录:```logfile /var/log/ntp.log```这将指定日志文件的路径和文件名。
5.配置时间同步频率。
可以通过添加以下行来配置时间同步的频率:```minpoll 4maxpoll 6```其中,`minpoll`表示最小的间隔时间单位,`maxpoll`表示最大的间隔时间单位。
较小的值表示更频繁的时间同步。
6.配置NTP服务器的启动选项。
可以通过添加以下行来配置NTP服务器的启动选项:```#启用NTP服务器server 127.127.1.0fudge 127.127.1.0 stratum 10```这将启用本地计算机作为NTP服务器以提供时间同步服务。
linux下ntp时间服务器的搭建与配置

Network Time Protocol(NTP,网络时间协议)用于同步它所有客户端时钟的服务.NTP服务器将本地系统的时钟与一个公共的NTP服务器同步然后作为时间主机提供服务,使本地网络的所有客户端能同步时钟。
同步时钟最大的好处就是统一企业内部各个系统的时间标准,如果网络中使用NTP对系统时间进行集中管理.在同步了时钟的网络中,集中式的性能监控、服务监控系统能实时的反应系统信息,系统管理员可以快速的检测和解决系统错误。
1.服务端的配置:第一步,安装NTP服务:1)rpm -ivh ntp-4。
2。
6p5—28.0.1.el7。
x86_642)yum install -y ntp ntpdate注:第一条命令安装ntp服务器软件,第二条命令安装ntp客户端软件(可以不安装)安装ntp服务器软件过程中可能会出现以上错误,请按照提示安装相应依赖包。
第二步,配置NTP服务:编辑配置文件/etc/ntp.conf ,配置之前记得先备份文件。
restrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0。
1restrict -6 ::1restrict 192.168。
100.0 mask 255。
255。
255。
0 nomodify notrap##按需修改server time1.aliyun。
comserver server time3。
aliyun。
comserver time4.aliyun。
comserver time5.aliyun。
comserver time6。
server server .pool。
ntp。
org preferlogfile /var/log/ntp.log第三步,启动NTP服务:/etc/init。
详解linuxntp服务器时间同步设置

详解linuxntp服务器时间同步设置linux ntp服务器时间同步设置时间同步这个需求在很多地⽅都有。
⽐如安装cm和cdh的话,需要ntp时间同步,否则会出现红⾊警告这⾥主要是设置⼀台服务器作为主服务器,让其他机器同步这台机器的时间,⽽且是配置的本地时间,没有同步internet时间,因为很多时候服务器不能联⽹⾸先我们这⾥设置2台机器,主机器为192.168.5.102,另外⼀台为192.168.5.103⾸先设置主机器编辑/etc/ntp.conf⽂件在⾥⾯加上restrict 127.0.0.1 # 开启内部递归⽹络接⼝ lorestrict 192.168.5.0 mask 255.255.255.0 nomodify #在内部⼦⽹⾥⾯的客户端可以进⾏⽹络校时,但不能修改NTP服务器的时间参数由于配置的是本地时间,所以还需要配置⼀个使⽤系统时钟作为时间源的NTP服务器,需要在/etc/ntp.conf⽂件中添加如下的记录:server 127.127.1.0fudge 127.127.1.0 stratun 10在以上的记录中:指定的IP地址是⼀个“伪”IP地址,确定本地系统为时间源。
指定的IP地址127.127.1.1告诉NTP使⽤内部时钟作为时间源。
"fudge"定义了这个时钟的级别,如果没有这个记录,节点就是⼀级服务器。
将级别重新定义为10是个好的办法,这样客户端在查询这个服务器的时候就会知道这个服务器不是⼀个可靠的时间源这种时间同步的⽅式只应该在本地的⽹络不能使⽤外部的时间源的时候使⽤然后启动NTP服务service ntpd start设置开机⾃启动chkconfig ntpd on然后配置客户端,在192.168.5.103这台主机上⾯,编辑/etc/crontab这个⽂件,⽤于设置此节点每分钟要像主服务器同步时间设置如下:* * * * * root /usr/sbin/ntpdate 192.168.5.102;/sbin/hwclock -w以上就是关于linux ntp服务器时间同步设置的讲解,感谢阅读,希望能帮助到⼤家,谢谢⼤家对本站的⽀持!。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
OracleLinux NTP时间服务器配置同步方案目标环境,Oracle linux6,作为内网的NTP时间服务器,局域网内的其他机器与这台服务做时间同步。
2、安装配置
Oracle linux6系统已经自带了NTPD服务,一般默认是安装了的,如果没有安装,先检查下,然后配置好yum仓库,yum方式安装下就OK,具体如下:
# rpm -q ntp
ntp-4.2.4p8-2.el6.x86_64 // 这表示已安装了,如果没有安装,这是空白。
如果没有安装,我们按照下
# yum install ntp
......
按上面的安装方式在内网每台服务器上都安装好NTP软件包。
完成后,都需要配置NTP服务为自启动
# chkconfig ntpd on
# chkconfig --list ntpd
ntpd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
在配置前,先使用ntpdate手动同步下时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步。
# ntpdate -u 202.112.10.36
22 Dec 16:52:38 ntpdate[6400]: adjust time server 202.112.10.36 offset 0.012135 sec
配置内网NTP-Server
下面主要是配置内网的NPTD服务器, NTPD服务配置核心就在/etc/ntp.conf文件,配置好了就OK。
先上配置文件再说,红色部分是修改部分,注意红色修改部分。
# 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 noquery
restrict -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 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
# 允许内网其他机器同步时间
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the project.
# Please consider joining the pool (/join.html). # 中国这边最活跃的时间服务器: /zone/cn server 210.72.145.44 perfer # 中国国家受时中心
server 202.112.10.36 #
server 59.124.196.83 #
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# allow update time by the upper server
# 允许上层时间服务器主动修改本机时间
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery
# Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available.
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
# 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 42
# 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
配置文件修改完成,保存退出。
关闭防火墙,
Iptables –I INPUT –p udp –dport -123 –j ACCEPT
启动服务。
# service ntpd start
# service ntpd stop
# service ntpd restart
......
启动后,一般需要5-10分钟左右的时候才能与外部时间服务器开始同步时间。
可以通过命令查询NTPD服务情况。
ntpq -p 查看网络中的NTP服务器,同时显示客户端和每个服务器的关系
# ntpq -p
# ntpq -p
remote refid st t when poll reach delay offset jitter
=================================================================== ===========
*202.112.10.36 202.112.10.60 2 u 277 128 314 201.553 9.193 17.068
+59.124.196.83 129.6.15.28 2 u 88 128 377 71.153 -25.111 14.004
LOCAL(0) .LOCL. 10 l 15 64 377 0.000 0.000 0.000
ntpstat 命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。
所以,服务器启动后需要稍等下。
刚启动的时候,一般是:
# ntpstat
unsynchronised
time server re-starting
polling server every 64 s
连接并同步后:
synchronised to NTP server (202.112.10.36) at stratum 3
time correct to within 275 ms
polling server every 256 s
OK,内网的NTPD服务已经配置完成,如果所有正常后,开始配置内网的其他设备与这台服务器作为时间同步服务。