您的位置:首页 > 运维架构 > Linux

linux使用ntp来设置时间同步

2018-01-23 13:27 666 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: