一、时间
概念:Linux时间有两个
系统时间:也叫软件时间(sys), 1970年1月1日到当前时间的秒数
BOIS时间:也叫硬件时间(hc)
显示时间:
date; -------》(软件时间)
hwclock -r --------》(硬件时间)
设置时间:
没有网络的情况下可以用这个
- date -s 20121019
- date -s 23:40:00
有网络的情况下使用:
- ntpdate time.windows.com && hwclock -w
连网更新时间,如果成功,将系统时间,写入BOIS
hwclock -w 或 hwclock --systohc
时间服务器的应用场景通常不是很复杂,一般都为局域网内部做同步时间使用,安装起来也比较简便。
1
|
# yum install -y ntpd #其他的安装方式就不列出了,基于RPM包的方式就可以满足使用需要了。
|
1
2
|
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
|
1
2
3
4
|
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
|
1
|
server 172.16.103.100
|
1
2
|
# crontab -e
*
/5
* * * *
/usr/sbin/ntpdate
172.16.103.100 &>
/dev/null
#每隔5分钟同步自动同步时间。
|
1
2
|
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
|
1
2
|
restrict default nomodify
#允许任意客户端主机来同步时间,但不允许修改服务器端参数
restrict 172.16.0.0 mask 255.255.0.0 nomodify
#仅允许172.16网段的主机来同步时间,但不允许修改服务器端的参数。
|
1
2
3
4
|
restrict 210.72.145.44
#授权国家授时中心服务器访问本地NTP
restrict 133.100.11.8
#授权133.100.11.8访问本地NTP
server 210.72.145.44 prefer
#指定上级更新时间服务器,优先使用这个地址
server 133.100.11.8
server
127.127
.
1.0
fudge 127.127 . 1.0 stratum 8 |
1
|
no server suitable
for
synchronization found
|
1
2
3
4
5
6
7
|
ignore:关闭所有NTP服务
nomodify :表示客户端不能更改NTP服务器的时间参数,但可以通过NTP服务器进行时间校对
noquery: 不提供NTP服务
notrap:不提供
trap
远程事件登录的功能
notrust: 聚聚没有通过认证的客户端
kod:kod技术可以组织“Kiss of Death”包(一种DOS攻击)对服务器的破坏,使用此参数将开启该功能
nopeer:不与其他同一层的NTP服务器进行时间同步
|
1
2
3
4
5
6
|
[root@server ~]
# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
dns.sjtu.edu.cn .STEP. 16 u - 1024 0 0.000 0.000 0.000
+news.neu.edu.cn 236.43.203.76 2 u 136 256 353 93.562 -4.175 11.871
*dns1.synet.edu. 223.255.185.2 2 u 162 256 377 92.719 -2.292 1.655
|
1
2
3
4
5
6
7
|
remote: 本地主机所连接的上层NTP服务器
st:NTP服务器优先级
when:上次与NTP服务器同步的时间(单位:s)
poll:下次与NTP服务器同步的时间(单位:s)
delay:从本地发出时间同步命令给远程时间服务器开始,到整个时间同步完成所需时间(单位:10^-6s)
offset:本地主机与时间服务器的时间差(同步后将自动纠正)
jitter:一个offset的分布统计值,该值越小,表示时间越精确
|