如何在linux suse中配置NTP服务器

如何在linux suse中配置NTP服务器,第1张

1
一个局域网中只需要一个NTP服务器,其他均为NTP客户端。
选择NTP服务器的原则:
该服务器可以上网:可以与标准Internet的服务器进行同步时间
Web服务器:
数据库服务器:

2
启动ntpd服务:
3
选择YaST
4
点击“系统”--> "系统服务(运行级别)"
5
选择"ntp" ,点击左下方的“启用”,
6
再点击“确定”
7
点击“确定”
8
选择’是’。

NTP服务端配置完成。
9
配置NTP客户端
使用crontab命令,定时执行与服务端同步命令。
ssh root用户登陆,执行命令:
linux-udly:~ # crontab –e

输入以下内容
0 /1 /usr/sbin/sntp -P no -r 192168150152 (对应的NTP服务器IP地址)

一、搭建时间服务器
1、在一台linux服务器安装ntp server
tar zxvf ntp-426targz
cd ntp-426
/configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install
2、修改ntpconf配置文件
vi /etc/ntpconf
# 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 default nomodify
(允许任何IP的客户机都可以进行时间同步,如果是只允许某个网段的客户机进行时间同步可以这样写
restrict 1058260 mask 2552552550 nomodify)
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 127001
restrict -6 ::1
# Hosts on local network are less restricted
#restrict 19216810 mask 2552552550 nomodify notrap
# Use public servers from the poolntporg project
# Please consider joining the pool
#server 0rhelpoolntporg(默认时间服务器)
#server 1rhelpoolntporg(默认时间服务器)
#server 2rhelpoolntporg(默认时间服务器)
server 101281425 (手工设置的时间服务器)
(如果是可以直连外网,可以使用LINUX默认提供的三组标准时间服务器,否则可以自己指定一个同步时间源)
#broadcast 1921681255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224011 key 42 # multicast server
#multicastclient 224011 # multicast client
#manycastserver 239255254254 # manycast server
#manycastclient 239255254254 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 12712710 # local clock
fudge 12712710 stratum 10
3、以守护进程启动ntpd
#/etc/rcd/initd/ntpd -c /etc/ntpconf -p /tmp/ntpdpid
#/etc/rcd/initd/ntpd start
#ps -ef|grep ntpd
4、在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令进行同步时会产生no server suitable for synchronization found的错误。
那么如何知道何时ntp server完成了和自身同步的过程呢?
在ntp server上使用命令:
# watch ntpq -p
出现如下画面:
注意LOCAL的这个就是与自身同步的ntp server。
注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒5=320秒的时间。
二、配置时间同步客户机
vi /var/spool/cron/root(或crontab -e)
增加一行,在每天的1点10分、9点10分、17点10分与时间同步服务器进行同步并写入BIOS
10 1 ,9,17 root /usr/sbin/ntpdate 101281425; /sbin/hwclock -w
如果同步不正常,可以加输出日志或看系统日志
输出日志的方法:
10 1 ,9,17 root /usr/sbin/ntpdate 101281425>>/tmp/1txt; /sbin/hwclock -w
在1txt中可查看时间同步时的输出结果。
或者看/var/mail/root系统日志
Subject: Cron <root@tyzssq8> /usr/sbin/ntpdate 101281425;/sbin/hwclock -w
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20121127103001076FF2090E@tyzssq8site>
Date: Tue, 27 Nov 2012 18:30:01 +0800 (CST)
27 Nov 18:29:59 ntpdate[6917]: step time server 101281425 offset -1361968 sec
可以看到同步成功了,如果未成功会报出错误。
三、无法同步的问题
检查ntp server主机的防火墙。可能是ntp server的防火墙屏蔽了upd 123端口。
可以用命令
#service iptables stop

执行ntpdate xxxxxxxxxxxx(ntp服务器地址)。
Linux下配置NTP服务器
配置方法:
1、ntp服务安装
NTP服务在RHEL5x中式默认安装的软件包,可用rpm -qa |grep
ntp检查是否安装,如果未安装可使用如下命令安装与删除NTP服务器软件包
#使用rpm方式安装
rpm -ivh ntp-422p1-8el5i386rmp
#使用yum方式安装
yum -y install ntpi
#使用rpm方式删除
rpm -e ntp-422pl-8el5i386rpm
#使用yum方式删除
yum -y remove ntpi
2、ntp服务配置
在ntp服务安装完成后,需要修改ntp服务配置文件。ntp服务主配置文件/etc/ntpconf
21 ntp服务的启动、暂停
NTP属于system
V服务,其启动、暂停相关命令如下:
#启动
service ntpd
start
#停止
Service ntpd
stop
#重新加载
service ntpd
reload
#查看当前启动状态
service ntpd
status
22 ntp服务自动加载
设置ntp服务下一次开机运行状态可通过命令配置
#在运行级别2、3、4、5上设置为自动运行
chkconfig
ntpd on
#在运行级别2、3、4、5上设置为不自动运行
chkconfig
ntpd off
#在运行级别3、5上设置为自动运行
chkconfig
ntpd --level 35 on
#在运行级别3、5上设置为不自动运行
chkconfig
ntpd --level 35 off
23 配置信息
配置ntp,将Internet上的时间服务器作为内部标准时间来源,过程如下
1)修改/etc/ntpconf文件
restrict default kod nomodify notrap nopeer noquery
restrict 127001
restrict -6::1
restrict 19216800 mask 2552552550 nomodify notrap
restrict 19216810 mask 2552552550 nomodify notrap
#指定Internet上的时间服务器
restrict 20746232182 mask 255255255255 nomodify notrap noquery
server 20746232182
server 12712710
fudge 12712710 stratum 10
keys /etc/ntp/keys
#指定NTP服务器日志文件
logfile /var/log/ntp
2)修改/etc/ntp/stpe-tickers文件,内容如下(当ntpd服务启动时,会自动与该文件中记录的上层NTP服务进行时间校对)
20746232182
12712710
3)修改/etc/sysconfig/ntpd文件,内容如下:
#允许BIOS与系统时间同步,也可以通过hwclock -w 命令
SYNC_HWCLOCK=yes
4)在配置完成并重新启动服务后,可通过ntpstat
命令显示本机上一次与上层ntp服务器同步时间的情况,也可以使用ntpq -p 查看本机与上层ntp服务器通信情况,
24 图形界面配置NTP
图形界面下直接用system-config-date, 在“Network Time Protocol”选项页指定NTP服务器后勾选“Synchronize system clock before startingservice”,将ntpd服务设置为自动运行即可。
25 客户端访问
1)Linux客户端可通过图形界面进行配置,也可以通过ntpdate命令立即与NTP服务器及行时间校对。
ntpdate 192168010
2)Windows客户端,只需双击任务栏右下角的时钟,选择“Internet时间”选项页,输入NTP服务IP地址或FQDN,并勾选“自动与Internet时间服务器同步”即可。
Windows默认7天自动更新一次,可通过修改注册表HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\services\W32Time\TimeProviders\NtpClient\SpecialPollInterval 默认单位为妙,修改后重新启动即可生效。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10618429.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存