Chinaunix首页 | 论坛 | 博客
  • 博客访问: 424364
  • 博文数量: 121
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 540
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-16 16:28
文章分类

全部博文(121)

文章存档

2021年(3)

2018年(1)

2017年(5)

2016年(9)

2015年(23)

2014年(80)

我的朋友

分类: LINUX

2014-02-11 16:41:47

1.软件的安装:

 可以直接输入yum install -y ntp ntpdate命令进行安装。如果无法联网则利用的rpm包,把含有ntp的软件包找出来,然后用 rpm -ivh安装

2.相关文件:
 对于时间方面在CentOS用的比较频繁的文件有:
 /usr/share/zonefile目录下的时区文件。由于我在中国,所以需要中国的时区。把/usr/share/zoneinfo/Asia/Hong_Kong文件覆盖了/etc/localtime文件即可
cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

接下来就是配置/etc/ntp.conf文件。该文件只需要配置主要的两部分:权限、连接远程服务器。
在该文件第19行开始添加入访问你ntp服务器的网路或者主机。例如:
restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.240.0 mask 255.255.255.0 nomodify notrap
关于restrict格式如下:
restrict [ip] mask [mask_number] [parameter]
其中parameter如下:
ignore:居然所有类型的ntp连接
nomodify:不允许客户端修改服务器的时间参数,但是允许客户端透过这部主机进行时间校验。
noquery:不允许客户端进行时间校验。
notrap:不提供trap时间登录
notrust:拒绝没有认证的客户端

然后设置server段,设置上层ntp服务器。具体格式如下:
server [IP or HOSTNAME] [PREFER]
国内经常用到的ntp服务器有如下:
 ntp.sjtu.edu.cn
 s1a.time.edu.cn
 s1b.time.edu.cn
 s1c.time.edu.cn
 s1d.time.edu.cn
 s1e.time.edu.cn
 s2a.time.edu.cn
 s2b.time.edu.cn
 s2c.time.edu.cn
 s2d.time.edu.cn
 s2e.time.edu.cn
 s2f.time.edu.cn
 s2g.time.edu.cn
 s2h.time.edu.cn
 s2j.time.edu.cn
 s2k.time.edu.cn
 s2m.time.edu.cn
 clock.cuhk.edu.hk
注销掉0.centos.pool.ntp.org、1.centos.pool.ntp.org、2.centos.pool.ntp.org,添加上述的服务器,如下所示:
server ntp.sjtu.edu.cn
server s1a.time.edu.cn
server s1b.time.edu.cn
server s1c.time.edu.cn
server s1d.time.edu.cn
server s1e.time.edu.cn
server s2a.time.edu.cn
server s2b.time.edu.cn
server s2c.time.edu.cn
server s2d.time.edu.cn
server s2e.time.edu.cn
server s2f.time.edu.cn
server s2g.time.edu.cn
server s2h.time.edu.cn
server s2j.time.edu.cn
server s2k.time.edu.cn
server s2m.time.edu.cn
server clock.cuhk.edu.hk
保存后退出

3.启动你的ntp服务
# /etc/init.d/ntpd restart
Shutting down ntpd:                                        [FAILED]
Starting ntpd:                                             [  OK  ]

观察你的ntp网络情况:
# netstat -tlunp | grep ntp
udp        0      0 192.168.100.253:123         0.0.0.0:*                               3846/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               3846/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               3846/ntpd           
udp        0      0 fe80::211:25ff:fea8:153a:123 :::*                                    3846/ntpd           
udp        0      0 ::1:123                     :::*                                    3846/ntpd           
udp        0      0 :::123                      :::*                                    3846/ntpd   


存在udp的123端口,则表示我们的ntp服务器已经建立并启动了。
检查是否有与上层ntp服务器联机:
# ntpstat 
unsynchronised
  time server re-starting
   polling server every 64 s
从命令中看出,并没有与上层ntp服务器进行联机
重新再次运行一次ntpstat
# ntpstat 
synchronised to NTP server (137.189.4.10) at stratum 2 
   time correct to within 46 ms
   polling server every 64 s
这次可以看出我们的ntp服务器器与上层的ntp服务器已经进行了同步。


4.客户端连接ntp服务器:
 我建议客户端只需要只用ntpdate向服务器提出同步请求,然后利用hwclock -w 命令进行写入客户端的BIOS。如果需要定时同步,可以利用crontab每小时同步一次即可。

阅读(1179) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~