如何删除 OpenStack Nova 僵尸实例

转自:http://www.vpsee.com/2011/11/how-to-delete-a-openstack-nova-zombie-instance/

前天强制重启一台 OpenStack Nova 控制结点以后发现虚拟机消失,但是 euca-describe-instances 命令显示 instances 仍然是 running 的状态,使用 euca-terminate-instances 终止命令仍然无效,暂时把这样的 instance 称作"僵尸实例(zombie instance)":

# virsh list
Id Name State
----------------------------------
# euca-describe-instances RESERVATION r-bkl83j20 bangcloud default INSTANCE i-0000001d ami-00000002 172.16.39.121 172.16.39.121 running vpsee (vpseecloud, node00) 0 2011-11-10T12:45:12Z nova aki-00000001 ami-00000000 RESERVATION r-j335q6ny bangcloud default INSTANCE i-0000001e ami-00000002 172.16.39.122 172.16.39.122 running vpsee (vpseecloud, node00) 0 2011-11-10T12:54:27Z nova aki-00000001 ami-00000000
# euca-terminate-instances i-0000001d # euca-terminate-instances i-0000001e

 

和 删除 OpenStack Nova Volume 时遇到的 error_deleting 问题 这篇文章提到的解决办法一样,直接操作数据库来删除这2条僵尸实例的记录。登录 mysql,使用 nova 数据库,找出要删除 instance 的 id,然后删除:

 

# mysql -u root -p
Enter password:
mysql
> use nova; mysql> select * from instances; mysql> delete from instances where id = '29'; ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`nova`.`virtual_interfaces`, CONSTRAINT `virtual_interfaces_ibfk_1` FOREIGN KEY (`instance_id`) REFERENCES `instances` (`id`))

 

 

MySQL 删除 id 为 29 的 instance 时触发外键限制错误,简单的办法是暂时关闭外键检查,等删除后再打开:

 

mysql> SET FOREIGN_KEY_CHECKS=0;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from instances where id = '29';
Query OK, 1 row affected (0.04 sec)

mysql> delete from instances where id = '30';
Query OK, 1 row affected (0.04 sec)

mysql> SET FOREIGN_KEY_CHECKS=1;
Query OK, 0 rows affected (0.00 sec)

 

 

删除 instance 29 和 30后再用 euca-describe-instances 命令验证一下:

 

# euca-describe-instances
posted @ 2015-05-09 10:14  dongdonggeorge  阅读(1051)  评论(0编辑  收藏  举报