Chinaunix首页 | 论坛 | 博客
  • 博客访问: 695696
  • 博文数量: 143
  • 博客积分: 1554
  • 博客等级: 上尉
  • 技术积分: 1767
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-10 11:50
文章分类

全部博文(143)

文章存档

2017年(2)

2016年(5)

2015年(16)

2014年(25)

2013年(27)

2012年(16)

2011年(52)

分类: 系统运维

2011-07-19 14:40:37

NTP时间服务器
NTP(Network Time Protocol,网络时间协议),使用UDP协议123端口
一、NTP服务端
安装
     rpm包安装  rpm -ivh ntp-4.x.rpm 或yum 安装   yum -y install ntp.i*
修改配置文件
 #vi /etc/ntp.conf
 第一种:允许任何IP的客户端都可以进行时间同步
 #restrict default kod nomodify notrap nopeer noquery
 restrict default modify notrap
 第二种:允许192.168.2.0网段的客服端进行时间同步
 在restart default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
 restrict 192.168.2.0 mask 255.255.255.0 nomodify motrap
 
权限主要以restrict这个参数来设定,格式如下
restrict IP地址 mask 子网掩码 参数
其中ignore:关闭所有NTP联机服务
    nomodify 客服端不能更改服务端时间参数,但客户端可以通过服务端进行网络校队
    notrust  客服端除非通过认证,否则该客服端来源将被视为不信任子网
    noquery   不提供客户端的时间查询
   如果没有参数设定,那就表示该IP(或子网)没有任何限制
用server这个参数设定上级时间服务器,格式如下
    server IP地址或域名【prefer】
其中IP地址或域名是制定上级时间服务器,如果server参数最后没有prefer,那表示NTP服务器以该部主机时间进行校准

启动NTP服务
#server  ntpd start
#chkconfig --level 35 ntpd on #开机启动服务
注意:ntpd启动后,客服端要等几分钟再与其同步,否则会提示“no server suitable for synchronization found”
 
二、客服端
#/usr/sbin/ntpdate 192.168.2.10  #NTP服务端的IP地址
#crontab -e       #加入计划任务
30 8 * * * /usr/sbin/ntpdate 192.168.2.10; /sbin/hwclock -w  #定时同步并写入到BIOS
 
 
=========================================================================
1.防火墙阻止的话
iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT
2.客户端报错“the NTP socket is in use, exiting”的问题,解决办法:
# service ntpd stop(关闭客户端的ntpd服务)
3.把系统时间写进COMS
#clock -w

实例:
1.以互联网的时间服务器为NTP
#vi /etc/ntp.conf
restrict default ignore #关闭所有的NTP要求封包
restrict 192.168.2.0 mask 255.255.255.0 nomodify motrap
server time.nist.gov #设置时间服务器
server 127.127.1.1    #开启内部递归网络接口lo
fudge 127.127.1.1 stratum 10 refid NIST   #LCL不同步
friftfile /etc/ntp.drift
logfile /var/log/ntp.log
Broadcastdelay 0.008  #广播延迟时间
 
2.以内部NTP服务器为数据服务器时钟
#vi /etc/ntp.conf
restrict default ignore #关闭所有的NTP要求封包
restrict 127.0.0.1 #开启内部递归网络接口 lo
restrict 192.168.2.0 mask 255.255.255.0 nomodify
driftfile /var/lib/ntp/drift
broadcastdelay 0.008    #广播延迟时间
 
另外,如果客户端可以上网可以直接同步互联网上的时间
在crontab -e中编辑出
/usr/sbin/ntpdate pool.ntp.org即可。
或者
 三、定时同步时间
* * * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1
将系统时间同步到硬件
hwclock –systohc
 
 
 
阅读(1919) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~