ntp

安装NTP:

yum install ntp

1)[root@localhost ~]# cat /etc/ntp.conf

restrict defaultkod nomodify notrap nopeer noquery

restrict -6default kod nomodify notrap nopeer noquery

restrict127.0.0.1

restrict -6 ::1

restrict192.168.115.110 mask 255.255.255.0 nomodify notrap[U1]

restrict133.100.11.8 mask 255.255.255.0 nomodify notrap[U2]

 

server133.100.11.8 prefer[U3]

server ntp.nasa.gov

server0.centos.pool.ntp.org

server1.centos.pool.ntp.org

server2.centos.pool.ntp.org

 

 

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

 

driftfile/var/lib/ntp/drift

 

keys /etc/ntp/keys

logfile/var/log/ntp[U4]

 

 

 

2)[root@localhost ~]# cat /etc/ntp/step-tickers [U5]

Server 133.100.11.8

serverntp.nasa.gov

 

3)[root@localhost ~]# vim /etc/sysconfig/ntpd

# Drop root toid 'ntp:ntp' by default.

OPTIONS="-untp:ntp -p /var/run/ntpd.pid"

# Set to 'yes'to sync hw clock after successful ntpdate

SYNC_HWCLOCK=yes[U6]

# Additionaloptions for ntpdate

NTPDATE_OPTIONS=""

 

4)[root@localhost ~]# service ntpd restart

ntpd: 同步时间服务器:[确定]

同步硬件时钟到系统时钟 [确定]

启动 ntpd:[确定]

[root@localhost~]# netstat -lnup|grep ntpd #查看123端口是否打开

udp 0 0 192.168.115.110:123 0.0.0.0:* 4359/ntpd

……..

 

5)开机自启动设置

[root@localhost~]# chkconfig --list ntpd

ntpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

[root@localhost~]# chkconfig --level 35 ntpd on

[root@localhost~]# chkconfig --list ntpd

ntpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭

 

6)查看时间是否正确

[root@localhost~]# date #查看系统时间

2013年 07月 20日星期六 18:39:46 CST

[root@localhost~]# hwclock #查看Bios时间

2013年07月20日星期六 19时07分32秒 -0.491867 seconds

 

7)设置防火墙,不然客户端不能与NTP Server同步

[root@localhost~]# iptables -A INPUT -p UDP -i eth0 -s 192.168.115.0/24 --dport 123 -j ACCEPT

 

8)查看日志信息

[root@localhost~]# cat /var/log/ntp

20 Jul 18:15:46ntpd[4359]: synchronized to LOCAL(0), stratum 10

20 Jul 18:15:46ntpd[4359]: synchronized to 202.112.31.197, stratum 2

20 Jul 18:21:05ntpd[4359]: synchronized to 133.100.11.8, stratum 1

 

 

9)[root@localhost ~]# ntpstat

unsynchronised

polling server every 64 s

[root@localhost~]# ntpq -p

remote refid st t when poll reach delay offset jitter

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

*clock.tl.fukuok.GPS. 1 u 83 64 326 226.603 -31.129 20.566

xntp-nasa.arc.na.GPS. 1 u 21 64 273 339.440 -143.72 13.075

+dns1.synet.edu.202.118.1.46 2 u 16 64 377 67.670 -51.317 13.595

+dns2.synet.edu.202.118.1.46 2 u 21 64 377 66.114 -50.780 13.107

LOCAL(0) .LOCL. 10 l 24 64 377 0.000 0.000 0.015

 

 

 

[root@30 ~]# ntpdate -u  133.100.11.8

10 Oct 15:46:30 ntpdate[2329]: step time server 133.100.11.8 offset 126250583.351436 sec

 

 

 

Linux 客户端同步

 Vim /etc/crontab 

0 */2 * * * root /usr/sbin/ntpdate –u ntp.nasa.com

 

 

 

driftfile /var/lib/ntp/drift

restrict default kod nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict -6 ::1

restrict 192.168.110.0 mask 255.255.255.0 nomodify notrap

server 192.168.110.1

server 192.168.110.131

server  127.127.1.0     # local clock

fudge   127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

logfile /var/log/ntp

 

 

 

 

[root@desktop2 ~]# cat /etc/ntp/step-tickers //NTP服务启动时,会自动与该文件中的记录的上层NTP服务进行时间校对

# List of servers used for initial synchronization.

192.168.0.254

[root@desktop2 ~]# cat /etc/sysconfig/ntpd //允许BIOS与系统时间同步

# Drop root to id 'ntp:ntp' by default.

SYNC_HWCLOCK=yes

OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"

3、启动NTP服务

[root@desktop2 ~]# service ntpd start

[root@desktop2 ~]# chkconfig ntpd on

4NTP的测试

[root@desktop2 ~]# ntpstat 

synchronised to NTP server (192.168.0.254) at stratum 12 //进行时间校对的NTP服务器

   time correct to within 958 ms //本地与上层NTP服务器的时间差

   polling server every 64 s //下次同步时间

[root@desktop2 ~]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

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

*instructor.exam LOCAL(0)        11 u   26   64  377    0.807    0.030   0.219

 LOCAL(0)        .LOCL.          10 l   27   64  377    0.000    0.000   0.000

 

 

转载于:https://my.oschina.net/u/1420001/blog/345470

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值