删除 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/