文本复制 虚拟机centor_Centos6.5系统安装kvm虚拟机之克隆、拷贝文件安装新虚拟机...

Centos 6.5 x86_64系统安装kvm虚拟机—克隆、拷贝xml文件安装新虚拟机

一、通过模板虚拟机克隆新虚拟机

IP规划:

宿主机:10.0.1.149

模板虚拟机:10.0.1.228

克隆虚拟机:10.0.1.100关闭或者暂停模板虚拟机,再进行克隆安装新虚拟机。[root@taokey ~]# virt-clone -o kvm_mode_5566 -n mysql-server -f /data/kvmdisk/mysql-server.qcow2

ERROR    Domain with devices to clone must be paused or shutoff.

报错原因:由于没有关闭模板主机,我们关闭模板主机再试下。

解决kvm环境下可以使用shutdown命令让虚拟机关机,但不生效。[root@taokey ~]# yum install -y acpid

[root@taokey ~]# virsh

Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands

'quit' to quit

virsh # list --all

Id    Name                           State

----------------------------------------------------

1     kvm_mode_5566                  running

virsh # shutdown kvm_mode_5566

Domain kvm_mode_5566 is being shutdown

virsh # list --all

Id    Name                           State

----------------------------------------------------

-     kvm_mode_5566                  shut off

2.通过virt-clone命令克隆虚拟机。[root@taokey ~]# virt-clone -o kvm_mode_5566 -n mysql-server -f /data/kvmdisk/mysql-server.qcow2

Cloning kvm_mode.img                                                                                         |  10 GB     03:43

Clone 'mysql-server' created successfully.

954c40a4b793ef0d9586e78c40577bbb.png

3.手动更改xml配置文件中VNC端口,然后重启libvirtd服务。[root@taokey ~]# more /etc/libvirt/qemu/mysql-server.xml | grep vnc

[root@taokey ~]# /etc/init.d/libvirtd restart

Stopping libvirtd daemon:                                  [  OK  ]

Starting libvirtd daemon: 2014-08-16 02:08:44.921+0000: 3112: info : libvirt version: 0.10.2, package: 29.el6_5.11 (CentOS BuildSystem , 2014-07-31-18:52:08, c6b8.bsys.dev.centos.org)

2014-08-16 02:08:44.921+0000: 3112: warning : virGetHostname:2294 : getaddrinfo failed for 'taokey': Name or service not known

[  OK  ]

4.启动新克隆成功的虚拟机。[root@taokey ~]# virsh start mysql-server

Domain mysql-server started

5.通过VNC客户端链接,配置eth0网卡。

2c2ed7f8bc9dc845b3a3048ff1888e2f.png解决办法:

rm -rf /etc/udev/rules.d/70-persistent-net.rules

修改下MAC地址和UUID  如图所示:

8458a941228ba0b8e48bf318f2987d0d.png

然后reboot新虚拟机。

d0c522c70d55379ceac36164405062b0.png

二、通过拷贝xml文件方式安装新虚拟机制作虚拟机镜像。[root@taokey ~]# cd /data/kvmdisk/

[root@taokey kvmdisk]# cp mysql-server.qcow2 cache-server.qcow2

[root@taokey kvmdisk]# ll

total 1878560

-rwxr-xr-x 1 root root 10739318784 Aug 15 22:24 cache-server.qcow2

-rwxr-xr-x 1 qemu qemu 10739318784 Aug 15 22:25 mysql-server.qcow2

2.创建xml文件。[root@taokey kvmdisk]# cd /etc/libvirt/qemu

[root@taokey qemu]# ls

autostart  kvm_mode_5566.xml  mysql-server.xml  networks

[root@taokey qemu]# cp mysql-server.xml cache-server.xml

3.修改相应的参数。

uuid mac vnc 硬盘文件位置 虚拟机的主机名

uuid和mac:可以随意更改,但是格式一致

vnc:指定端口,不能跟其它虚拟机冲突

虚拟磁盘文件位置:/data/kvmdisk/cache-server.qcow2[root@taokey qemu]# vim cache-server.xml

d779256d-b82d-0ce6-520f-c4dda1596da9

4.创建虚拟机。[root@taokey qemu]# virsh define cache-server.xml

Domain cache-server defined from cache-server.xml

5.启动虚拟机。[root@taokey qemu]# virsh start cache-server

Domain cache-server started

6.设置虚拟机自动重启。[root@taokey qemu]# virsh autostart cache-server

Domain cache-server marked as autostarted

7.查看下所有的虚拟机。[root@taokey ~]# virsh

Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands

'quit' to quit

virsh # list --all

Id    Name                           State

----------------------------------------------------

1     kvm_mode_5566                  running

2     mysql-server                   running

3     cache-server                   running

到此为止,实验结束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值