刪除 OpenStack Nova Volume 時遇到的 error_deleting 問題
前段時間 VPSee 在 OpenStack Nova 上刪除一個 volume 的時候(vol-00000002)報錯,檢查了一下 volume 的狀態是 error_deleting 然後就無法刪除了,不管用 euca-delete-volume 還是 nova-manage volume delete 都無法刪除。
# euca-delete-volume vol-00000002 ApiError: ApiError: Volume status must be available # euca-describe-volumes VOLUME vol-00000002 10 nova error_deleting (mycloud, node01, None, None) 2011-08-30T13:15:24Z VOLUME vol-00000003 10 nova available (mycloud, node01, None, None) 2011-08-30T13:20:04Z
查了一下要刪除的 volume-00000002 的情況:
# lvdisplay ... --- Logical volume --- LV Name /dev/nova-volumes/volume-00000002 VG Name nova-volumes LV UUID UgOwdr-W61E-MrdG-PrdY-IToa-LBi8-2XJjXF LV Write Access read/write LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 251:2 ...
既然用工具沒法刪除的話就乾脆從數據庫裏直接刪除,無非就是一條記錄而已,先從 nova 數據庫裏找到這條 volume 記錄並設置狀態爲 deleted,然後刪除實際對應的 LVM. 從數據庫裏找到相應的表和記錄後設置 status 爲 deleted 狀態:
# mysql -u root -p Enter password: mysql> use nova; mysql> select status,id from volumes; +----------------+----+ | status | id | +----------------+----+ | creating | 1 | | error_deleting | 2 | | available | 3 | +----------------+----+describe 3 rows in set (0.00 sec) mysql> update volumes set status='deleted' where id='2'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
退出 mysql 數據庫操作回到命令行就會看到 vol-00000002 的狀態是 deleted 的,然後用 lvmremove 命令刪除:
# euca-describe-volumes VOLUME vol-00000002 10 nova deleted (mycloud, node01, None, None) 2011-08-30T13:15:24Z # ls /dev/nova-volumes/ volume-00000002 volume-00000003 # lvremove /dev/nova-volumes/volume-00000002 Do you really want to remove active logical volume volume-00000002? [y/n]: y Logical volume "volume-00000002" successfully removed
最後用 nova-manage 命令從數據庫裏徹底刪除 vol-00000002(當然也可以直接在 mysql 裏用 SQL 語句操作刪除對應的記錄 DELETE FROM volumes WHERE id=’2′;):
euca-delete-volume vol-00000002 ApiError: ApiError: Volume status must be available # euca-describe-volumes VOLUME vol-00000002 10 nova error_deleting (mycloud, node01, None, None) 2011-08-30T13:15:24Z VOLUME vol-00000003 10 nova avaiable (mycloud, node01, None, None) 2011-08-30T13:20:04Z # nova-manage volume delete vol-00000002 # euca-describe-volumes VOLUME vol-00000003 10 nova available (mycloud, node01, None, None) 2011-08-30T13:20:04Z
另外可能會出現這個問題:
MYSQL: Cannot delete or update a parent row: a foreign key constraint fails
Error No. 1451 Cannot delete or update a parent row: a foreign key constraint fails (...)
這 可能是MySQL在InnoDB中設置了foreign key關聯,造成無法更新或刪除數據。可以通過設置FOREIGN_KEY_CHECKS變量來避免這種情況。 SET FOREIGN_KEY_CHECKS = 0;刪除完成後設置 SET FOREIGN_KEY_CHECKS = 1;
轉自:http://www.vpsee.com/2011/09/how-to-delete-a-openstack-nova-volume-when-the-status-is-error_deleting/