Centos6.5系統安裝kvm虛擬機器之複製、拷貝檔案安裝新虛擬機器

來源:互聯網
上載者:User

標籤:虛擬機器   welcome   

          Centos 6.5 x86_64系統安裝kvm虛擬機器—複製、拷貝xml檔案安裝新虛擬機器

一、通過模板虛擬機器複製新虛擬機器

IP規劃:

宿主機:10.0.1.149

模板虛擬機器:10.0.1.228

複製虛擬機器:10.0.1.100

  1. 關閉或者暫停模板虛擬機器,再進行複製安裝新虛擬機器。

[[email protected] ~]# virt-clone -o kvm_mode_5566 -n mysql-server -f /data/kvmdisk/mysql-server.qcow2ERROR    Domain with devices to clone must be paused or shutoff.

報錯原因:由於沒有關閉模板主機,我們關閉模板主機再試下。

解決kvm環境下可以使用shutdown命令讓虛擬機器關機,但不生效。

[[email protected] ~]# yum install -y acpid[[email protected] ~]# virsh Welcome to virsh, the virtualization interactive terminal.Type:  ‘help‘ for help with commands       ‘quit‘ to quitvirsh # list --all Id    Name                           State---------------------------------------------------- 1     kvm_mode_5566                  runningvirsh # shutdown kvm_mode_5566Domain kvm_mode_5566 is being shutdownvirsh # list --all             Id    Name                           State---------------------------------------------------- -     kvm_mode_5566                  shut off

2.通過virt-clone命令複製虛擬機器。

[[email protected] ~]# virt-clone -o kvm_mode_5566 -n mysql-server -f /data/kvmdisk/mysql-server.qcow2Cloning kvm_mode.img                                                                                         |  10 GB     03:43     Clone ‘mysql-server‘ created successfully.

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/46/35/wKioL1PvCi7TcmkvAACflP5vido436.jpg" title="222333.jpg" alt="wKioL1PvCi7TcmkvAACflP5vido436.jpg" />

3.手動更改xml設定檔中VNC連接埠,然後重啟libvirtd服務。

[[email protected] ~]# more /etc/libvirt/qemu/mysql-server.xml | grep vnc    <graphics type=‘vnc‘ port=‘7789‘ autoport=‘no‘ listen=‘0.0.0.0‘>[[email protected] ~]# /etc/init.d/libvirtd restartStopping 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 <http://bugs.centos.org>, 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.啟動新複製成功的虛擬機器。

[[email protected] ~]# virsh start mysql-serverDomain mysql-server started

5.通過VNC用戶端連結,配置eth0網卡。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/46/34/wKiom1PvCUqjE4m2AAGVTBW_yME667.jpg" title="網卡重啟報錯。.jpg" alt="wKiom1PvCUqjE4m2AAGVTBW_yME667.jpg" />解決辦法:

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

修改下MAC地址和UUID  :

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/46/35/wKioL1PvCrTDCib7AAE_MEQE5ko116.jpg" title="00000.jpg" alt="wKioL1PvCrTDCib7AAE_MEQE5ko116.jpg" />      

然後reboot新虛擬機器。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/46/35/wKioL1PvCvyzHf0GAAK9ZTRHTNQ020.jpg" title="成功.jpg" alt="wKioL1PvCvyzHf0GAAK9ZTRHTNQ020.jpg" />


二、通過拷貝xml檔案方式安裝新虛擬機器

  1. 製作虛擬機器鏡像。

[[email protected] ~]# cd /data/kvmdisk/[[email protected] kvmdisk]# cp mysql-server.qcow2 cache-server.qcow2[[email protected] kvmdisk]# lltotal 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檔案。

[[email protected] kvmdisk]# cd /etc/libvirt/qemu[[email protected] qemu]# lsautostart  kvm_mode_5566.xml  mysql-server.xml  networks[[email protected] qemu]# cp mysql-server.xml cache-server.xml

3.修改相應的參數。

uuid mac vnc 硬碟檔案位置 虛擬機器的主機名稱

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

vnc:指定連接埠,不能跟其它虛擬機器衝突

虛擬磁碟檔案位置:/data/kvmdisk/cache-server.qcow2

[[email protected] qemu]# vim cache-server.xml<uuid>d779256d-b82d-0ce6-520f-c4dda1596da9</uuid><mac address=‘52:54:00:9c:b8:0a‘/><source file=‘/data/kvmdisk/cache-server.qcow2‘/><graphics type=‘vnc‘ port=‘7790‘ autoport=‘no‘ listen=‘0.0.0.0‘>

4.建立虛擬機器。

[[email protected] qemu]# virsh define cache-server.xml Domain cache-server defined from cache-server.xml

5.啟動虛擬機器。

[[email protected] qemu]# virsh start cache-serverDomain cache-server started

6.設定虛擬機器自動重啟。

[[email protected] qemu]# virsh autostart cache-serverDomain cache-server marked as autostarted

7.查看下所有的虛擬機器。

[[email protected] ~]# virsh Welcome to virsh, the virtualization interactive terminal.Type:  ‘help‘ for help with commands       ‘quit‘ to quitvirsh # list --all Id    Name                           State---------------------------------------------------- 1     kvm_mode_5566                  running 2     mysql-server                   running 3     cache-server                   running

到此為止,實驗結束。

本文出自 “歲月在流逝,光輝依然在” 部落格,轉載請與作者聯絡!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.