Linux中时间服务器

wenzhongxiang
wenzhongxiang
管理员
304
文章
0
粉丝
Linux字数 558阅读模式

NTP时间服务器

  1. NTP简介

NTPNetwork Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms
文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

NTP服务器就是利用NTP协议提供时间同步服务的。
文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

2、NTP服务器安装文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

[root@XXX ~]# rpm -aq ntp
文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

[root@XXX ~]#
文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

[root@XXX ~]# yum -y install ntp
文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

[root@XXX ~]# rpm -aq ntp
文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

ntp-4.2.6p5-10.el6.centos.1.x86_64
文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

3、配置NTP服务(结果如下:)文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

黄色为添加项文章源自小温Talk.听闻 | 小温Talk-https://azureyun.azurewebsites.net/454.html

绿色为注释项

[root@XXX ~]# cat /etc/ntp.conf

# For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

#restrict default kod nomodify notrap nopeer noquery 注释掉

restrict -6 default kod nomodify notrap nopeer noquery

restrict default nomodify 添加此行

# Permit all access over the loopback interface. This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

restrict 127.0.0.1

restrict -6 ::1

# Hosts on local network are less restricted.

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

#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 —— |

server ntp1.aliyun.com 添加可用源

server time.nist.gov

#broadcast 192.168.1.255 autokey # broadcast server

#broadcastclient # broadcast client

#broadcast 224.0.1.1 autokey # multicast server

#multicastclient 224.0.1.1 # multicast client

#manycastserver 239.255.254.254 # manycast server

#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.

#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating

# with symmetric key cryptography.

keys /etc/ntp/keys

# Specify the key identifiers which are trusted.

#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.

#requestkey 8

# Specify the key identifier to use with the ntpq utility.

#controlkey 8

# Enable writing of statistics records.

#statistics clockstats cryptostats loopstats peerstats

[root@XXX ~]#

4、启动NTP服务器

[root@XXX ~]# /etc/init.d/ntpd start

正在启动 ntpd: [确定]

[root@XXX ~]# ntpq -p

remote refid st t when poll reach delay offset jitter

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

time5.aliyun.co .INIT. 16 u - 64 0 0.000 0.000 0.000

india.colorado. .NIST. 1 u 2 64 0 0.000 0.000 0.000

[root@XXX ~]# ntpstat

synchronised to NTP server (182.92.12.11) at stratum 3

time correct to within 8024 ms

polling server every 64 s

[root@XXX ~]# ntpdate 10.0.0.86

7 Jun 11:11:07 ntpdate[2286]: the NTP socket is in use, exiting

[root@XXX ~]#

5、客户机时间同步

[root@nfs ~]# date

2016年 06月 07日 星期二 09:11:09 CST

[root@nfs ~]# ntpdate 10.0.0.86

7 Jun 11:16:02 ntpdate[4301]: step time server 10.0.0.86 offset 7477.470757 sec

[root@nfs ~]# date

2016年 06月 07日 星期二 11:16:05 CST

[root@nfs ~]# crontab -e

#时间同步

* * * * * ntpdate 10.0.0.86

文章末尾固定信息

 
  • 本文由 wenzhongxiang 发表于06/07/2016 11:17:58
  • 转载请务必保留本文链接:https://azureyun.azurewebsites.net/454.html