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
interface listen <本机IP>
ntpdate -u cn.pool.ntp.org

启动 service ntpd start

开机启动 chkconfig ntpd on

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值