ntpdate210.72.145.44北京时间同步
1 .与已知时间服务器同步
2.
在linux上自动同步时间
vi/etc/crontab
补充一句:
0001**rootrdate-stime.nist.gov
time.nist.gov是时间服务器。
2 .时间服务器配置(192.168.10.1 )1).# rpm-ivhntp-4.1.2-4.El 3.1.i386.rpm
2 )、#vi/etc/ntp.conf
一行注释
restrictdefaultignore
添加一行
restrict 192.168.10.0 mask 255.255.255.0 notrustnomodifynotrap
3 )、#vi/etc/ntp/step-tickers
添加一行
pool.ntp.org
这样,每当ntpd启动时,它就会自动连接到国际标准时间服务
4 )、#servicentpdstart
5 ).#netstat-an|grep123
验证端口是否在udp中打开
时间客户端配置(192.168.10.2 ) ) ) ) ) ) ) ) ) )。
1 )、#ntpdate192.168.10.2
应该表明同步成功了
2 )、#crond-e
添加
0-59/10 * * */usr/sbin/ntpdate 192.168.10.1
指示每10分钟同步的时间
Linux时间服务器的安装配置
1、创建/etc/ntp.conf文件,添加以下内容:
serverclepsydra.dec.com#外部时间服务器
driftfile/etc/ntp.drift
2、创建/etc/ntp.drift,创建一个空文件即可
3、启动时间服务器:
#/etc/rc.d/init.d/ntpdstart
客户端配置:
1、同步时间
ntpdate时间服务器地址
2、加入crontab,每日同步。
01***/usr/sbin/ntpdate时间服务器地址
客户端开始时间同步将在服务器启动后5-10分钟同步到客户端开始时间。 否则我会报告错误。
更改时间
日期年月日时分年
请注意,这都将更改linuxlocalclock。 最后,请注意运行hwclock-w以将时间更新写入bios/cmos中的硬件时钟
3 .如果是防火墙的问题,发送一句配置
iptables-t filter-a input-pudp-- destination-port 123-j accept
也就是说123udpin全部接受
服务器配置完成后启动
1类:可通过/etc/rc.d/init.d/ntpd启动
两种类型: #/sbin/servicentpdstart//启动ntpd参数可以是重新开始停止
#/sbin/chkconfig----addntpd
#/sbin/chkconfig-- level 234 ntpd on//配置在通电时执行
Linux附带了ntp服务--/etc/init.d/ntpd。 该服务不仅可以使本地计算机和某台/某台计算机的时间同步,还可以起到与其他计算机同步时间的time作用。 配置文件为/etc/ntp.conf。
将现有的4台机器,217作为时间服务器,使218、219、200和217同步,构成如下。
第一步:
[ root @ eytdbetc ] # rpm-QA|grep NTP--是否已经安装了此程序包? [root@eytdbetc]#ntpstat--NTP服务状态查询
通过217timeserver,217自己不与其他机器的时间同步是留出本地的时间。 首先调整了217台机器的时间。 [ root @ eytdbetc ] # date-- set ' 10/26/20111633600536000 ]
[root@eytdbetc]#clock-w
[ root @ eytdbetc ] # hwclock-- systohc后面的两个命令将设置的时间写入硬件时间。 也就是CMOS中的时间。
步骤:然后,将217配置为timeserver,更改/etc/ntp.conf,然后单击[ root @ eytdbetc ] # CP NTP.conf NTP-back.conf-- -首先单击[ root ]
关注restrict的配置:1.注释掉下面2行,意思是不响应任何的ntp更新请求,其实也就是禁用了本机的ntp server的功能,所以需要注释掉。# restrict default kod nomodify notrap nopeer noquery --对于默认的client拒绝所有的操作# restrict -6 default kod nomodify notrap nopeer noquery
2.加入下面3行--让x.x.x.218---200网段上的机器能和本机做时间同步restrict x.x.x.218 mask 255.255.255.0 nomodify notrap ---x.x.x.218为需要同步的机器IP地址restrict x.x.x.219 mask 255.255.255.0 nomodify notrap
restrict x.x.x.200 mask 255.255.255.0 nomodify notrap
restrict x.x.x.190 nomodify notrap ---x.x.x.190可以同步时间x.x.x.191等不可以同步--说明:ignore关闭所有的NTP服务,nomodify客户端不能修改时间服务器的参数,只能进行时间校对restrict IP地址mask子网掩码参数其中IP可以是IP地址,也可以是default,default就是指所有的IP参数有以下几个:
notrap不提供trap远程事件登陆的功能,
ignore:关闭所有的NTP联机服务
noquery:不提供客户端的时间查询
notrust拒绝所有通过认证的客服端,kod kod技术可以阻止KissOf Death包对服务器的破坏,使用此参数将开启该功能。nopeer不与同一层的NTP服务器进行时间的同步当然,也可以添加server xxx.xxx.xxx.xxx,让他和其他的timeserver时间同步。
3.重启服务/etc/init.d/ntpd restart或者:启动/停止/重启动NTP服务的命令:service ntpd start|stop|restart
4. NTP服务开机自动启动的配置及检查命令:chkconfig ntpd on --在运行级别2、3、4、5上设置为自动运行或chkconfig --level 35 ntpd on --在运行级别3、5上设置为自动运行(打开自动启动用“on”;去掉自动启动用“off”)# watch ntpq -p --查看# chkconfig --list --检查ntpd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭ntpdate 0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
5.修改iptables配置,将tcp和udp 123端口开放,这是ntp需要的端口,在/etc/services中可以查到这个端口。--打开端口[root@eytdb etc]# iptables -I INPUT -p udp --dport 123 -j ACCEPT
或者[root@eytdb etc]#iptables-A INPUT -p UDP -i eth0 -s 192.168.0.0/24 --dport 123 -j ACCEPT
这样217就成为一台time server了.
可以使用下面的命令来检查NTP服务是否启动,可以得到一个进程ID号:[root@eytdb etc]# pgrep ntpd
26957
26959
使用下面的命令检查时间服务器同步的状态:[root@eytdb etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 10 l 46 64 377 0.000 0.000 0.000
第三步:配置其它几台机器,也是修改/etc/ntp.conf,[root@eytweb ~]# vi /etc/ntp.conf
1.注释掉server 127.127.1.0, fudge 127.127.1.0 stratum 10这两行,因为这台机器不需要和本地硬件时钟同步了。2.加入server x.x.x.217这行,和217机器同步。
配置完成,看时间已经和217同步了。往后默认配置好像是5分钟和time server同步一次。ntpdate命令是显式的和某台机器做时间同步.
[root@eytweb ~]# ntpq -p --检查与217机器是否同步remote refid st t when poll reach delay offset jitter
==============================================================================
*x.x.x.217 .INIT. 16 u 39 128 376 0.150 0.057 0.017
第四步,将ntpdate放到crontab中定期步也是可以的[root@eytweb ~]#vi ntpupdate.sh
/usr/sbin/ntpdate x.x.x.217
[root@eytweb ~]#chmod 755 ntpupdate.sh
[root@eytweb ~]#crontab -e
1 * * * * /root/ntpupdate.sh --每小时的第1分钟做一次时间同步[root@eytweb ~]#/etc/init.d/crond restart
内容来自网络