NTP简介
网络时间协议(英语:Network Time Protocol,缩写:NTP)是在数据网络潜伏时间可变的计算机系统之间通过分组交换进行时钟同步的一个网络协议,位于OSI模型的应用层。
NTP的作用
NTP的作用是为了所有参与计算机的协调世界时(UTC)时间同步到几毫秒的误差内。
CentOS基于NTP的时间同步
- 安装ntp:
sudo yum -y install ntp
- 修改/etc/ntp.conf
Use public servers from the pool.ntp.org project.
Please consider joining the pool (http://www.pool.ntp.org/join.html)
# new(新增)
server ntp1.aliyun.com prefer
server ntp2.aliyun.com
# old(原有) server 0.centos.pool.ntp.org iburst server
# centos.pool.ntp.org iburst server
# centos.pool.ntp.org iburst server
# centos.pool.ntp.org iburst
- 设置时区
sudo timedatectl set-timezone Asia/Shanghai
# 或者 sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- 时间同步 手工发起同步:
sudo ntpdate ntp1.aliyun.com
查看时间是否有变更
- 启动NTP服务:
sudo systemctl enable ntpd.service sudo systemctl start ntpd.service