linux虛擬機Virtual Machine Manager

1、虛擬機安裝

1.啓動虛擬加管理器

[root@foundation29 ~]# 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

虛擬機建立完成linux

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

虛擬機安裝完成vim

2、封裝虛擬機鏡像

1.虛擬機鏡像

使用RHEL中的Virtual Machine Manager建立的虛擬機會生成後綴爲.qcow2的虛擬機鏡像文件
Virtual Machine Manager支持從.qcow2的虛擬機鏡像文件建立虛擬機,這樣咱們就能夠經過管理鏡像,從而很方便的建立與管理linux虛擬機。bash

#####2.配置虛擬機
須要使用剛纔安裝的虛擬機封裝一個虛擬機母鏡像,因此咱們來配置這個虛擬機,方便之後的使用
開啓虛擬機,使用root身份登入系統,進行對應的配置,而後關機(注意要關機而不是重啓)
個人配置有:
1.修改主機名:網絡

[root@server1 ~]# hostname server1
 [root@server1 ~]# vi /etc/sysconfig/network
 NETWORKING=yes
 HOSTNAME=server1

2.關閉防火牆dom

[root@server1 ~]# chkconfig iptables off

3.關閉selinuxssh

[root@server1 ~]# vi /etc/selinux/config 
 ...
 SELINUX=disabled
 ...

4.配置網絡ide

[root@server1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 
 DEVICE="eth0"
 BOOTPROTO="dhcp"
 ONBOOT="yes"
 IPADDR=172.25.29.1
 PREFIX=24
 [root@server1 ~]# cd /etc/udev/rules.d/
 [root@server1 rules.d]# ls
 60-raw.rules  70-persistent-net.rules
 [root@server1 rules.d]# rm -f 70-persistent-net.rules 
 [root@server1 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.主機名解析oop

[root@server1 ~]# 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源ui

[root@server1 ~]# 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.安裝經常使用軟件及服務url

[root@server1 ~]# 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
 [root@server1 ~]# yum install -y vim man lftp
 ...

8.關機

[root@server1 ~]# poweroff

3.使用qcow2文件建立虛擬機

1.初始化域

[root@foundation29 ~]# cd /var/lib/libvirt/images/
 [root@foundation29 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的虛擬機

[root@foundation29 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
 [root@foundation29 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
 [root@foundation29 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,server34.server1,server2,server3設置開機並設置好eth0,hostname

相關文章
相關標籤/搜索