需求說明:
計算節點linux-node1.openstack:192.168.1.8
計算節點linux-node2.openstack:192.168.1.17
這兩個計算節點在同一個控制節點下(192.168.1.8既是控制節點,也是其中一個計算節點),現在需要將linux-node1.openstack上的虛擬機器kvm-server005遷移到liunx-node2.openstack上。
一、openstack的虛擬機器線下遷移(”冷遷移“,遷移前關閉虛擬機器)
操作記錄如下:
linux-node1.openstack上的操作:
1)檢視虛擬機器
[root@linux-node1 src]# source admin-openrc.sh
[root@linux-node1 src]# nova list +--------------------------------------+----------------------------+--------+------------+-------------+--------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+----------------------------+--------+------------+-------------+--------------------+ | b6a4738d-7e01-4068-a09b-7008b612d126 | beta-new1 | ACTIVE | - | Running | flat=192.168.1.151 | | 9acdb28b-02c2-41bb-87c4-5f3a8fa008ab | dev-new-test1 | ACTIVE | - | Running | flat=192.168.1.150 | | 30e5ba3e-3942-4119-9ba6-7523cf865b6f | fangfull-backup | ACTIVE | - | Running | flat=192.168.1.152 | | 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005 | ACTIVE | - | Running | flat=192.168.1.154 | | 5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3 | memcache1-backup | ACTIVE | - | Running | flat=192.168.1.155 | | a5863e46-ef75-4601-a9df-505da5db58ed | memcache2-backup | ACTIVE | - | Running | flat=192.168.1.156 | | 377c536e-4d27-4447-8d9d-24c2686a73f6 | memcache3-backup | ACTIVE | - | Running | flat=192.168.1.103 | | a2893208-3ec9-4606-ab82-d7a870206cb9 | xqsj-backup | ACTIVE | - | Running | flat=192.168.1.153 | +--------------------------------------+----------------------------+--------+------------+-------------+--------------------+
2)停止待遷移虛擬機器kvm-server005
[root@linux-node1 src]# nova stop 3483d9f1-4015-48d9-9837-b67ca82dd54d Request to stop server 3483d9f1-4015-48d9-9837-b67ca82dd54d has been accepted. [root@linux-node1 src]# nova list +--------------------------------------+----------------------------+--------+--------------+-------------+--------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+----------------------------+--------+--------------+-------------+--------------------+ | b6a4738d-7e01-4068-a09b-7008b612d126 | beta-new1 | ACTIVE | - | Running | flat=192.168.1.151 | | 9acdb28b-02c2-41bb-87c4-5f3a8fa008ab | dev-new-test1 | ACTIVE | - | Running | flat=192.168.1.150 | | 30e5ba3e-3942-4119-9ba6-7523cf865b6f | fangfull-backup | ACTIVE | - | Running | flat=192.168.1.152 | | 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005 | SHUTOFF| - | Shutdown | flat=192.168.1.154 | | 5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3 | memcache1-backup | ACTIVE | - | Running | flat=192.168.1.155 | | a5863e46-ef75-4601-a9df-505da5db58ed | memcache2-backup | ACTIVE | - | Running | flat=192.168.1.156 | | 377c536e-4d27-4447-8d9d-24c2686a73f6 | memcache3-backup | ACTIVE | - | Running | flat=192.168.1.103 | | a2893208-3ec9-4606-ab82-d7a870206cb9 | xqsj-backup | ACTIVE | - | Running | flat=192.168.1.153 | +--------------------------------------+----------------------------+--------+--------------+-------------+--------------------+
3)檢視待遷虛擬機器kvm-server005所在的宿主機
[root@linux-node1 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos' | OS-EXT-SRV-ATTR:host | linux-node1.openstack
4)登入宿主機linux-node1.openstack上,將虛擬機器kvm-server005虛擬機器的資料拷貝到待遷移的宿主機linux-node2.openstack上
[root@linux-node1 src]# cd /var/lib/nova/instances [root@linux-node1 instances]# ls 30e5ba3e-3942-4119-9ba6-7523cf865b6f 5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3 a5863e46-ef75-4601-a9df-505da5db58ed compute_nodes 3483d9f1-4015-48d9-9837-b67ca82dd54d 9acdb28b-02c2-41bb-87c4-5f3a8fa008ab b6a4738d-7e01-4068-a09b-7008b612d126 locks 377c536e-4d27-4447-8d9d-24c2686a73f6 a2893208-3ec9-4606-ab82-d7a870206cb9 _base snapshots [root@linux-node1 instances]# rsync -e "ssh -p22" -avpgolr 3483d9f1-4015-48d9-9837-b67ca82dd54d 192.168.1.17:/var/lib/nova/instances/ sending incremental file list 3483d9f1-4015-48d9-9837-b67ca82dd54d/ 3483d9f1-4015-48d9-9837-b67ca82dd54d/console.log 3483d9f1-4015-48d9-9837-b67ca82dd54d/disk 3483d9f1-4015-48d9-9837-b67ca82dd54d/disk.info 3483d9f1-4015-48d9-9837-b67ca82dd54d/disk.swap 3483d9f1-4015-48d9-9837-b67ca82dd54d/libvirt.xml sent 381469737 bytes received 111 bytes 69358154.18 bytes/sec total size is 381422781 speedup is 1.00
目標節點linux-node2.openstack上的操作
1)檢視虛擬機器kvm-server005的資料有沒有拷貝過來,修改許可權
[root@linux-node2 instances]# pwd /var/lib/nova/instances [root@linux-node2 instances]# ll total 12 drwxr-xr-x. 2 nova nova 85 Oct 31 14:54 0944254c-1c75-4523-9751-2389d677d59c drwxr-xr-x. 2 nova nova 85 Sep 6 12:59 3483d9f1-4015-48d9-9837-b67ca82dd54d drwxr-xr-x. 2 nova nova 85 Oct 31 17:29 946b340a-28bc-492d-8b3a-59d2fea1b464 drwxr-xr-x. 2 nova nova 4096 Oct 31 17:17 _base -rw-r--r--. 1 nova nova 44 Nov 1 10:53 compute_nodes drwxr-xr-x. 2 nova nova 85 Oct 31 17:23 f6be1cb3-a694-4492-b2db-55ff9f09d843 drwxr-xr-x. 2 nova nova 4096 Oct 31 17:14 locks [root@linux-node2 instances]# chown -R nova.nova 3483d9f1-4015-48d9-9837-b67ca82dd54d/ [root@linux-node2 instances]# ll 3483d9f1-4015-48d9-9837-b67ca82dd54d/ total 372492 -rw-rw----. 1 nova nova 65214 Sep 8 13:58 console.log -rw-r--r--. 1 nova nova 381157376 Nov 1 10:59 disk -rw-r--r--. 1 nova nova 162 Sep 6 12:59 disk.info -rw-r--r--. 1 nova nova 197120 Sep 6 12:59 disk.swap -rw-r--r--. 1 nova nova 2909 Sep 6 12:59 libvirt.xml
2)登入資料庫更改MySQL中的host、node欄位為新的物理主機名字
[root@linux-node2 instances]# mysql -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4063 Server version: 10.1.17-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use nova; Database changed MariaDB [nova]> update instances set host='linux-node2.openstack', node='linux-node2.openstack' where uuid='3483d9f1-4015-48d9-9837-b67ca82dd54d'; Query OK, 1 rows affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 MariaDB [nova]>
3)在目標節點linux-node2.openstack上啟動虛擬機器,啟動前重啟一下該計算節點的compute服務
[root@linux-node2 instances]# systemctl restart openstack-nova-compute [root@linux-node2 instances]# nova start 3483d9f1-4015-48d9-9837-b67ca82dd54d
4)驗證虛擬機器所在的宿主機
[root@linux-node2 src]# nova list +--------------------------------------+--------------+--------+------------+-------------+--------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+--------------+--------+------------+-------------+--------------------+ | 946b340a-28bc-492d-8b3a-59d2fea1b464 | centos03 | ACTIVE | - | Running | flat=192.168.1.104 | | 0944254c-1c75-4523-9751-2389d677d59c | kvm-centos01 | ACTIVE | - | Running | flat=192.168.1.121 | | f6be1cb3-a694-4492-b2db-55ff9f09d843 | kvm-centos02 | ACTIVE | - | Running | flat=192.168.1.122 | | 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005| ACTIVE | - | Running | flat=192.168.1.154 | +--------------------------------------+--------------+--------+------------+-------------+--------------------+
[root@linux-node2 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos'
| OS-EXT-SRV-ATTR:host | linux-node2.openstack
二、openstack的虛擬機器線上遷移(”熱遷移“,虛擬機器在執行中遷移)
直接在控制節點上操作
1)檢視虛擬機器
[root@linux-node1 src]# source admin-openrc.sh [root@linux-node1 src]# nova list +--------------------------------------+----------------------------+--------+------------+-------------+--------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+----------------------------+--------+------------+-------------+--------------------+ | b6a4738d-7e01-4068-a09b-7008b612d126 | beta-new1 | ACTIVE | - | Running | flat=192.168.1.151 | | 9acdb28b-02c2-41bb-87c4-5f3a8fa008ab | dev-new-test1 | ACTIVE | - | Running | flat=192.168.1.150 | | 30e5ba3e-3942-4119-9ba6-7523cf865b6f | fangfull-backup | ACTIVE | - | Running | flat=192.168.1.152 | | 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005 | ACTIVE | - | Running | flat=192.168.1.154 | | 5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3 | memcache1-backup | ACTIVE | - | Running | flat=192.168.1.155 | | a5863e46-ef75-4601-a9df-505da5db58ed | memcache2-backup | ACTIVE | - | Running | flat=192.168.1.156 | | 377c536e-4d27-4447-8d9d-24c2686a73f6 | memcache3-backup | ACTIVE | - | Running | flat=192.168.1.103 | | a2893208-3ec9-4606-ab82-d7a870206cb9 | xqsj-backup | ACTIVE | - | Running | flat=192.168.1.153 | +--------------------------------------+----------------------------+--------+------------+-------------+--------------------+
2)檢視待遷虛擬機器kvm-server005所在的宿主機
[root@linux-node1 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos' | OS-EXT-SRV-ATTR:host | linux-node1.openstack
3)檢視可用的計算節點
[root@linux-node1 src]# nova-manage service list
No handlers could be found for logger "oslo_config.cfg"
Binary Host Zone Status State Updated_At
.........
nova-compute linux-node1.openstack nova enabled :-) 2016-11-01 05:12:56
nova-compute linux-node2.openstack nova enabled XXX 2016-10-31 05:55:24
4)檢視目標計算節點linux-node2.openstack資源
[root@linux-node1 src]# nova-manage service describe_resource linux-node2.openstack
No handlers could be found for logger "oslo_config.cfg"
HOST PROJECT cpu mem(mb) hdd
linux-node2.openstack(total) 32 64211 149
linux-node2.openstack(used_now) 6 14848 75
linux-node2.openstack(used_max) 6 14336 75
linux-node2.openstack 0cd3632df93d48d6b2c24c67f70e56b8 6 14336 75
5)執行虛擬機器的線上遷移,遷移到計算節點linux-node2.openstack上
[root@linux-node1 src]# nova live-migration 3483d9f1-4015-48d9-9837-b67ca82dd54d linux-node2.openstack
6)檢視遷移後虛擬機器kvm-server005所在的宿主機是否已發生改變
[root@linux-node1 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos' | OS-EXT-SRV-ATTR:host | linux-node2.openstack
注意:
1)/etc/hosts檔案提前做好主機對映,確定節點之間能互相ping通主機名。
2)利用id nova命令檢視下控制節點nova的uid和gid,並記錄,保證兩個計算節點的id和gid是否和控制節點保持一致
如果不一致,則利用
usermod -u “控制節點的nova的uid”
gropumod -g “控制節點的nova的gid”
兩條命令進行修改,同時在所有計算節點執行該命令,保證所有nova相關檔案使用新的uid和gid