ntp服务器配置for linux

来源:互联网 发布:手机免费听歌软件 编辑:程序博客网 时间:2024/04/23 15:01

1.ntp服务器安装配置

yum install ntp* -y

[root@localhost ~]#   rpm -qa|grep ntp-
ntp-4.2.2p1-9.el5_4.1

2:编辑/etc/ntp.conf

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 0.0.0.0 mask 255.255.255.0 nomodify# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).#server 0.rhel.pool.ntp.org#server 1.rhel.pool.ntp.org#server 2.rhel.pool.ntp.orgserver 0.cn.pool.ntp.orgserver 0.asia.pool.ntp.orgserver 2.asia.pool.ntp.org#broadcast 192.168.1.255 key 42         # broadcast server#broadcastclient                        # broadcast client#broadcast 224.0.1.1 key 42             # multicast server#multicastclient 224.0.1.1              # multicast client#manycastserver 239.255.254.254         # manycast server#manycastclient 239.255.254.254 key 42  # manycast client# Undisciplined Local Clock. This is a fake driver intended for backup# and when no outside source of synchronized time is available.server  127.127.1.0     # local clockfudge   127.127.1.0 stratum 10# Drift file.  Put this in a directory which the daemon can write to.# No symbolic links allowed, either, since the daemon updates the file# by creating a temporary in the same directory and then rename()'ing# it to the file.driftfile /var/lib/ntp/drift# 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

3:重启服务,这里需要几分钟ntp服务才会和校时服务器同步的。

校时服务器/etc/ntp.conf里的:

server 0.cn.pool.ntp.org  //中国时间池
server 0.asia.pool.ntp.org
server 2.asia.pool.ntp.org

[root@localhost ~]#  /etc/init.d/ntpd restart
Shutting down ntpd:                                        [  OK  ]
Starting ntpd:                                             [  OK  ]

4:查看ntp服务器和校时服务器的连接状态  以及ntp服务器和校时服务是否同步过

[root@localhost ~]# watch ntpq -p

Every 2.0s: ntpq -p                                                                                 Tue May 28 21:13:02 2013

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 dns1.synet.edu. 123.199.115.203  2 u   46   64   37  799.820  409.310  23.205
 pache.auto-id.w 189.70.85.38     2 u   53   64   37  137.693   52.859  38.663
*211.39.136.4    198.123.30.132   2 u   11   64   77  112.189   88.152  19.073

[root@localhost ~]# ntpstat
synchronised to NTP server (211.39.136.4) at stratum 3   这里和校时服务器服务器同步之后 客户端才能从ntp服务器里同步时间 不然客户端同步时会报错。
   time correct to within 582 ms
   polling server every 64 s

ntp客户端同步--linux

首先关闭客户端ntp服务,不然和ntp服务器同步的时候会报错误

/etc/init.d/ntpd stop

chkconfig ntpd off

然后用

ntpdate server_ip进行同步,也可以用crontab搞个计划任务定时同步


ntp客户端同步--windows

首先在命令行启动W32Time服务

net start W32Time

然后用在这里同步


原创粉丝点击