时间同步

一、时区调整

常见的时区

EDT  :格林威治时间,即0时区时间

UTC:世界协调时间,UTC和GMT的值相等(误差相当之小)

CST:北京时间 ,即东八区时间

 

1.调整linux主机时间为东八区时间(centos 为例)

显示当前时间

[root@host-192-168-118-56 ~]# date

Fri Aug 25 04:19:38 EDT 2017

显示当前时区

[root@host-192-168-118-56 ~]# ll /etc/localtime

lrwxrwxrwx. 1 root root 38 May 16  2016 /etc/localtime -> ../usr/share/zoneinfo/America/New_York

[root@host-192-168-118-56 ~]# mv /etc/localtime /etc/localtime.bak

修改主机时区

[root@host-192-168-118-56 ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

[root@host-192-168-118-56 ~]# ll /etc/localtime

lrwxrwxrwx 1 root root 33 Aug 25 16:25 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai

[root@host-192-168-118-56 ~]# date

Fri Aug 25 16:25:36 CST 2017

2.windows主机

在“日期时间设置”中直接选择北京时间

 

注:在日志分析项目中所有主机时间为北京时间

二、时间同步

1.使用公共ntp server进行时间同步

只需要配置ntp client端

(1)安装ntp服务

yum install ntp  

注:依赖包有libedit 和 ntpdate,ntp的版本为4.2.6p5-10.el6.centos.2

(2)设置开机启动

systemctl enable ntpd    或者  chkconfig ntpd on

(3)配置ntp client

driftfile /var/lib/ntp/drift

 

restrict 127.0.0.1

restrict ::1

 

#ntp server 地址

server 192.168.161.96

 

#同意ntp server 修改时间

restrict 192.168.161.96 nomodify notrap noquery

 

#外部时间server不可用时,以本地时间作为时间服务

server  127.127.1.0

fudge   127.127.1.0 stratum 10

 

logfile /var/log/ntp.log

 

includefile /etc/ntp/crypto/pw

 

keys /etc/ntp/keys

 

disable monitor

 

启动ntp服务

systemctl start ntpd

(4)测试ntp时间同步

[root@host-192-168-118-56 ~]# ntpdate -u 192.168.161.96

25 Aug 16:44:41 ntpdate[21994]: adjust time server 192.168.161.96 offset -0.058958 sec

(5)查看同步情况

# ntpq -p

# ntpstat

 

2.搭建自身的ntp server

配置ntp server 端,ntp client和使用公共ntp server 类似

(1)安装ntp服务

yum install ntp  

注:依赖包有libedit 和 ntpdate,ntp的版本为4.2.6p5-10.el6.centos.2

(2)设置开机启动

systemctl enable ntpd    或者  chkconfig ntpd on

(3)配置ntp server

driftfile /var/lib/ntp/drift

 

restrict 127.0.0.1

restrict ::1

 

# 同意内网其它机器同步时间

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

 

#国内ntp服务器

server ntp.sjtu.edu.cn

server s1a.time.edu.cn

server s1b.time.edu.cn

 

#默认ntp服务器

server 0.centos.pool.ntp.org iburst

server 1.centos.pool.ntp.org iburst

server 2.centos.pool.ntp.org iburst

server 3.centos.pool.ntp.org iburst

 

#同意上层时间server主动改动本机时间

restrict ntp.sjtu.edu.cn nomodify notrap noquery

restrict s1a.time.edu.cn nomodify notrap noquery

restrict s1b.time.edu.cn nomodify notrap noquery

 

# 外部时间server不可用时,以本地时间作为时间服务

server  127.127.1.0

fudge   127.127.1.0 stratum 10

 

logfile /var/log/ntp.log

 

includefile /etc/ntp/crypto/pw

 

keys /etc/ntp/keys

 

disable monitor

 

 

 

 

(4)配置防火墙端口

iptables -I INPUT -p udp -m udp --sport 123 -j ACCEPT

 

 

 

reference

http://www.cnblogs.com/yjbjingcha/p/6918917.html

http://blog.csdn.net/gycool21/article/details/51746174

国内常用的ntp server

ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)

s1a.time.edu.cn 北京邮电大学

s1b.time.edu.cn 清华大学

s1c.time.edu.cn 北京大学

s1d.time.edu.cn 东南大学

s1e.time.edu.cn 清华大学

s2a.time.edu.cn 清华大学

s2b.time.edu.cn 清华大学

s2c.time.edu.cn 北京邮电大学

s2d.time.edu.cn 西南地区网络中心

s2e.time.edu.cn 西北地区网络中心

s2f.time.edu.cn 东北地区网络中心

s2g.time.edu.cn 华东南地区网络中心

s2h.time.edu.cn 四川大学网络管理中心

s2j.time.edu.cn 大连理工大学网络中心

s2k.time.edu.cn CERNET桂林主节点

s2m.time.edu.cn 北京大学

——————————————————————————

 

210.72.145.44 (国家授时中心服务器IP地址)

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值