Linux教程

linux同步网络时间

本文主要是介绍linux同步网络时间,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

先改个时区

先查看一下     ll /etc/localtime

centos6

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

centos7

最简单的方法是创建软连接

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

也可以用下面的方法

# timedatectl list-timezones |grep Shanghai    #查找中国时区的完整名称
Asia/Shanghai
# timedatectl set-timezone Asia/Shanghai    #其他时区以此类推

安装ntp

yum install ntp -y

vi /etc/ntp.conf

# 处理权限问题
restrict 127.0.0.1      #这两个是默认值,放行本机来源
restrict -6 ::1

restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap  # 放行局域网来源

# 设置主机来源,请将原来的[0|1|2|3].centos.pool.ntp.org设置注释掉
restrict cn.pool.ntp.org        # 放行cn.pool.ntp.org进入本ntp服务器
server cn.pool.ntp.org prefer   # 以这台主机为优先
server ntp.sjtu.edu.cn
nterface listen <本机IP>
ntpdate -u cn.pool.ntp.org

启动 service ntpd start

开机启动 chkconfig ntpd on

用ntpstat查看同步状态,一般要等几分钟才能同步过来

这篇关于linux同步网络时间的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!