首先祝愿大家在2021年事业顺利,开开心心,我是杆枪,指哪打哪,公司搞的vSphere,虚拟的服务器时间总是会出现时间上的差异,为了解决这个问题,才用到了ntp服务,这篇文章比较适用于linux新手的(因为我就是从新手过来的),ok,下面进入正题
先说下的个人理解ntp时间同步的思路,其实很简单,就是一边为服务端,保证服务端时间正确,终端定时同步时间就可以了
因为我是在服务器里装的虚拟机,虚拟机时间和是物理服务器时间同步的,所以只需要终端同步服务端的时间就行了 | |
---|---|
1. 查看终端服务器是否安装ntp,系统默认安装ntpdate,如果没安装安装下来
rpm -qa | grep ntp
2.修改配置文件(安装好的ntp默认路径)
vim /etc/ntp.conf
把如下四行代码注释掉
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
配置上游时间服务器为本地的ntpd Server服务器
server 服务端ip
配置允许上游时间服务器主动修改本机的时间
restrict 终端ip nomodify notrap noquery
3.与本地ntpd Server同步一下(测试下有没有成功)
ntpdate -u 服务端ip
4.启动ntp服务
systemctl start ntpd
重启命令:
systemctl restart ntpd
设置开机启动
systemctl enable ntpd
查看服务是否启动命令为:
service ntpd status
5.查看同步状态
ntpq -p