linux虚拟机Virtual Machine Manager

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux虚拟机Virtual Machine Manager相关的知识,希望对你有一定的参考价值。

一、虚拟机安装

1.启动虚拟加管理器

 [[email protected] ~]# virt-manager 

2.新建一个虚拟机

  1. 点击左上角File—>New Virtual Machine,选择Local install media ( ISO image or CDROM ),点击Forward
  2. 选择Use ISO image,点击Browse从本地选择一个OS镜像,我选择的是rhel-server-6.5-x86_64-dvd.iso,点击Forward
  3. Memory ( RAM ) 填写512MB,这样可以最小化(无GUI)安装,CPUs默认分配一颗核心即可,点击Forward
  4. 填写20GiB作为虚拟机磁盘空间,点击Forward
  5. Name填写rhel-6.5-server,点击Finish

虚拟机创建完成

3.安装OS镜像至虚拟机

  1. 点击Begin Installation,回车开始安装
  2. 空格键选择OK
  3. 空格键选择Test
  4. 等待Test完成,空格键选择OK,然后再选择OK
  5. Tab键选择Continue,空格键确认
  6. 空格键选择OK
  7. 默认English,Tab键选择OK,空格键确认
  8. 默认us,Tab键选择OK,空格键确认
  9. Tab键选择Re-initialize all,全部格式化,空格键确认
  10. Tab键选择Asia/Shanghai,Tab键选择OK,空格键确认
  11. 输入root密码并确认密码,完成后Tab选择OK,空格键确认(如果输入的密码比较简单,会提示密码强度较弱,选择Use Anyway即可生效)
  12. 默认Replace existing Linux system,Tab键选择OK,空格键确认
  13. Tab键选择Write changes to disk,空格键确认
  14. 等待安装完成,空格键选择Reboot

虚拟机安装完成

二、封装虚拟机镜像

1.虚拟机镜像

使用RHEL中的Virtual Machine Manager创建的虚拟机会生成后缀为.qcow2的虚拟机镜像文件
Virtual Machine Manager支持从.qcow2的虚拟机镜像文件创建虚拟机,这样我们就可以通过管理镜像,从而很方便的创建与管理linux虚拟机。

#####2.配置虚拟机
需要使用刚才安装的虚拟机封装一个虚拟机母镜像,所以我们来配置这个虚拟机,方便以后的使用
开启虚拟机,使用root身份登入系统,进行对应的配置,然后关机(注意要关机而不是重启)
我的配置有:
1.修改主机名:

 [[email protected] ~]# hostname server1
 [[email protected] ~]# vi /etc/sysconfig/network
 NETWORKING=yes
 HOSTNAME=server1

2.关闭防火墙

 [[email protected] ~]# chkconfig iptables off

3.关闭selinux

 [[email protected] ~]# vi /etc/selinux/config 
 ...
 SELINUX=disabled
 ...

