ntp服务器搭建与修改时区

NTP是最长用的也是最基本的服务了,很多加密应用都依赖此服务,比如:openvpn、puppet、saltstack等都需要首先同步好时间,所以把搭建NTPserver总结下,方便以后自己查询。

首先下载ntp server源码包:ntp-4.2.6p5.tar,如附件。

解压,进入ntp-4.2.6p5目录开始安装,命令如下:
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install

安装完成后直接配置/etc/ntp.conf  是ntp这个包提供的配置文件,配置如下:

driftfile /var/lib/ntp/drift

#restrict default kod nomodify notrap nopeer noquery

restrict 58.55.127.0 mask 255.255.255.0 nomodify

restrict 221.235.188.0 mask 255.255.255.0 nomodify

restrict default nomodify notrap 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

server 0.centos.pool.ntp.org

server 1.centos.pool.ntp.org

server 2.centos.pool.ntp.org

修改配置文件:

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

server 0.pool.ntp.org

#server 0.centos.pool.ntp.org

#server 1.centos.pool.ntp.org

#server 2.centos.pool.ntp.org

配置完成后开启ntp服务:

[[email protected] logs]# /etc/init.d/ntpd restart

Shutting down ntpd:                                        [FAILED]

Starting ntpd:                                             [  OK  ]

查看服务是否正常运行:

[email protected] logs]# netstat -lntup |grep ntp

udp        0      0 192.168.2.137:123           0.0.0.0:*                               14010/ntpd

udp        0      0 58.55.127.137:123           0.0.0.0:*                               14010/ntpd

udp        0      0 127.0.0.1:123               0.0.0.0:*                               14010/ntpd

udp        0      0 0.0.0.0:123                 0.0.0.0:*                               14010/ntpd

udp        0      0 fe80::2a0:d1ff:feea:bd15:123 :::*                                    14010/ntpd

udp        0      0 fe80::2a0:d1ff:feea:bd14:123 :::*                                    14010/ntpd

udp        0      0 ::1:123                     :::*                                    14010/ntpd

udp        0      0 :::123                      :::*                                    14010/ntpd

查看NTP状态是否同步上层NTP服务器成功:

[[email protected] logs]# ntpstat

synchronised to NTP server (83.137.98.96) at stratum 3

time correct to within 499 ms

polling server every 64 s

看到synchronised to NTP server,说明已经同步成功了,

查看NTP Server时间是否正确:

[[email protected] logs]# date

Thu Sep  5 11:03:33 CST 2013

如果显示如下:

[[email protected] logs]# ntpstat

unsynchronised

polling server every 16 s

说明未同步成功,请检查配置是否修改正确。

还可以用这个命令查看;

[[email protected] logs]# ntpq -p

remote           refid      st t when poll reach   delay   offset  jitter

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

spacys.de       130.133.1.10     2 u   35   64    3  346.738   -7.946   0.536

blueshift.trevo 209.51.161.238   2 u   56   64    1  252.679    0.387   0.000

jaded.fsck.ca   132.163.4.103    2 u   45   64    1  286.477  -37.529   0.000
每项含义可以参照:
http://baike.baidu.com/view/5874764.htm

PS:
每次重启NTP 服务器之后大约要3-5 分钟客户端才能与server 建立正常的通讯
切记每次修改了配置文件后都需要重新启动服务来使配置生效。

命令行修改时区三步:

[[email protected] ~]# vi /etc/sysconfig/clock

ZONE="Asia/Shanghai"

[[email protected] ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

cp: overwrite `/etc/localtime‘? y

[[email protected] ~]# date

Thu Sep  5 19:33:12 CST 2013

最后crontab中添加:

*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1

Ntpdate –u +ip  同步时间。

原文地址: http://www.myjishu.com/?p=172

时间: 2024-08-17 09:30:19

ntp服务器搭建与修改时区的相关文章

鸟哥服务器架设——NTP服务器搭建

NTP服务器搭建 一.NTP通信协议 实际上,Linux操作系统的计时方式主要从1970年1月1日开始计算总秒数,因此,如果你还记得date这个命令的话,会发现他有个+%s的参数,可以去的总秒数,这个就是软件时钟.但是,如同前面说的,计算机硬件主要是以BIOS内部的时间为主要的时间依据(硬件时钟),而偏偏这个时间可能因为BIOS内部芯片本身的问题,而导致BIOS时间与标准时间(UTC)存在一点点的差异.所以,为了避免主机时间因为长期运行而导致时间偏差,进行时间同步(synchronize)的工作

Linux NTP 服务器搭建

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

windows ntp服务器搭建

ntp服务器搭建 1.      确定两台主机处于同一网段,能相互ping通 2.      单击"开始",单击"运行",键入 regedit,然后单击"确定". 3.      找到并单击下面的注册表子项:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\Type 4.      在右窗格中,右键单击"Type",然后单击"

Linux下NTP服务器搭建

一.搭建准备 1.确定自己的时区 #date命令可以查看当前系统时间,中国的时区为CST.使用tzselect命令进行配置时区 配置文件的修改:/etc/sysconfig/clock 2.检查NTP服务程序 #rpm -qa |grep ntp fontpackages-filesystem-1.41-1.1.el6.noarch ntpdate-4.2.4p8-3.el6.x86_64 如果没有,则需要安装ntp程序 #yum -y install ntp ntpdate 需要配置好yum源

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

ntp 服务器搭建

终于还是要搭建ntp服务器,我的架构是一台服务器可以上公网,其他内网服务器不能. ntp服务器是C/S架构的时间同步服务器. 方案: 公网服务器搭建ntp服务器端 其他服务器为客户端 公网服务器: [[email protected] ~]# yum install ntp 配置/etc/ntp.conf [[email protected] ~]# more /etc/ntp.conf |grep  -v ^$|grep -v ^# driftfile /var/lib/ntp/drift r

ntp服务器搭建与客户端设置

服务器对时间要求非常严格,linux服务器文件的生成,日志,以及数据库的连接都是根据时间的逻辑 进行任务处理,如果时间不同步,那么,处理的任务,以及出问题的分析日志,时间不对,很难分析 直接更改linux服务器时间,影响特别大,大家都知道,服务器群启动是有规律的,如果随便更改linux服务器时间 很有可能造成时间逻辑大站,造成其它模块报警,以及数据库报警等,所以建服务器之前,先配置ntp服务器, 部分服务器为了安全不能上网,所以不能同步网络时间,所以我们让它同步我局域网的ntp服务器,以下是设置

NTP服务器搭建

在ORACLE 10G环境中如果要搭建集群的话是需要同步时钟的,这就需要NTP服务器. 1.在授时系统机上,编辑/etc/ntp.conf retrict default nomodifyrestrict 127.0.0.1server 127.127.1.0fudge 127.127.1.0 stratum 8driftfile /var/lib/ntp/driftbroadcastdelay 0.008 然后重启ntpd服务 service ntpd restart 2.在其它主机上去同步时

linux基础之ntp服务器搭建

Linux ntp服务器配置 第一步.检查是否安装了ntp 运行如下命令: rpm -qa | grep ntp 如果有如下输出: ntp-4******** 表示有安装ntp 服务器 如果没有则安装. 第二步.修改ntp的配置文件 vi /etc/ntp.conf ①.第一种配置:允许任何IP的客户机都可以进行时间同步将"restrict default kod nomodify notrap nopeer noquery"这行修改成: restrict defaultnomodif