Vmware中虚拟机设置NTP服务时间同步

实验状况:虚拟机中的一台Centos7系统想要连接内部网络NTP服务器(IP:192.168.100.100),但其本身不能连接互联网。

一、更改yum源从本地硬盘

打开VMware中“虚拟机M选择设置”,再选择“CD/DVD(IDE)”,选择“使用ISO映像文件(M)”,选择合适的系统版本。

二、挂载光盘

光盘放好后挂载光盘

先新建挂载点:# mkdir -p  /mnt/cdrom,然后再重新进行挂载。

mount /dev/cdrom  /mnt/cdrom

或者 mount /dev/sr0  /mnt/cdrom

三、修改yum源(临时更改

[root@localhost ~]# cd /etc/yum.repos.d/

[root@svr_share_02 yum.repos.d]# vi CentOS-Base.repo

# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client.  You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

#

#

[base]

name=CentOS-$releasever - Base

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra

baseurl=file:///mnt/cdrom    #设置路径

gpgcheck=0                       #表示对从这个源下载的rpm包不进行校验

enable=1                           #表示启用这个源

最后 wq! 保存退出。

四、安装NTP

1、查看/etc/yum.repo.d列表里面已经安装和可以安装的程序包

[root@localhost ~]# yum list 

若发现出现如下报错。基本的原因就是自己的网络设置问题,解决好就正常了。

若发现自己的网络问题已正常,使用yum list 还是报如下错误:

可以先查看自己之前挂载的情况:

发现自己的挂载没有了,需要重新再挂载。

这时候再使用[root@localhost ~]# yum list 查看,就会发现已正常。

2、安装NTP

[root@localhost ~]# yum install ntp

 

四、修改配置文件

[root@localhost ~]#  vi /etc/ntp.conf

# For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

restrict default nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

restrict 127.0.0.1

restrict ::1

# Hosts on local network are less restricted.

#restrict 192.168.1.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 192.168.100.100   增加的NTP服务器地址

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

#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

# Enable public key cryptography.

#crypto

includefile /etc/ntp/crypto/pw

五、设置NTP服务

[root@localhost ~]# systemctl restart ntpd.service      #重启NTP服务

[root@localhost ~]# systemctl status ntpd.service       #查看NTP服务状态

● ntpd.service - Network Time Service

   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)

   Active: active (running) since 一 2018-07-30 13:15:15 CST; 52s ago

  Process: 34667 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)

 Main PID: 34668 (ntpd)

   CGroup: /system.slice/ntpd.service

           ├─34668 /usr/sbin/ntpd -u ntp:ntp -g

           └─34669 /usr/sbin/ntpd -u ntp:ntp -g

可以看到当前的状态为 running

六、查看是否成功

[root@localhost ~]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

 192.168.100.100     .GPS.            1 u    1   64    7    7.840  240671.   3.119

七、设置开机自启动

[root@localhost ~]# systemctl enable  ntpd.service

Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Linux虚拟机时间同步可以通过以下几种方式实现: 1. 使用NTP服务同步时间:NTP(Network Time Protocol)是一种用于同步计算机时间的协议,可以通过配置NTP服务器来同步虚拟机时间。在Linux系统,可以使用ntpdate命令手动同步时间,也可以通过配置ntp.conf文件来自动同步时间。 2. 使用VMware Tools同步时间:VMware Tools是一种虚拟机增强工具,可以提供虚拟机与宿主机之间的时间同步功能。在安装VMware Tools后,可以通过配置vmware-toolbox-cmd命令来启用时间同步功能。 3. 手动设置时间:如果以上两种方法无法实现时间同步,可以手动设置虚拟机时间。在Linux系统,可以使用date命令手动设置时间。 总之,为了保证虚拟机时间的准确性,建议使用NTP服务VMware Tools进行时间同步。 ### 回答2: Linux虚拟机时间同步是指在Linux虚拟机上进行时间同步的过程。在一些环境下,不同虚拟机之间的时间差异可能会产生一些问题,因此需要对Linux虚拟机的时间进行同步。本文将介绍几种常见的时间同步方法。 1. NTP同步 NTP是网络时间协议,可用于在多个服务器之间同步时间。在Linux虚拟机上使用NTP同步时间需要先在虚拟机上安装ntp服务。在ubuntu系统上可以使用命令 sudo apt-get install ntp 安装。安装完成后可用命令 systemctl status ntp.service 查看服务是否已启动。如果未启动则使用命令 systemctl start ntp.service 启动即可。NTP同步主要使用的是UDP协议,通过和NTP服务器通信来同步时间。 2. VMware Tools时钟同步 VMware Tools是VMware公司开发的一款虚拟化软件,包括了一些虚拟机操作系统的工具,其包括时钟同步。使用VMware Tools时钟同步,需要先在虚拟机安装VMware Tools。在安装完成后,在VMware虚拟机设置启用时间同步功能即可,使得虚拟机能够自动同步主机的时间。VMware Tools时钟同步可以帮助保持虚拟机和主机时间同步。 3. 使用chrony同步 chrony是一个时间同步工具,能够在本地机器和远程服务器之间进行时间同步。使用chrony能够利用网络延迟来自动计算时钟偏移,并进行调整。使用chrony同步时间需要先在虚拟机安装chrony服务,并通过配置文件指定要使用的外部NTP服务器地址。在Ubuntu系统上,可以使用命令 sudo apt-get install chrony 安装,并在编辑配置文件 /etc/chrony/chrony.conf 设置server指令来配置NTP服务器地址。 总之,对于不同的应用场景,需要采用不同的时间同步方法。NTP同步是一种常用且全球通用的时间同步方法,VMware Tools时钟同步适用于在VMware虚拟机上进行时间同步。而chrony同步则采用类似于NTP的方式来进行时间同步。无论是哪种时间同步方法,都应根据实际需要进行选择。 ### 回答3: 在使用Linux虚拟机的过程时间同步是一个非常重要的功能,它可以确保虚拟机与物理主机之间的时间同步,从而避免出现一些奇怪的问题。 在Linux虚拟机时间同步可以通过两种方式实现:一是使用NTP服务进行时间同步;二是使用VMware Tools时间同步功能。 使用NTP服务进行时间同步,首先需要安装一个NTP服务。在Debian/Ubuntu发行版,可以使用以下命令来安装NTP服务: sudo apt-get update sudo apt-get install ntp 在安装完NTP之后,需要进行一些配置。需要修改/etc/ntp.conf文件,如下所示: # Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for # more information. pool 0.ubuntu.pool.ntp.org iburst pool 1.ubuntu.pool.ntp.org iburst pool 2.ubuntu.pool.ntp.org iburst pool 3.ubuntu.pool.ntp.org iburst 在这里,我们使用的是Ubuntu的默认NTP服务器,当然也可以使用其他的NTP服务器。 修改完配置文件之后,需要重启NTP服务: sudo service ntp restart 这样,Linux虚拟机就可以使用NTP服务进行时间同步了。 另外一种方式是使用VMware Tools时间同步功能。这种方式比较简单,只需要在VMware Tools选择“Synchronize guest time with host”选项即可。这样,在虚拟机和物理主机之间同步时间时,VMware会自动进行时间同步。 总的来说,无论使用哪种方法进行时间同步,都可以保证Linux虚拟机与物理主机之间时间同步,避免出现一些奇怪的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值