linux使用ntp来设置时间同步

1.安装ntp

$   yum install ntp

如果是ubtuntu:

$   apt-get install ntp

(如果安装不了去设置切换一下下载地址,我选择的是阿里的镜像)

2.查看下时间格式是不是cst,通过date

$   date

如果不是设置下:

$   mv /etc/localtime /etc/localtime.bak

$   ln -s /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

3.先更新下时间把

$   ntpdate 208.91.112.50

4.修改下ntp的配置文件

$  vi /etc/ntp.conf

# Hosts on local network are less restricted.
# 允许内网中其他机器同步时间
restrict 192.168.0.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 210.72.145.44 perfer      # 中国国家受时中心
server 202.112.10.36             # 1.cn.pool.ntp.org
server 59.124.196.83             # 0.asia.pool.ntp.org

#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

# allow update time by the upper server 
# 允许上层时间服务器主动修改本机时间
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery

4.复制替换

5.启动服务

$ sudo service ntp start

6.查看启动的服务端口以及同步时间的服务地址

$ sudo netstat -tlunp | grep ntp

$ ntpq -p


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值