CentOS7 安装管理KVM虚拟机
CentOS7 安装管理KVM虚拟机
雁南飞丶 发表于3年前
CentOS7 安装管理KVM虚拟机
  • 发表于 3年前
  • 阅读 256
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

系统:CentOS7 64位

[root@e3 ~]# cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core)

安装KVM

IBM对kvm的介绍https://www.ibm.com/search/csass/search/?q=kvm&sn=dw&lang=zh&cc=CN&en=utf&hpp=20&dws=cndw&lo=zh

 yum install qemu-kvm libvirt virt-install bridge-utils
  lsmod |grep kvm
kvm_intel             138567  0 
kvm                   441119  1 kvm_intel
[root@e3 ~]#systemctl start libvirtd #启动  libvirtd
[root@e3 ~]# systemctl enable libvirtd #开机自启动

libvirtd详解看这位博友的文章http://blog.csdn.net/gaoxingnengjisuan/article/details/9674315

配置KVM虚拟机桥接网络

[root@e3 ~]# nmcli c add type bridge autoconnect yes con-name br0 ifname br0  #添加虚拟桥接网卡br0
[root@e3 ~]# nmcli c modify br0 ipv4.addresses "192.168.0.244/24 192.168.0.1" ipv4.method manual #设置虚拟网卡ip和网关
[root@e3 ~]# nmcli c modify br0 ipv4.dns 192.168.0.1 #设置DNS 192.168.0.1
[root@e3 ~]# nmcli c delete enp3s0 #删除当前网络配置  enp3s0 是我的网路标示,在CentOS 6是eth0
[root@e3 ~]# nmcli c add type bridge-slave autoconnect yes con-name enp3s0 ifname enp3s0 master br0 #添加br0接口
[root@e3 ~]#  systemctl stop NetworkManager; systemctl start NetworkManager #停止网络和启动网络
##nmcli是一个网络管理工具
[root@e3 ~]# which nmcli 
/usr/bin/nmcli
[root@e3 ~]# rpm -qf /usr/bin/nmcli 
NetworkManager-0.9.9.1-29.git20140326.4dba720.el7_0.x86_64
#ip addr
[root@e3 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
    link/ether e0:3f:49:13:0a:7e brd ff:ff:ff:ff:ff:ff
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff
    inet 172.17.42.1/16 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::5484:7aff:fefe:9799/64 scope link 
       valid_lft forever preferred_lft forever
5: vethde86ccb: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master docker0 state UP qlen 1000
    link/ether ca:ba:76:4e:c1:92 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::c8ba:76ff:fe4e:c192/64 scope link 
       valid_lft forever preferred_lft forever
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether e0:3f:49:13:0a:7e brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.244/24 brd 192.168.0.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::e23f:49ff:fe13:a7e/64 scope link 
       valid_lft forever preferred_lft forever

OK至此kvm安装完毕下来看看如何安装第一台guset虚拟机

构建安装源,

[root@e3 ~]# yum install vsftpd #安装ftp
[root@e3 ~]# systemctl start vsftpd #启动ftp
 [root@e3 ~]# systemctl enable vsftpd  #开机自启动
[root@e3 tmp]#wget http://mirrors.sohu.com/centos/6/isos/x86_64/CentOS-6.6-x86_64-minimal.iso  #下载Centos6.6 MINI安装盘
[root@e3 tmp]# mkdir /mnt/cdrom/
[root@e3 tmp]# mount CentOS-6.6-x86_64-minimal.iso /mnt/cdrom/ #挂载
[root@e3 tmp]# cp -r /mnt/cdrom /var/ftp/ 
[root@e3 tmp]# cd /root/centos/cdrom/
[root@e3 cdrom]# vim .treeinfo
#修改如下
[general]
family = CentOS
timestamp = 1414159790.06
variant =
totaldiscs = 1
version = 6.6
discnum = 1
packagedir =
arch = x86_64

[images-x86_64]
kernel = isolinux/vmlinuz  ##主要是修改这
initrd = isolinux/initrd.img ##主要修改这

[images-xen]

initrd = images/pxeboot/initrd.img

[stage2]
mainimage = images/install.img

#完了保存的时候强制保存 :wq!
然后重启你的vftpd。
测试:看能不能访问


下来创建guset虚拟机

使用virt-install创建虚拟机并安装GuestOS

virt-install是一个命令行工具,它能够为KVM、Xen或其它支持libvrit API的hypervisor创建虚拟机并完成GuestOS安装;此外,它能够基于串行控制台、VNC或SDL支持文本或图形安装界面。安装过程可以使用本地的安装介质如CDROM,也可以通过网络方式如NFS、HTTP或FTP服务实现。对于通过网络安装的方式,virt-install可以自动加载必要的文件以启动安装过程而无须额外提供引导工具。当然,virt-install也支持PXE方式的安装过程,也能够直接使用现有的磁盘映像直接启动安装过程。
virt-install命令有许多选项,这些选项大体可分为下面几大类,同时对每类中的常用选项也做出简单说明。
◇    一般选项:指定虚拟机的名称、内存大小、VCPU个数及特性等;
    -n NAME, --name=NAME:虚拟机名称,需全局惟一;
    -r MEMORY, --ram=MEMORY:虚拟机内在大小,单位为MB;
    --vcpus=VCPUS[,maxvcpus=MAX][,sockets=#][,cores=#][,threads=#]:VCPU个数及相关配置;
    --cpu=CPU:CPU模式及特性,如coreduo等;可以使用qemu-kvm -cpu ?来获取支持的CPU模式;
◇    安装方法:指定安装方法、GuestOS类型等;
    -c CDROM, --cdrom=CDROM:光盘安装介质;
    -l LOCATION, --location=LOCATION:安装源URL,支持FTP、HTTP及NFS等,如ftp://172.16.0.1/pub;
    --pxe:基于PXE完成安装;
    --livecd: 把光盘当作LiveCD;
    --os-type=DISTRO_TYPE:操作系统类型,如linux、unix或windows等;
    --os-variant=DISTRO_VARIANT:某类型操作系统的变体,如rhel5、fedora8等;
    -x EXTRA, --extra-args=EXTRA:根据--location指定的方式安装GuestOS时,用于传递给内核的额外选项,例如指定kickstart文件的位置,--extra-args "ks=http://172.16.0.1/class.cfg"
    --boot=BOOTOPTS:指定安装过程完成后的配置选项,如指定引导设备次序、使用指定的而非安装的kernel/initrd来引导系统启动等 ;例如:
    --boot  cdrom,hd,network:指定引导次序;
    --boot kernel=KERNEL,initrd=INITRD,kernel_args=”console=/dev/ttyS0”:指定启动系统的内核及initrd文件;
◇    存储配置:指定存储类型、位置及属性等;
    --disk=DISKOPTS:指定存储设备及其属性;格式为--disk /some/storage/path,opt1=val1,opt2=val2等;常用的选项有:
    device:设备类型,如cdrom、disk或floppy等,默认为disk;
    bus:磁盘总结类型,其值可以为ide、scsi、usb、virtio或xen;
    perms:访问权限,如rw、ro或sh(共享的可读写),默认为rw;
    size:新建磁盘映像的大小,单位为GB;
    cache:缓存模型,其值有none、writethrouth(缓存读)及writeback(缓存读写);
    format:磁盘映像格式,如raw、qcow2、vmdk等;
    sparse:磁盘映像使用稀疏格式,即不立即分配指定大小的空间;
    --nodisks:不使用本地磁盘,在LiveCD模式中常用;
◇    网络配置:指定网络接口的网络类型及接口属性如MAC地址、驱动模式等;
    -w NETWORK, --network=NETWORK,opt1=val1,opt2=val2:将虚拟机连入宿主机的网络中,其中NETWORK可以为:
    bridge=BRIDGE:连接至名为“BRIDEG”的桥设备;
    network=NAME:连接至名为“NAME”的网络;
其它常用的选项还有:
    model:GuestOS中看到的网络设备型号,如e1000、rtl8139或virtio等;
    mac:固定的MAC地址;省略此选项时将使用随机地址,但无论何种方式,对于KVM来说,其前三段必须为52:54:00;
    --nonetworks:虚拟机不使用网络功能;
◇    图形配置:定义虚拟机显示功能相关的配置,如VNC相关配置;
    --graphics TYPE,opt1=val1,opt2=val2:指定图形显示相关的配置,此选项不会配置任何显示硬件(如显卡),而是仅指定虚拟机启动后对其进行访问的接口;
    TYPE:指定显示类型,可以为vnc、sdl、spice或none等,默认为vnc;
    port:TYPE为vnc或spice时其监听的端口;
    listen:TYPE为vnc或spice时所监听的IP地址,默认为127.0.0.1,可以通过修改/etc/libvirt/qemu.conf定义新的默认值;
    password:TYPE为vnc或spice时,为远程访问监听的服务进指定认证密码;
    --noautoconsole:禁止自动连接至虚拟机的控制台;
◇    设备选项:指定文本控制台、声音设备、串行接口、并行接口、显示接口等;
    --serial=CHAROPTS:附加一个串行设备至当前虚拟机,根据设备类型的不同,可以使用不同的选项,格式为“--serial type,opt1=val1,opt2=val2,...”,例如:
    --serial pty:创建伪终端;
    --serial dev,path=HOSTPATH:附加主机设备至此虚拟机;
    --video=VIDEO:指定显卡设备模型,可用取值为cirrus、vga、qxl或vmvga;
 
◇    虚拟化平台:虚拟化模型(hvm或paravirt)、模拟的CPU平台类型、模拟的主机类型、hypervisor类型(如kvm、xen或qemu等)以及当前虚拟机的UUID等;
    -v, --hvm:当物理机同时支持完全虚拟化和半虚拟化时,指定使用完全虚拟化;
    -p, --paravirt:指定使用半虚拟化;
    --virt-type:使用的hypervisor,如kvm、qemu、xen等;所有可用值可以使用’virsh capabilities’命令获取;
◇    其它:
    --autostart:指定虚拟机是否在物理启动后自动启动;
    --print-xml:如果虚拟机不需要安装过程(--import、--boot),则显示生成的XML而不是创建此虚拟机;默认情况下,此选项仍会创建磁盘映像;
    --force:禁止命令进入交互式模式,如果有需要回答yes或no选项,则自动回答为yes;
    --dry-run:执行创建虚拟机的整个过程,但不真正创建虚拟机、改变主机上的设备配置信息及将其创建的需求通知给libvirt;
    -d, --debug:显示debug信息;

[root@e3 cdrom]#  virt-install \
> --name centos6.6 \ #指定虚拟机名字
> --ram 512 \  #分配虚拟机的内存大小
> --disk path=/data/kvm/images/centos6.6.img,size=20 \ #虚拟机硬盘安装路径
> --vcpus 2 \  #CPU个数
> --os-type linux \ #操作系统类型
> --os-variant rhel6 \ #虚拟机操作系统的变种,当前CENTOS是redhat的所以。
> --network bridge=br0 \ #网络配置
> --graphics none \  #不使用图形界面
> --console pty,target_type=serial \ #配置接口
> --location 'ftp://192.168.0.244/cdrom/' \  #指定安装源
>  --extra-args 'console=ttyS0,115200n8 serial'  #额外传的参数
#回车
开始安装......
搜索文件 .treeinfo......                                                                                                                                                                  |  590 B  00:00:00 !!! 
搜索文件 vmlinuz......                                                                                                                                                                    | 7.9 MB  00:00:00 !!! 
搜索文件 initrd.img......                                                                                                                                                                 |  66 MB  00:00:00 !!! 
创建存储文件 centos6.6.img                                                                                                                                                              |  20 GB  00:00:00     
创建域......                                                                                                                                                                               |    0 B  00:00:00     
连接到域 centos6.6
换码符为 ^]

Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.32-504.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014
Command line: method=ftp://192.168.0.244/cdrom/ console=ttyS0,115200n8 serial
KERNEL supported cpus:
  Intel GenuineIntel
  AMD AuthenticAMD
  Centaur CentaurHauls
BIOS-provided physical RAM map:
 BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
 BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
......省略。
###############
Welcome to CentOS for x86_64

                    ┌────────┤ Choose a Language ├────────┐
                    │                                     │
                    │ What language would you like to use │
                    │ during the installation process?    │
                    │                                     │
                    │      Catalan                ↑       │
                    │      Chinese(Simplified)    ▒       │
                    │      Chinese(Traditional)   ▮       │
                    │      Croatian               ▒       │
                    │      Czech                  ▒       │
                    │      Danish                 ▒       │
                    │      Dutch                  ▒       │
                    │      English                ↓       │
                    │                                     │
                    │               ┌────┐                │
                    │               │ OK │                │
                    │               └────┘                │
                    │                                     │
                    │                                     │
                    └─────────────────────────────────────┘
#用tab键选择语言
Welcome to CentOS for x86_64

                                                                                
                 ┌────────────┤ Configure TCP/IP ├────────────┐                 
                 │                                            │                 
                 │ [*] Enable IPv4 support                    │                 
                 │        (*) Dynamic IP configuration (DHCP) │                 
                 │        ( ) Manual configuration            │                 
                 │                                            │                 
                 │ [*] Enable IPv6 support                    │                 
                 │        (*) Automatic                       │                 
                 │        ( ) Automatic, DHCP only            │                 
                 │        ( ) Manual configuration            │                 
                 │                                            │                 
                 │        ┌────┐              ┌──────┐        │                 
                 │        │ OK │              │ Back │        │                 
                 │        └────┘              └──────┘        │                 
                 │                                            │                 
                 │                                            │                 
                 └────────────────────────────────────────────┘       
#激活ipv4,局域网有dhcp就下一步取消ipv6,没有手动写个ip跟你ftp server 在同一网关即可
Welcome to CentOS for x86_64

                                                                                
       ┌────────────────┤ Manual TCP/IP Configuration ├─────────────────┐       
       │                                                                │       
       │ Enter the IPv4 and/or the IPv6 address and prefix (address /   │       
       │ prefix).  For IPv4, the dotted-quad netmask or the CIDR-style  │       
       │ prefix are acceptable. The gateway and name server fields must │       
       │ be valid IPv4 or IPv6 addresses.                               │       
       │                                                                │       
       │ IPv4 address: 192.168.0.13____ / 24______________              │       
       │ Gateway:      192.168.0.1______________________________        │       
       │ Name Server:  _________________________________________        │       
       │                                                                │       
       │             ┌────┐                        ┌──────┐             │       
       │             │ OK │                        │ Back │             │       
       │             └────┘                        └──────┘             │       
       │                                                                │       
       │                                                                │       
       └────────────────────────────────────────────────────────────────┘       
#用tab键切换到OK上然后会提示保存网卡信息OK即可下一步
 Welcome to CentOS for x86_64





               ┌──────────────────┤ CentOS ├───────────────────┐
               │                                               │
               │ Welcome to CentOS!                            │
               │                                               │
               │                                               │
               │                    ┌────┐                     │
               │                    │ OK │                     │
               │                    └────┘                     │
               │                                               │
               │                                               │
               └───────────────────────────────────────────────┘

#OK
Welcome to CentOS for x86_64
 ┌────────────────────────────────┤ Warning ├─────────────────────────────────┐ 
 │                                                                            │ 
 │         Error processing drive:                                 ↑          │ 
 │                                                                 ▮          │ 
 │         pci-0000:00:04.0-virtio-pci-virtio1                     ▒          │ 
 │         20480MB                                                 ▒          │ 
 │         Virtio Block Device                                     ▒          │ 
 │                                                                 ▒          │ 
 │         This device may need to be reinitialized.               ▒          │ 
 │                                                                 ▒          │ 
 │         REINITIALIZING WILL CAUSE ALL DATA TO BE LOST!          ▒          │ 
 │                                                                 ▒          │ 
 │         This action may also be applied to all other disks      ▒          │ 
 │         needing reinitialization.                               ↓          │ 
 │                                                                            │ 
 │  ┌────────┐   ┌────────────┐   ┌───────────────┐   ┌───────────────────┐   │ 
 │  │ Ignore │   │ Ignore all │   │ Re-initialize │   │ Re-initialize all │   │ 
 │  └────────┘   └────────────┘   └───────────────┘   └───────────────────┘   │ 
 │                                                                            │ 
 │                                                                            │ 
#选择初始化所有Re-initialize all 
Welcome to CentOS for x86_64
                                                                                
                                                                                
                    ┌───────┤ Time Zone Selection ├───────┐                     
                    │                                     │                     
                    │ In which time zone are you located? │                     
                    │                                     │                     
                    │ [*] System clock uses UTC           │                     
                    │                                     │                     
                    │  America/Monterrey               ↑  │                     
                    │  America/Montevideo              ▮  │                     
                    │  America/Montserrat              ▒  │                     
                    │  America/Nassau                  ▒  │                     
                    │  America/New York                ↓  │                     
                    │                                     │                     
                    │      ┌────┐          ┌──────┐       │                     
                    │      │ OK │          │ Back │       │                     
                    │      └────┘          └──────┘       │                     
                    │                                     │                     
                    │                                     │                     
                    └─────────────────────────────────────┘          
#选择时区Asia/上海
Welcome to CentOS for x86_64
                                                                                
                                                                                
                                                                                
                ┌──────────────┤ Root Password ├───────────────┐                
                │                                              │                
                │    Pick a root password. You must type it    │                
                │    twice to ensure you know it and do not    │                
                │    make a typing mistake.                    │                
                │                                              │                
                │ Password:           ________________________ │                
                │ Password (confirm): ________________________ │                
                │                                              │                
                │        ┌────┐               ┌──────┐         │                
                │        │ OK │               │ Back │         │                
                │        └────┘               └──────┘         │                
                │                                              │                
                │                                              │                
                └──────────────────────────────────────────────┘                
#设置root密码
Welcome to CentOS for x86_64
                                                                                
       ┌─────────────────────┤ Partitioning Type ├─────────────────────┐        
       │                                                               │        
       │ Installation requires partitioning of your hard drive.  The   │        
       │ default layout is suitable for most users.  Select what space │        
       │ to use and which drives to use as the install target.         │        
       │                                                               │        
       │                 Use entire drive                              │        
       │                 Replace existing Linux system                 │        
       │                 Use free space                                │        
       │                                                               │        
       │   Which drive(s) do you want to use for this installation?    │        
       │        [*]    vda    20480 MB (Virtio Block Device) ↑         │        
       │                                                     ▮         │        
       │                                                               │        
       │                      ┌────┐   ┌──────┐                        │        
       │                      │ OK │   │ Back │                        │        
       │                      └────┘   └──────┘                        │        
       │                                                               │        
       │                                                               │        
       └───────────────────────────────────────────────────────────────┘        

<Space>,<+>,<-> selection   |   <F2> Add drive   |   <F12> next screen  
#分区
Welcome to CentOS for x86_64
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
     ┌─────────────┤ Writing storage configuration to disk ├──────────────┐     
     │                                                                    │     
     │ The partitioning options you have selected will now be written to  │     
     │ disk.  Any data on deleted or reformatted partitions will be lost. │     
     │                                                                    │     
     │        ┌─────────┐               ┌───────────────────────┐         │     
     │        │ Go back │               │ Write changes to disk │         │     
     │        └─────────┘               └───────────────────────┘         │     
     │                                                                    │     
     │                                                                    │     
     └────────────────────────────────────────────────────────────────────┘     
#写入保存磁盘。
Welcome to CentOS for x86_64
                                                                                
                                                                                
                                                                                
                                                                                
     ┌─────────────────────┤ Package Installation ├──────────────────────┐      
     │                                                                   │      
     │                                                                   │      
     │                                71%                                │      
     │                                                                   │      
     │                  Packages completed: 180 of 205                   │      
     │                                                                   │      
     │ Installing kernel-2.6.32-504.el6.x86_64 (123 MB)                  │      
     │ The Linux kernel                                                  │      
     │                                                                   │      
     │                                                                   │      
     │                                                                   │      
     └───────────────────────────────────────────────────────────────────┘      
                                                                                
                                                                                
  <Tab>/<Alt-Tab> between elements   |  <Space> selects   |  <F12> next screen 

#然后初始化,格式化硬盘自动等待安装完毕 
Welcome to CentOS for x86_64
                                                                                
                                                                                
                                                                                
                                                                                
     ┌───────────────────────────┤ Complete ├────────────────────────────┐      
     │                                                                   │      
     │ Congratulations, your CentOS installation is complete.            │      
     │                                                                   │      
     │ Please reboot to use the installed system.  Note that updates may │      
     │ be available to ensure the proper functioning of your system and  │      
     │ installation of these updates is recommended after the reboot.    │      
     │                                                                   │      
     │                            ┌────────┐                             │      
     │                            │ Reboot │                             │      
     │                            └────────┘                             │      
     │                                                                   │      
     │                                                                   │      
     └───────────────────────────────────────────────────────────────────┘ 
 #重启即可进入创建的虚拟机                                                                               
#因为是mimi关盘安装很快的                                                                           
     CentOS release 6.6 (Final)
Kernel 2.6.32-504.el6.x86_64 on an x86_64

localhost.localdomain login: 
                                                                    
#OK,输入用户名和密码即可
[root@localhost ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 52:54:00:4F:7D:82  
          inet addr:192.168.0.13  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:ff:fe4f:7d82/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:206 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:22155 (21.6 KiB)  TX bytes:546 (546.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:340 (340.0 b)  TX bytes:340 (340.0 b)

[root@localhost ~]# 
#

这里有一篇virt-install 的中文翻译http://blog.csdn.net/starshine/article/details/6998189

#按Ctrl+]从虚拟机里切换到物理机
[root@e3 cdrom]# virsh list  #列出已经安装的虚拟机
 Id    名称                         状态
----------------------------------------------------
 11    centos6.5                      running
 13    centos6.6                      running

[root@e3 cdrom]# virsh console centos6.6  #从物理机连接虚拟机
连接到域 centos6.6
换码符为 ^]


[root@localhost ~]#
[root@e3 ~]# virsh autostart centos6.5 #自动启动
域 centos6.5标记为自动开始

[root@e3 ~]# virsh autostart centos6.6 #自动启动
域 centos6.6标记为自动开始
#
[root@e3 images]# cd /etc/libvirt/
[root@e3 libvirt]# ls
libvirt.conf  libvirtd.conf  lxc.conf  nwfilter  qemu  qemu.conf  qemu-lockd.conf  storage  virtlockd.conf
[root@e3 libvirt]# cd qemu/
[root@e3 qemu]# ls
autostart  centos6.5.xml  centos6.6.xml  kvm001.xml  kvm002.xml  networks  template.xml
[root@e3 qemu]# cd autostart/
[root@e3 autostart]# ll
总用量 0
lrwxrwxrwx. 1 root root 31 1月  20 14:18 centos6.5.xml -> /etc/libvirt/qemu/centos6.5.xml  #开机自启动的文件都会在安装目录里创建一个autostart目录,并设置软连接
lrwxrwxrwx. 1 root root 31 1月  20 14:19 centos6.6.xml -> /etc/libvirt/qemu/centos6.6.xml

[root@e3 ~]# 

[root@e3 ~]# virsh autostart --disable centos6.6 #取消自动启动
域 centos6.6取消标记为自动开始
#关闭一台虚拟机
[root@e3 images]# virsh list --all #列出所有启动没启动的虚拟机
 Id    名称                         状态
----------------------------------------------------
 23    centos6.5                      running
 29    centos6.6                      running
 -     kvm001                         关闭
 -     kvm002                         关闭
 -     template                       关闭

[root@e3 images]# virsh shutdown centos6.6 #关闭一台centos6.6
域 centos6.6 被关闭

好像关不了#默认virsh不能关闭虚拟机需要安装acpid

[root@e3 images]# yum install acpid
[root@e3 images]# systemctl start acpid.service 
[root@e3 images]# systemctl enable acpid.service
#在关闭试试

virsh管理虚拟机工具请看博友http://my.oschina.net/guol/blog/62253

共有 人打赏支持
粉丝 38
博文 116
码字总数 208084
×
雁南飞丶
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: