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