Vmware中虚拟机设置NTP服务时间同步 | 您所在的位置:网站首页 › 在vmware虚拟机中运行虚拟机的命令是什么 › 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. |
CopyRight 2018-2019 实验室设备网 版权所有 |