linux ntp 服务器,时间同步

周氏一族,整理技术文档,给下一代留点教程......

公司服务器较多,各种服务分布式管理,所以时间的同步非常重要。

经过几番了解和思考之后,决定用这样的方式来控制时间同步

1、随便一台公网服务器server21,ntp 到 http://www.pool.ntp.org ,获得国际标准时间

2、内部形成一个局域网,全部所有机器,ntp到内网服务器 server21,获得同步

3、内网服务器,编写同步监控脚本,1小时执行一次,以确保时间同步无误。

服务器,centos 6.3  64bit

公网,server21服务器的配置如下:

-----------------------------------------------------------------------------------------------

已经安装好了,系统本身就有了,不需要安装,提示nothing to do,不鸟他

编辑ntp配置文件,配置文件之前,先来做一下前期工作

1、要找出来一个比较靠谱的公网服务器ntp才行,不能满大街,随便抓

2、我们可以到国际标准ntp平台,找,http://www.pool.ntp.org/zone/cn

3、定义好内网服务器的ip段,假如,我们定义为10.1.3.0/24

4、接下来,就真正要来开始配置 /etc/ntp.conf 了,配置文件如下:


[[email protected] ~]# cat /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 10.1.3.0 mask 255.255.255.0 nomodify notrap      //定义只有10.1.3.0的内网访问server21

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

#server 0.cn.pool.ntp.org    //因为我的服务器机房所在地,对第一个域名访问速度不好 ,所以屏蔽掉他

server 3.asia.pool.ntp.org

server 2.asia.pool.ntp.org

#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

# 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

5、启动ntp服务,加入开机自启动

service ntpd start  &&  chkconfig ntpd on

6、看一下ntp时间是否同步过来


[[email protected]_Master ~]# watch ntpq -p

Every 2.0s: ntpq -p                                                 Tue Aug 26 10:50:35 2014

remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

61.110.197.50   108.71.253.20    2 u   28   64    1  108.384   37.441   0.000

194.27.44.55    62.12.173.11     2 u   28   64    1  352.688   49.994   0.000

很明显, 已经在同步了。

7、注意,你问我,现在几点,我跟你说是11:46:00,但是,如果你问老外,现在几点,他可能会说,现在是24:00:00,因为时区不同,所以导致时间不一样。

因此,我们需要先定义好自身的时区,用下面这条命令

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

然后,再次重启一下ntp服务,时间就对了。

内网,所有服务器的配置如下:

-----------------------------------------------------------------------------------------------

[[email protected] ~]# crontab -e

#输入下面内容,保存退出完全wq!

00 */1 * * *  root /usr/sbin/ntpdate 10.1.3.21 && /sbin/hwclock -w

[[email protected] ~]# service crond restart

这样两条命令,就能让他自动更新时间,一小时/次

因为我这是真实的环境,所以会碰到很多问题,现在的问题就是所有服务器都是内网,当初都是最小化安装,所以没有装这些 crontab,但是又连不到外网,所以就不能yum 安装,只能rpm包了。

http://rpm.pbone.net/index.php3/stat/4/idpl/25006580/dir/centos_6/com/cronie-1.4.4-12.el6.x86_64.rpm.html

可以到这里来搜索,你要的rpm包,然后下载到本地,再上传到server21,再传给内网服务器

rpm -ivh --nodeps cronie-1.4.4-12.el6.x86_64.rpm

搞定

时间: 2024-08-14 02:10:16

linux ntp 服务器,时间同步的相关文章

Linux NTP服务器搭建精讲

Linux NTP服务器  (时间服务器) Date –s 22:12:30   # 设置时间 闰秒  7月1日07:59:60秒 在这个时候,要关闭ntp服务 1.1. 软件安装 所需软件:默认已安装 yum install ntp -y ntpdate-4.2.6p5-1.el6.centos.i686 fontpackages-filesystem-1.41-1.1.el6.noarch ntp-4.2.6p5-1.el6.centos.i686 1.2. 配置NTP 配置文件:   vi

Linux NTP 服务器搭建

Linux时间同步服务器搭建 NTP(Network Time Protocol)是用来使计算机时间同步化的一种协议,它使用UDP协议123号端口对外提供服务,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做时间的同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击.时间按NTP服务器的等级传播.按照离外部UTC源的远近把所有服务器归入不同的Stratum(层)中. 今天做一个项目需要配置一台NTP时间同步服

linux ntp 服务器和用户端

ntp 服务器 1.输入 rpm -qa|grep ntp 查看是否安装了ntp服务器 2.如果没安装 yum -y install ntp 安装 3.修改 /etc/ntp.conf 将原server加上注释 添加本地server 127.127.1.1 4.重启服务 systemctl restart ntpd.service使用 ntpq -p 查看是否为本地ntpd 5. 客户端配置 安装ntp 修改配置文档 vi /etc/ntp.conf 修改 server 服务器ip地址 ibur

【NetApp】配置NetApp控制器与Linux NTP服务器同步

Linux NTP服务器端配置: 1)设置/etc/ntp.conf配置文件 [[email protected] etc]# vi /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 # Pe

Linux集群的NTP服务器时间同步

我们搭建集群环境的时候,时间必须是要统一的,才能保证集群数据的一致性. 一般操作是直接使用NTP,跟默认的时间服务器同步,但是最好还是让所有节点跟集群中的某台作为时间服务器的节点同步. 步骤:(节点有NameNode1,NameNode2,DataNode1,DataNode2,DataNode3) 选择一台服务器作为时间服务器.(DataNode1做为时间服务器) 使用root用户,查看服务器是否安装ntp服务 rpm -qa|grep ntp 没有安装的话使用yum install进行安装.

ntp 服务器时间同步

win: 运行--services.msc, 开启windows time 自启动. 更改日期和时间设置--internet 时间-更改设置,选择服务器,windows默认的时间服务器为time.windows.com ,这个经常出问题,我们可以选择 time.nist.org 这台服务器, 点击立即更新,确定即可 linux: 一般通用的做法是通过定时任务实现,可直接修改vim /var/spool/cron/root(等同crontab -e), */5 * * * * /usr/sbin/

linux ntp服务器搭建

在VMvare中,采用的是光盘镜像安装, 1 . 安装ntp rpm 包 mount /dev/cdrom /mnt         #挂载光盘镜像文件到mnt下,便于访问 ls /mnt/Packages/ntp*      #找到ntp相关的rpm包 rpm -ivh

Linux -- NTP服务器配置

/etc/Linux NTP.conf System-config-date Network Time Protocol(Linux NTP,网络时间协议)用于同步它所有客户端时钟的服务.Linux NTP服务器将本地系统的时钟与一个公共的Linux NTP服务器同步然后作为时间主机提供服务,使本地网络的所有客户端能同步时钟. 同步时钟最大的好处就是相关系统上日志文件中的数据,如果网络中使用中央日志主机集中管理日志,得到的日志结果就更能反映真实情况.在同步了时钟的网络中,集中式的性能监控.服务监

Win12&16域控设置NTP服务器

PDC: 指定外部时间源并与之同步,在PDC所在的域控制器上的管理员命令行进行操作(PDC角色(默认的域内权威的时间服务源). w32tm /config /manualpeerlist:" 3.cn.pool.ntp.org 1.cn.pool.ntp.org" /syncfromflags:manual /reliable:yes /update net stop w32time & net start w32time w32tm /resync W32tm /query