服务器系统使用ntp,NTP服务器相关配置和使用

3 NTP服务器的安装和设置

3.1 检查需要的包

[root@rhel ~]# rpm -qa |grep ntp --ntp的主要软件,包括配置文件和执行文件等。

ntp-4.2.4p8-2.el6.i686

ntpdate-4.2.4p8-2.el6.i686

fontpackages-filesystem-1.41-1.1.el6.noarch

[root@rhel ~]# rpm -qa|grep tzdata  -- time zone data ,主要提供各个时区对应的显示格式。

tzdata-java-2010l-1.el6.noarch

tzdata-2010l-1.el6.noarch

[root@rhel ~]#

3.2配置文件(1) /etc/ntp.confntp daemon的主要配置文件,不同版本可能放置的目录不同,RedHat 6 是放在/etc目录下,可以通过locate 查找。

root@rhel ~]# locate ntp.conf

/etc/.ntp.conf.swp

/etc/ntp.conf

/usr/share/man/man5/ntp.conf.5.gz

/usr/share/system-config-date/ntp.conf.templat

(2)/etc/sysconfig/clock

每次开机会读取 该文件中包含的配置文件中默认色显示时间。会将ZONE对应的文件另存为/etc/localtime,可以从后面两个文件的内容看出。

[root@rhel Asia]# less /etc/sysconfig/clock

# The time zone of the system is defined by the contents of /etc/localtime.

# This file is only for evaluation by system-config-date, do not rely on its

# contents elsewhere.

ZONE="Asia/Shanghai"

(END)

(3) /usr/share/zoneinfo目录

linux本身提供,www.linuxidc.com规定了各个主要时区的时间设置文件,如shanghai.

root@rhel Asia]# pwd

/usr/share/zoneinfo/Asia

[root@rhel Asia]# ls -al Shanghai

-rw-r--r--. 3 root root 405 Aug 31  2010 Shanghai

[root@rhel Asia]# strings Shanghai

TZif2

p ~h

!Iap"^J

#)Cp$Gg

TZif2

!Iap

#)Cp

CST-8(4)[root@rhel Asia]# strings /etc/localtime

TZif2

p ~h

!Iap"^J

#)Cp$Gg

TZif2

!Iap

#)Cp

CST-8

(5)/bin/date

(6)/sbin/hwclock

因为biso时间和系统时间是分开的,用date调整了系统时间后,通过该命令将修改后的时间写入bios.

[root@rhel Asia]# whereis hwclock

hwclock: /sbin/hwclock /usr/sbin/hwclock /usr/share/man/man8/hwclock.8.gz

[root@rhel Asia]# hwclock

Sat 17 Sep 2011 06:50:23 PM CST  -0.229942 seconds

(7)/usr/sbin/ntpd

服务器daemon

(8)/usr/sbin/ntpdate

client 端用于连接ntp server.

[root@rhel Asia]# ntpdate 0.pool.ntp.org

17 Sep 19:20:32 ntpdate[16649]: step time server 115.181.34.4 offset 6404.317378 sec

(9)/usr/sbin/ntptrace

3.3/etc/ntp.conf配置文件

[root@rhel ~]# less /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

# 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.rhel.pool.ntp.org iburst

server 2.rhel.pool.ntp.org iburst

#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

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

#fudge  127.127.1.0 stratum 10

# 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

server 0.pool.ntp.org iburst

(END)

说明:driftfile /var/lib/ntp/drift   #由于ntp server本身的时间是依据bios芯片震动周期频率计算的,与上层ntp server不完全一致,两者频率的误差记录在该文件中。

ps:必须是完整的路径;不能是链接文件,需要设置ntp有写入权限;数值单位为百万分之一秒(ppm).

[root@rhel ntp]# less drift

-395.982restrict  [ip]  mask [netmask_ip] [parameter]

parameter参数主要有:

ignore: 拒绝所有类型的NTP联机

nomodify:不能更改ntp服务器的时间参数

noquery:不提供ntp的网络校时。

notrap:不提供trap远程事件登陆的功能。

notrust:拒绝没有认证的客户端。

ip段没带任何的parameter,即缺省情况下,表示“该ip或网段不受任何限制".

serverip or hostname [prefer] 上层ntp 服务器的。

[root@rhel ntp]# vim /etc/sysconfig/ntpd

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

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

SYNC_HWCLOCK=yes  #同步BIOS的时间。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值