4.配置网络

 [[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 
 DEVICE="eth0"
 BOOTPROTO="dhcp"
 ONBOOT="yes"
 IPADDR=172.25.29.1
 PREFIX=24
 [[email protected] ~]# cd /etc/udev/rules.d/
 [[email protected] rules.d]# ls
 60-raw.rules  70-persistent-net.rules
 [[email protected] rules.d]# rm -f 70-persistent-net.rules 
 [[email protected] rules.d]# /etc/init.d/network restart
 Shutting down interface eth0:                              [  OK  ]
 Shutting down loopback interface:                          [  OK  ]
 Bringing up loopback interface:                            [  OK  ]
 Bringing up interface eth0:  Determining if ip address 172.25.29.1 is already in use for device eth0...
                                                            [  OK  ]

5.主机名解析

 [[email protected] ~]# vi /etc/hosts
 127.0.0.1   localhost localhost.localdomain localhost4  localhost4.localdomain4
 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 172.25.29.1 server1
 172.25.29.2 server2
 172.25.29.3 server3
 172.25.29.4 server4
 172.25.29.5 server5
 172.25.29.6 server6

6.配置yum源

 [[email protected] ~]# vi /etc/yum.repos.d/rhel-source.repo 
 [rhel-dvd]
 name=rhel6.5-dvd
 baseurl=http://172.25.29.250/rhel6.5
 gpgcheck=0

 [HighAvailability]
 name=HighAvailability
 baseurl=http://172.25.29.250/rhel6.5/HighAvailability
 gpgcheck=0

 [LoadBalancer]
 name=LoadBalancer
 baseurl=http://172.25.29.250/rhel6.5/LoadBalancer
 gpgcheck=0

 [ResilientStorage]
 name=ResilientStorage
 baseurl=http://172.25.29.250/rhel6.5/ResilientStorage
 gpgcheck=0

 [ScalableFileSystem]
 name=ScalableFileSystem
 baseurl=http://172.25.29.250/rhel6.5/ScalableFileSystem
 gpgcheck=0

7.安装常用软件及服务

 [[email protected] ~]# yum clean all
 Loaded plugins: product-id, subscription-manager
 This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
 Cleaning repos: HighAvailability LoadBalancer ResilientStorage
               : ScalableFileSystem rhel-dvd
 Cleaning up Everything
 [[email protected] ~]# yum install -y vim man lftp
 ...

8.关机

 [[email protected] ~]# poweroff

3.使用qcow2文件创建虚拟机

1.初始化域

 [[email protected] ~]# cd /var/lib/libvirt/images/
 [[email protected] images]# virt-sysprep -d rhel-6.5-server
 [   0.0] Examining the guest ...
 [  69.0] Performing "abrt-data" ...
 [  69.0] Performing "bash-history" ...
 [  69.0] Performing "blkid-tab" ...
 [  69.0] Performing "crash-data" ...
 [  69.0] Performing "cron-spool" ...
 [  69.0] Performing "dhcp-client-state" ...
 [  69.0] Performing "dhcp-server-state" ...
 [  69.0] Performing "dovecot-data" ...
 [  69.0] Performing "logfiles" ...
 [  69.0] Performing "machine-id" ...
 [  69.0] Performing "mail-spool" ...
 [  69.0] Performing "net-hostname" ...
 [  69.0] Performing "net-hwaddr" ...
 [  69.0] Performing "pacct-log" ...
 [  69.0] Performing "package-manager-cache" ...
 [  69.0] Performing "pam-data" ...
 [  69.0] Performing "puppet-data-log" ...
 [  69.0] Performing "rh-subscription-manager" ...
 [  69.0] Performing "rhn-systemid" ...
 [  69.0] Performing "rpm-db" ...
 [  69.0] Performing "samba-db-log" ...
 [  69.0] Performing "script" ...
 [  69.0] Performing "smolt-uuid" ...
 [  69.0] Performing "ssh-hostkeys" ...
 [  69.0] Performing "ssh-userdir" ...
 [  69.0] Performing "sssd-db-log" ...
 [  69.0] Performing "tmp-files" ...
 [  69.0] Performing "udev-persistent-net" ...
 [  69.0] Performing "utmp" ...
 [  69.0] Performing "yum-uuid" ...
 [  69.0] Performing "customize" ...
 [  69.0] Setting a random seed
 [  69.0] Performing "lvm-uuids" ...

2.创建虚拟机image
首先删除原虚拟机并且保留qcow2镜像,其原因是为了避免母镜像(即原虚拟机rhel-6.5-server)与使用该qcow2文件创建的虚拟机同时工作导致错误
删除过程:

  1. 打开Virtual Machine Manager
  2. 在rhel-6.5-server上右键并选中Delete
  3. 取消勾选Delete associated storage files,然后单击Delete删除

创建基于rhel-6.5-server.qcow2的虚拟机

 [[email protected] images]# qemu-img create -f qcow2 -b rhel-6.5-server.qcow2 server1
 Formatting ‘server1‘, fmt=qcow2 size=21474836480 backing_file=‘rhel-6.5-server.qcow2‘ encryption=off cluster_size=65536 lazy_refcounts=off
 [[email protected] images]# qemu-img create -f qcow2 -b rhel-6.5-server.qcow2 server2
 Formatting ‘server2‘, fmt=qcow2 size=21474836480 backing_file=‘rhel-6.5-server.qcow2‘ encryption=off cluster_size=65536 lazy_refcounts=off
 [[email protected] images]# qemu-img create -f qcow2 -b rhel-6.5-server.qcow2 server3
 Formatting ‘server3‘, fmt=qcow2 size=21474836480 backing_file=‘rhel-6.5-server.qcow2‘ encryption=off cluster_size=65536 lazy_refcounts=off

3.创建虚拟机

  1. 点击左上角File—>New Virtual Machine,选择Import existing disk image,点击Forward
  2. 点击Browse,点击左上角default,选择刚才创建的server1,点击Choose Volume,OS tyoe选择Linux,Version选择对应的RHEL6.5,点击Forward
  3. Memory ( RAM ) 和CPUs根据需求分配,一般Memory ( RAM ) 分配512MiB或1024MiB,CPUs分配一颗核心即可,点击Forward
  4. Name填写server1,点击Finish

server1创建完成,同上可以创建server2,server3
4.server1,server2,server3设置
开机并设置好eth0,hostname

以上是关于linux虚拟机Virtual Machine Manager的主要内容,如果未能解决你的问题,请参考以下文章

Windows Azure Virtual Machine (34) 保护Azure虚拟机

ChatGPT在 ChatGPT 中构建 Linux 虚拟机 Building A Virtual Machine inside ChatGPT

kvm -- Kernel-based Virtual Machine

使用 Virtual Machine Manager 管理虚拟机

eclipse启动时报错 Could not create the java virtual machine

JAVA虚拟机栈(Java Virtual Machine Stacks)抛出StackOverflowError和OutOfMemoryError的异常的示例