linux虛擬機Virtual Machine Manager
阿新 • • 發佈:2018-04-18
虛擬機一、虛擬機安裝
開啟虛擬機,使用root身份登入系統,進行對應的配置,然後關機(註意要關機而不是重啟)
我的配置有:
1.修改主機名:
1.啟動虛擬加管理器
[root@foundation29 ~]# virt-manager
2.新建一個虛擬機
- 點擊左上角File—>New Virtual Machine,選擇Local install media ( ISO image or CDROM ),點擊Forward
- 選擇Use ISO image,點擊Browse從本地選擇一個OS鏡像,我選擇的是rhel-server-6.5-x86_64-dvd.iso,點擊Forward
- Memory ( RAM ) 填寫512MB,這樣可以最小化(無GUI)安裝,CPUs默認分配一顆核心即可,點擊Forward
- 填寫20GiB作為虛擬機磁盤空間,點擊Forward
- Name填寫rhel-6.5-server,點擊Finish
虛擬機創建完成
3.安裝OS鏡像至虛擬機
- 點擊Begin Installation,回車開始安裝
- 空格鍵選擇OK
- 空格鍵選擇Test
- 等待Test完成,空格鍵選擇OK,然後再選擇OK
- Tab鍵選擇Continue,空格鍵確認
- 空格鍵選擇OK
- 默認English,Tab鍵選擇OK,空格鍵確認
- 默認us,Tab鍵選擇OK,空格鍵確認
- Tab鍵選擇Re-initialize all,全部格式化,空格鍵確認
- Tab鍵選擇Asia/Shanghai,Tab鍵選擇OK,空格鍵確認
- 輸入root密碼並確認密碼,完成後Tab選擇OK,空格鍵確認(如果輸入的密碼比較簡單,會提示密碼強度較弱,選擇Use Anyway即可生效)
- 默認Replace existing Linux system,Tab鍵選擇OK,空格鍵確認
- Tab鍵選擇Write changes to disk,空格鍵確認
- 等待安裝完成,空格鍵選擇Reboot
虛擬機安裝完成
二、封裝虛擬機鏡像
1.虛擬機鏡像
使用RHEL中的Virtual Machine Manager創建的虛擬機會生成後綴為.qcow2的虛擬機鏡像文件
Virtual Machine Manager支持從.qcow2的虛擬機鏡像文件創建虛擬機,這樣我們就可以通過管理鏡像,從而很方便的創建與管理linux虛擬機。
#####2.配置虛擬機
需要使用剛才安裝的虛擬機封裝一個虛擬機母鏡像,所以我們來配置這個虛擬機,方便以後的使用
我的配置有:
1.修改主機名:
[root@server1 ~]# hostname server1
[root@server1 ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=server1
2.關閉防火墻
[root@server1 ~]# chkconfig iptables off
3.關閉selinux
[root@server1 ~]# vi /etc/selinux/config
...
SELINUX=disabled
...
4.配置網絡
[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.主機名解析
[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源
[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.安裝常用軟件及服務
[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文件創建的虛擬機同時工作導致錯誤
刪除過程:
- 打開Virtual Machine Manager
- 在rhel-6.5-server上右鍵並選中Delete
- 取消勾選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.創建虛擬機
- 點擊左上角File—>New Virtual Machine,選擇Import existing disk image,點擊Forward
- 點擊Browse,點擊左上角default,選擇剛才創建的server1,點擊Choose Volume,OS tyoe選擇Linux,Version選擇對應的RHEL6.5,點擊Forward
- Memory ( RAM ) 和CPUs根據需求分配,一般Memory ( RAM ) 分配512MiB或1024MiB,CPUs分配一顆核心即可,點擊Forward
- Name填寫server1,點擊Finish
server1創建完成,同上可以創建server2,server3
4.server1,server2,server3設置
開機並設置好eth0,hostname
linux虛擬機Virtual Machine Manager