linux服务器id不同步,linux 时间同步两法 Linux时间服务器安装配置 ntpdate ...-百 …...

ntpdate 210.72.145.44 同步北京时间

1. 与一个已知的时间服务器同步

2.

1. 让linux自动同步时间

vi /etc/crontab

加上一句:

00 0 1 * * root rdate -s time.nist.gov

time.nist.gov 是一个时间服务器.

2. 时间服务器配置(192.168.10.1)1). # rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm

2). # vi /etc/ntp.conf

注释一行

restrict default ignore

加入一行

restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap

3). # vi /etc/ntp/step-tickers

加入一行

pool.ntp.org

这样每次ntpd启动时,会自动连接该国际标准时间服务器;

4). # service ntpd start

5). # netstat -an |grep 123

确保该端口以udp方式开放

时间客户端配置(192.168.10.2)

1). # ntpdate 192.168.10.2

应该显示同步成功

2). # crond -e

加入

0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1

表示每隔10分钟同步一次时间

Linux时间服务器安装配置

1、 创建/etc/ntp.conf文件,添加如下内容:

server clepsydra.dec.com # 外部时间服务器

driftfile /etc/ntp.drift

2、 创建/etc/ntp.drift,建立一个空文件就成

3、 启动时间服务器:

#/etc/rc.d/init.d/ntpd start

客户端配置:

1、 同步时间

ntpdate 时间服务器地址

2、 加入crontab, 每天同步一次.

0 1 * * * /usr/sbin/ntpdate 时间服务器地址

客户端启动时间同步要在服务器启动完后5-10分在启动客户端的时间同步。不然会报错。

时间更改

Date 月日时分年

注意这都是改 linuxlocal clock,最后注意要执行 hwclock -w 把时间更新写入 bios/cmos 内硬体时钟

3.防火墙问题的话,送一句配置

iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT

也就是123 udp in 全部接受

服务器配置完成后启动

1种:可以在/etc/rc.d/init.d/ntpd 启动

2种:#/sbin/service ntpd start //启动ntpd 参数可为restart start stop

#/sbin/chkconfig --add ntpd

#/sbin/chkconfig --level 234 ntpd on //配置在开机时运行

Linux自带了ntp服务--/etc/init.d/ntpd,这个服务不仅可以设置让本机和某台/某些机器做时间同步,他本身还可以扮演一个time的角色,让其他机器和他同步时间,配置文件就是/etc/ntp.conf。

现有4台机器,让217做时间服务器,让218、219、200与217进行同步,配置如下:

第一步:

[root@eytdb etc]# rpm -qa|grep ntp --是否已经安装了这个软件包:[root@eytdb etc]# ntpstat --NTP服务状态查询

217做time server,217本身不和其他机器时间同步,就是取本地时间,先把217机器的时间调准了:[root@eytdb etc]# date --set "10/26/2011 16:05:00"

[root@eytdb etc]# clock -w

[root@eytdb etc]# hwclock --systohc后两个命令是把设置的时间写到硬件时间中去(也就是CMOS里面的时间)。

第二步:然后将217配置成一个time server,修改/etc/ntp.conf,[root@eytdb etc]# cp ntp.conf ntp-back.conf --先备份[root@eytdb etc]# vi /etc/ntp.conf其他的配置不怎么需要改,只需要关注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

内容来自网络

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值