xp架ntpp系统时间服务器,ntp时间服务器(示例代码)

1、NTP时间服务器:

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

NTP服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致,某些应用对时间实时性要求高的必须统一时间。

基于Client/server模式,udp123端口

2、安装步骤:

2.1、 服务器端:

NTP服务器监听端口为UDP的123,那就需要在本地防火墙开启运行客户端访问123端口,vi /etc/sysconfig/iptables添加如下规则:

-A INPUT -m state --state NEW -m udp -pudp --dport 123 -j ACCEPT

2.1.1、首先关闭防火墙:  /etc/init.d/iptables stop

或关闭Selinux软件服务:Setenforce 0临时关闭

2.1.2、[[email protected]~]#yum install ntp* -y//安装ntp软件

[[email protected] ~]#cp /etc/ntp.conf/etc/ntp.conf.bak  //备份ntp主配置文件

[[email protected] ~]#vi /etc/ntp.conf  //修改ntp主配置文件

[[email protected]~]#cat /etc/ntp.conf   //查看主配置文件

driftfile /var/lib/ntp/drift

//在与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内

restrictdefault kod nomodify notrap nopeer noquery

//允许所有来跟我进行同步

restrict 127.0.0.1//开启内部递归网络接口lo

restrict 192.168.1.0 mask255.255.255.0 nomodify notrap

//定义可访问的内部子网客户端,但不能修改NTP服务器的时间参数。

server 0.centos.pool.ntp.org iburst

//上级时间服务器

server 127.127.1.0# local clock//设置与本机ntp同步时钟

[[email protected]~]# /etc/init.d/ntpd start

//启动ntp服务,客户端需要几分钟后才能同步,否则会提示错误.

[[email protected] ~]# netstat -nulp|grep ntp   //查看是否有ntp进程

查看ntp服务器的上级服务器或

[[email protected] ~]# watch ntpq -p

remote           refid      st t when poll reach   delay  offset  jitter

==============================================================================

ntp1.ams1.nl.le 130.133.1.10     2 u  15   64  153 337.087  -705047 7050475

注释:remote-本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先

refid-参考上一层ntp主机地址

st- stratum阶层

when-多少秒前曾经同步过时间

poll-下次更新在多少秒后

reach-已经向上层ntp服务器要求更新的次数

delay-网络延迟

offset-时间补偿

jitter-系统时间与bios时间差

2.2、客户端:

[[email protected] ~]# ntpdate172.16.30.12  //与NTP进行同步

30 May 01:15:35 ntpdate[1096]: adjust timeserver 172.16.30.12 offset 0.003669 sec

备注:如果客户机没有ntpdate,可以yum –y install ntp 即可!

客户端创建计划任务:

crontab -e创建客户端定期同步,需创建计划任务。

如:增加一行,在每天的6点10分与时间同步服务器进行同步

10(分)  06(时) *(日) *(月) *(周)/usr/sbin/ntpdate ntp-server的ip (172.16.30.10)>>/usr/local/logs/crontab/ntpdate.log

crontab -l//查看计划任务

备注:如果客户机没有crontab,可以yum  install cron*  -y 即可。

crontab主要用来创建计划任务

2.3、ntp客户端同步时的错误解决方案:

[[email protected]~]# ntpdate 172.16.30.12

30 May11:50:29 ntpdate[1136]: no server suitable for synchronization found

客户端用[[email protected]~]# ntpdate  -d 172.16.30.12

错误1.Serverdropped: no data

关闭防火墙或者加入规则-AINPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值