Linux时间同步

发布 : 2019-06-21 分类 : Linux 浏览 :

Linux局域网的时间同步
两台服务器:一台有外网,一台只有内网,由外网服务器做时间服务器

时间初步设置

先查看时间并进行初步设置(防止时间差太大同步不成功)

1
2
3
4
5
6
7
8
9
10
11
date -R

date -s xxxx-xx-xx #设置年月日
date -s xx:xx:xx #设置时间

date -s xxxx-xx-xx xx:xx:xx #设置年月日时间

#设置时区
rm -rf /etc/localtime #移除时区文件
#软连时区到东8区
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

安装时间同步工具NTP

1
yum -y install ntpdate ntp

时间服务端配置

配置时间同步
vim /etc/ntp.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

restrict 127.0.0.1
restrict -6 ::1

restrict 10.194.180.0 mask 255.255.255.0 nomodify notrap

server cn.pool.ntp.org #ntp官网的中国区
server ntp1.aliyun.com #阿里
server time1.cloud.tencent.com #腾讯
server time.edu.cn #教育科研机构
server cn.ntp.org.cn #国家授时
server ntp.ntsc.ac.cn #中国国家授时中心

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

设置同步独立主机的硬件时钟
vim /etc/sysconfig/ntpd

1
SYNC_HWCLOCK=yes 

配置开机启动ntp服务,定期同步时间
service ntpd start
修改服务的默认启动等级
chkconfig --levels 235 ntpd on
启动ntp同步
/etc/init.d/ntpd start

配置局域网内服务器

配置时间同步
vim /etc/ntp.conf

1
2
3
4
5
6
7
8
9
10
driftfile /var/lib/ntp/drift

restrict 127.0.0.1
restrict -6 ::1

restrict 10.194.180.71 nomodify
server 10.194.180.71 prefer

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

启动ntpd服务
service ntpd start
加入开机启动项
chkconfig ntpd on/etc/init.d/ntpd start

最后检查一下是否同步成功

大功告成

本文作者 : zhouinfo
原文链接 : http://blog.zhouinfo.site/2019/06/21/Linux%E6%97%B6%E9%97%B4%E5%90%8C%E6%AD%A5/
版权声明 : 本博客所有文章除特别声明外,均采用 CC Apache License 2.0 许可协议。转载请注明出处!
留下足迹