需要注意的几点:
1.自己配置的NTP是需要设置上层服务器来进行时间同步的,172.25.23.250主机通过另一块网卡可以上网,使用的上层主机是cn.ntp.org.cn ;
2.NTP服务器和上层NTP服务的时间不能够相差太多;
3.对于防火墙的设置,一定需要允许123/UDP端口;
4.防火墙还需要放行时间同步请求的网段;
首先安装ntp服务的软件包,这里使用Yum配置安装
1.[root@my Desktop]# yum install ntp -y
2.[root@my Desktop]# rpm -q ntp
3.ntp-4.2.6p5-22.el7.x86_64
然后根据上面的提示修改配置文件/etc/ntp.conf
NTP全称是Network Time Protocol,也就是互联网时间协议,说到时间,就谈谈时间的一些概念吧;
时区
按照常识来说,一天被划分24小时,近似球体的地球是360度,所以使用经纬度为坐标,将全球划分为24个时区,每个时区是15度;
东八区
格林尼治时间为世界标准时间,又因为,东半球(格林尼治以东)的时间比较早,中国的经度在120E,是位于第八个时区,这里的中国表示北京或者上海,因为横跨的时区不止一个;
UTC
Coordinated Universal Time表示协调通用时间,根据原子振荡周期所计算的物理时钟,这种计算方式对于时间的计算误差时很小的;
GMT
Greenwich Mean Time表示的是格林尼治时间,是根据地球的自转周期计算的标准时间,由于各种不稳定因素的影响,计时不是很理想;
软件时钟
表示的是LInux[这里指提Linux]操作系统从1970/01/01开始计算的秒数;
硬件时钟
主机硬件上面的时钟,主要是BIOS内部时间的记录了;
时间校对的几个步骤
1.server端启动daemon;
2.Client向server发送校对时间的报文;
3.NTP server返回当前的标准时间给Client;
4.Client根据返回的时间校对自己当前的系统时间;
关于NTP服务相关的配置文件
/etc/ntp.conf
//表示NTP服务的主要配置文件,也是为一个的配置文件
/usr/share/zoneinfo/
//表示对应的各个时区的文件
/etc/sysconfig/clock
//表示用于设置时钟和是否使用UTC的配置文件
/etc/localtime
//用于复制/usr/share/zoneinfo/里面对应的,/etc/sysconfig/clock里面设定的时区文件,作为当前系统使用的本地时间配置文件;
关于时间的几个命令
/bin/date
//Linux软件时钟的修改和查看
/sbin/hwclock
//用于硬件时钟的修改和显示,如果修改了软件时钟需要使用这个方式同步到硬件时钟上面;
/usr/sbin/ntpd
//NTP服务的主要程序,配置文件为/etc/ntp.conf
/usr/sbin/ntpdate
//用于实现Client时间的校正
关于/etc/ntp.conf配置文件
利用restrict来实现权限控制
restrict [IP] [mask] [netmask_IP] [patameter]
patameter支持的参数:
igonre:拒绝所有类型的`NTP`连接
nomodify:Client不能够使用命令ntpc以及ntpdq来修改修改服务器的时间参数,但是可以进行网络校时;
noquery:表示不提供NTP网络校时;
notrap:表示不提供远程事件登陆的功能;
notrust:表示不接受没有认证的Clent;
如果没有任何参数,表示不接受任何的限制;
server [IP or hostname] [prefer]
用于设置上层提供NTP服务的服务器;
prefer:表示优先使用
driftfile [可以被ntpd写入的进程或者文件]
NTP Server计算时间是通过本机的时钟振荡来记录的,这个时间和上层Time Server的时钟振荡频率不一定是一致的,需要将这个振荡差异记录下
NTP服务的规划
rhel7.2作为提供时间同步服务的主机172.25.23.250
rhel6.5作为某个集群中的节点,进行时间同步,这里选择server21.com
需要注意的几点:
需要注意的几点:
1.自己配置的NTP是需要设置上层服务器来进行时间同步的,172.25.23.250主机通过另一块网卡可以上网,使用的上层主机是cn.ntp.org.cn ;
2.NTP服务器和上层NTP服务的时间不能够相差太多;
3.对于防火墙的设置,一定需要允许123/UDP端口;
4.防火墙还需要放行时间同步请求的网段;
首先安装ntp服务的软件包,这里使用Yum配置安装
[root@my Desktop]# yum install ntp -y
[root@my Desktop]# rpm -q ntp
ntp-4.2.6p5-22.el7.x86_64
然后根据上面的提示修改配置文件/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 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 ::1
restrict cn.ntp.org.cn
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 172.25.23.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#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 iburst
#
server cn.ntp.org.cn prefer
#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.
#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
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor
然后启动或者重新启动服务
[root@my Desktop]# !systemc
systemctl start ntpd
确保端口已经启动
使用命令ntpstat
查看NTP
服务器的状态
[root@my Desktop]# ntpstat
synchronised to NTP server (202.108.6.95) at stratum 3
time correct to within 106 ms
polling server every 64 s
或者使用ntpq -p
来查看NTP
服务器时间同步的过程
[root@my Desktop]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*xk-6-95-a8.bta. 10.69.2.34 2 u 35 64 377 28.381 -30.163 17.439
解释上述几个子段的作用
remote
:表示NTP主机的IP或者是主机名,最左边的
*
:表示目前正在作用当中的上层NTP服务器;
+
:表示已经连接成功,并且可以作为下一个提供时间更新的候选者;
refid
:表示参考的上一层NTP主机的地址;
st
:表示的含义是startnum,一般范围是从0–>15;
when
:表示几秒前做过时间同步化更新操作;
poll
:表示下一次更新在几秒钟之后;
reach
:表示已经向上一层服务器要求更新的次数;
delay
: 表示数据在传输过程中延迟的时间;
offset
:表示时间补偿的结果;
jitter
:Linux系统时间和BIOS硬件时间的差异;
Client
仅仅需要使用简单的命令就可以完成时间和NTP的同步操作
[root@server20 ~]# ntpdate 172.25.23.250
10 Mar 15:49:08 ntpdate[13911]: adjust time server 172.25.23.250 offset -0.049370 sec
补充关于date
命令的使用
[root@server21 ~]# date MMDDHHMMYYYY
MM:表示月
DD:表示天
HH:表示小时
MM:表示分钟
YYYY:表示年
上面这个命令主要用来查看(不使用任何选项)和修改时间;
hwclock
关于硬件时间
-r :表示用于读取硬件时间
-w:表示将软件时间写入为硬件时间