exsi主机和虚拟主机时间老是不同步

[复制链接]
ruzhuo 发表于 2024-8-1 20:56:08 | 显示全部楼层 |阅读模式
exsi主机和虚拟主机时间老是不同步


1 虚拟机时间快8个小时的原因
ESXI 主机在有些场合是不连接互联网的,所以也就无法做到与互联网NTP服务器的时间同步,只能手动设置时间。在手动设置时间的过程中,ESXI主机没有时区的概念,只有一个UTC时间,但用户往往错把这个时间设置为此刻的本地时间。所以虚拟机在启动的过程中,往往会自动同步esxi主机的时间,并把虚拟机的UTC时间同步为ESXI的时间,加之虚拟机设置了时区,所有虚拟机本机时间就会加上8个小时,这就是内在的原因。


虚拟机没有自己的BIOS时钟,开机时只能靠ESXI主机的时间来同步。


2 关于ESXI主机的时间和日期
ESXI 没有时区的概念,只有一个UTC时间.
在ESXI 中可以设定ntp服务器,来自动调整 esxi主机的utc时间.
在ESXI主机中创建的虚拟机,每当虚拟机重新启动时,都会同步ESXI 主机的时间.
如果虚拟机可以联网,也可以单独设置虚拟机的NTP时间同步。
二 虚拟机中安装与配置时间同步服务 chrony
# 安装 chrony
yum install chrony ntpdate
# 启动chrony
systemctl start chronyd
# 设置开机启动
systemctl enable chronyd


三 配置本机自动与互联网时间服务器同步
yum 安装的 chrony的配置文件
rpm -ql chrony
1.
chrony 初始配置
vim /etc/chrony.conf


# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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


# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift


# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3


# Enable kernel synchronization of the real-time clock (RTC).
rtcsync


# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *


# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2


# Allow NTP client access from local network.
#allow 192.168.0.0/16


# Serve time even if not synchronized to a time source.
#local stratum 10


# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys


# Specify directory for log files.
logdir /var/log/chrony




一般把公共NTP服务器设置为国内源
vim /etc/chrony.conf


# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).


# 国家授时中心NTP服务器
pool  ntp.ntsc.ac.cn  iburst
# 阿里云时间源
pool  ntp.aliyun.com   iburst
# 腾讯云源
pool  ntp.tencent.com  iburst
# 上海交通大学
pool  ntp.sjtu.edu.cn  iburst


#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


# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift


# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3


# Enable kernel synchronization of the real-time clock (RTC).
rtcsync


# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *


# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2


# Allow NTP client access from local network.
#allow 192.168.0.0/16


# Serve time even if not synchronized to a time source.
#local stratum 10


# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys


# Specify directory for log files.
logdir /var/log/chrony


# Select which information is logged.
#log measurements statistics tracking




四 把本机作为时间服务器对外提供时间服务
保证本机与其他主机之间的网络畅通
仅需修改 chrony.conf 的 少量参数
vim /etc/chrony.conf
.......
# 设置允许 10.31.0.0 这个网段的机器作为客户端来本机同步时间
# Allow NTP client access from local network.
allow 10.31.0.0/16


# Serve time even if not synchronized to a time source.
local stratum 10


重新启动 chronyd 服务
systemctl  restart chronyd
1.
把NTP服务加入防火墙
[root@wyf-test ~]# firewall-cmd  --permanent --add-service=ntp
[root@wyf-test ~]# firewall-cmd  --reload
[root@wyf-test ~]# firewall-cmd  --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources:
  services: dhcpv6-client ntp ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

如何使用自建的NTP服务器
#1 安装 chrony服务,修改 chrony.conf
...
# 把server 设置为已搭建的NTP服务器的IP
...
# 启动 chronyd 服务


#也可以随时手动同步时间
ntpdate IP(自己大劫案的NTP服务器的IP)

icmp-blocks:
rich rules:




几个常用的NTP服务器时间同步列表
Windows系统上自带的两个:time.windows.com 和 time.nist.gov
MacOS上自带的两个:time.apple.com 和 time.asia.apple.com
NTP授时快速域名服务:cn.ntp.org.cn
中国科学院国家授时中心:ntp.ntsc.ac.cn
开源NTP服务器:cn.pool.ntp.org
阿里云时间源:ntp.aliyun.com
腾讯云源:ntp.tencent.com
上海交通大学:ntp.sjtu.edu.cn

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|RuZhuo ( 鄂ICP备16015978号-8 )

GMT+8, 2024-9-17 03:33 , Processed in 0.023623 second(s), 27 queries .

Powered by RuZhuo

快速回复 返回顶部 返回列表