您的位置:首页 > 编程语言 > PHP开发

NTP服务配置

2011-02-20 11:12 281 查看
ntp服务器配置笔记

一、安装
安装包名:ntp.i386
协议:udp
port:123

[root@station1 ~]#yum install ntp.i386
[root@station1 ~]#chkconfig ntpd on
[root@station1 ~]#service ntpd start

二、NTP服务器配置(IP:192.168.32.1)
1、修改主配置文件
[root@station1 ~]#vi /etc/ntp.conf
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
restrict 192.168.32.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.40.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 192.168.3.1
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.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 clock
fudge 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

注释说明:
restrict :指定可以进行ntp通信的IP地址或网段
ignore:关闭所有的ntp服务
nomodify:客户端不能更改ntp服务器的时间参数,但可以通过ntp服务器进行时间校对
noquery:不提供ntp服务
notrap:不提供trap远程事件登陆(Remote Event Logging)的功能
notrust:拒绝没有通过认证的客户端
kod:kod技术可以阻止“Kiss of Death”包(一种Dos攻击)对服务器的破坏,使用此参数开启该功能
nopeer:不与其他同一层的ntp服务器进行时间同步

server:指定该服务器上层ntp服务器,即为该服务器自身提供时间校对的ntp服务器,默认在指定上层ntp服务器后至少要15分钟才会和上层ntp服务器进行时间校对

fudge:修改ntp服务器相关参数
driftfile:指定记录ntp服务器和其上层ntp服务器间频率误差,一般无需修改
broadcast:指定进行ntp时间广播的网段,默认对所有能访问的网段广播
logfile:指定ntp服务器的日志文件

2、修改/etc/ntp/step-tickers文件(当ntpd服务启动时,会自动与该文件中的记录的上层ntp服务器进行时间校对)
[root@station1 ~]#vi /etc/ntp/step-stickers
192.168.3.1
127.127.1.0

3、修改/etc/sysconfig/ntpd文件(用来允许BIOS与系统时间同步,也可同hwclock -w命令同步)
[root@station1 ~]#vi /etc/sysconfig/ntp
SYNC_HWCLOCK=yes

三、NTP客户端配置(192.168.32.32)
1、修改/etc/ntp.conf
[root@station2 ~]#vi /etc/ntp.conf
server 192.168.32.31

2、修改/etc/ntp/step-stickers
[root@station2 ~]#vi /etc/ntp/step-stickers
192.168.32.31

3、[root@station1 ~]#service ntpd restart

4、校对和查询命令
ntpdate:校对命令
-d:查看连接过程的debug信息,不会调整本地时钟;有问题先用它试试找原因
-q 查询,不调整本地时钟
-u 使用非特权端口(即upd:123)发送数据包,在防火墙后核对时钟有用
eg:[root@station1 ~]#update -u 192.168.32.31

注:若是在运行以上命令出现提示:7 Dec 19:24:55 ntpdate[2120]: the NTP socket is in use, exiting
解决办法:关闭ntpd服务后,再用ntpdate 192.168.32.31校对时间,在启动ntpd服务。或者直接进入X11图形界面中修改ntpd配置,不用ntpdate校对,让系统自动去校对。

若提示:No Server suitable for synchronization found
这个是最容易出现的问题,比较常见的是配置好服务器并启动服务器进程后,马上启动客户进程,那么客户进程就会报错。解决方法是,在大约3-5分钟以后启动进程就行。

ntpstat:显示本机与上层ntp服务器同步时间的情况
ntpq -p:查看本机与上层ntp服务器通信情况
ntptrace:确定上层ntp服务器在哪里获得时间,并遵循ntp服务器链到他们的控制时间源

四、NTP服务相关文件
1、/usr/share/zoneinfo/:在该目录中的文件规定了各个主要时区的时间配置文件,如中国上海的时间配置文件为/usr/share/zoneinfo/Asia/Shanghai

2、/etc/sysconfig/clock:该文件指定系统中当前时区的信息,该文件是让系统知道应该使用/usr/share/zoneinfo/下的哪个时间配置文件

3、/etc/localtime:该文件是系统通过/etc/sysconfig/clock将/usr/share/zoneinfo/下指定的时间配置文件复制为/etc/localtime
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息