记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。

RHEL6.5,Centos6.5配置NTP服务器并调整时区,供内网服务器使用NTP同步时间


内部有一台web服务器可以上外网,但是内网其它很多机器不能上网,

需要同步时间,就把这台web服务器作成NTP服务器供内部网络使用。

网上有不少资料,但是都是人云亦云,

实际配置后,根本不能用,其实很简单。


至于什么iptables防火墙,selinux,修改时区tzselect命令 ,自行脑补。


这里我将硬件时间与系统时钟,修改成一样的,采用本地时钟。

[root@web ~] #   vi /etc/adjtime

-4.943613 1478145537 0.000000
1478145537
LOCAL

将UTC修改成LOCAL。

注意系统时间不能相差太大。


首先安装软件,比较简单,不说了。

[root@web ~] #  yum install ntp* -y


修改NTP服务器端配置文件:


[root@web ~]# 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 nomodify notrap noquery
restrict -6 default nomodify  notrap 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 192.168.11.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).

server ch.pool.ntp.org    prefer
server ntp1.aliyun.com  

 

#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


注意: 红色是添加或修改的内容。

自己根据情况修改,192.168.11.0是允许本地局域网服务器可以同步时间。


同步硬件时间,修改红色部分

[root@web  ~]#  cat /etc/sysconfig/ntpd

# Drop root to id 'ntp:ntp' by default.
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"
SYNC_HWCLOCK=yes


重启NTP服务,过几分钟,查看时间是否同步。

[root@web  ~]#  chkconfig ntpd on

[root@web  ~]#  service ntpd  restart


[root@web  ~]#   ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-bwntpo.bluewin. 195.186.11.242   2 u  94m 1024  240  277.403  106.241   4.865
+ntp.bradfordemb 193.190.230.65   2 u  311 1024  227  239.127  -37.468  10.503
*82.200.209.236  89.109.251.21    2 u  246 1024  377  287.810   41.949  14.389
+time.unisza.edu 87.120.164.97    2 u  672 1024  337  211.284  -46.958  17.268
-202.118.1.130   202.118.1.46     2 u  175 1024  171  320.606  157.431  20.613

 dns2.synet.edu. 202.118.1.47     2 u   8h 1024    0   57.344   24.287   0.000


[root@web  ~]#   ntpstat
synchronised to NTP server (82.200.209.236) at stratum 3
   time correct to within 530 ms
   polling server every 1024 s

 




NTP客户端服务器配置定时同步,也很简单。

先将硬件时间与系统时钟,修改成一样的,采用本地时钟。

[root@web ~] #   vi /etc/adjtime

-4.943613 1478145537 0.000000
1478145537
LOCAL

将UTC修改成LOCAL。

注意系统时间不能相差太大。



直接配置定时任务。

 [root@web  ~]#  echo "0 1 * * * root (/usr/sbin/ntpdate 192.168.11.192 && /sbin/hwclock -w) && 2>&1 > /dev/null" >> /etc/crontab

 [root@web  ~]#  /etc/init.d/crond restart


每天早上1点,同步一次时间。


搞定收工。


NTP 服务器列表

  1. 最常见、熟知的就是 www.pool.ntp.org/zone/cn,国内地址为:cn.pool.ntp.org
  2. Windows 系统上自带的俩个:time.windows.comtime.nist.gov
  3. Mac OS X 上自带的俩个:time.apple.comtime.asia.apple.com
  4. 一个国内无偿提供的 NTP 服务器,速度可以,但地址池有两个 IP 已不可用,我已邮件给官方。官网:NTP授时快速域名服务,NTP 服务器:cn.ntp.org.cn
  5. 来自阿里云的 NTP 服务器:【吓到了吧,7 个】
    • ntp1.aliyun.com
    • ntp2.aliyun.com
    • ntp3.aliyun.com
    • ntp4.aliyun.com
    • ntp5.aliyun.com
    • ntp6.aliyun.com
    • ntp7.aliyun.com


当前已提供的各国NTP服务器列表

[INTERNATIONAL NTP server list.]

区域[zone]                域名[Domain]
中国[China]             cn.ntp.org.cn
中国教育网[China-EDU]    edu.ntp.org.cn
中国台湾[ChinaTaiwan]    tw.ntp.org.cn
美国[America]            us.ntp.org.cn
新加坡[Singapore]        sgp.ntp.org.cn
韩国[korea]                kr.ntp.org.cn
德国[Germany]            de.ntp.org.cn
日本[Japan]                jp.ntp.org.cn

-注:多组IP则为多IP轮询[Group IP was using IP-list polling]。


当前已提供的特殊机房NTP服务器列表

[Special IDC currently provides a list of NTP servers]:

区域[zone]域名[Domain]IP池[IP Pool]
Simcentricsim.ntp.org.cn[182.16.3.162]

-注:仅在特定机房内有效[Only for special IDC]。




转载请标明出处【RHEL6.5,Centos6.5配置NTP服务器并调整时区,供内网服务器使用NTP同步时间】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论