OpenStack Juno刪除殭屍實例 - 虛機實例相關nova表

MQ服務消息超時或者任何其他中斷實例創建或者刪除的情況,都會造成“僵死”實例的存在。也即是這個實例並不存在,或者即便存在也是有問題的,並且在Dashboard儀表盤上刪除不了。提示“you are not allowed to terminate this instance"之類的錯誤。即便提示刪除成功,實際還是在那裏死趟着。命令行同樣的問題,如下

# nova list /*列表顯示出來*/

+--------------------------------------+--------------------+--------+------------+-------------+---------------------+
| ID                                   | Name               | Status | Task State | Power State | Networks            |
+--------------------------------------+--------------------+--------+------------+-------------+---------------------+
| 09dca062-c577-469f-bff5-cccbe65a5b7c | instance_name      | ERROR  | deleting   | NOSTATE     |                     | 
# nova reset-state 09dca062-c577-469f-bff5-cccbe65a5b7c /*重置下狀態,正在刪除任務消失*/

# nova delete 09dca062-c577-469f-bff5-cccbe65a5b7c /*嘗試命令行刪除*/

# nova list /*還是上面的顯示正在刪除任務的狀態*/

# mysql -uroot -p /*在控制節點上數據庫去看看這個實例在哪個結算節點上*/

MariaDB [(none)]> select node from nova.instances where uuid='09dca062-c577-469f-bff5-cccbe65a5b7c'; /*得到這個實例所在的計算節點*/

# ll /var/lib/nova/instances/ /*到該計算節點查看實例文件夾在不在*/

# rm -Rf 09dca062-c577-469f-bff5-cccbe65a5b7c /*在的話,給刪除*/

現在再次進入數據庫,進行多個表格刪除對應實例ID的記錄。

1. nova.instances表中,實例ID的字段名是uuid;

2. 其他外鏈表使用的是instance_uuid來引用。

MariaDB [nova]> delete from table_name where instance_uuid='09dca062-c577-469f-bff5-cccbe65a5b7c'; /*從下面的表格中一一刪除關聯的記錄*/

table_name如下:

1. security_group_instance_association,實例安全組,創建默認安全組是default,但不會記錄,如果你已經關聯了安全組,那就刪除下*/

2. instance_info_caches,實例緩存,刪除

3. block_device_mapping,實例塊存儲,默認保存了一條volume_id爲NULL的記錄,刪除之*/

4. instance_actions_events,實例操作結果,字段action_id引用下表instance_actions中的id,該表沒有instance_uuid*/

5. instance_actions,實例操作,每個操作有一個id,作爲上表instance_actions_events的action_id*/

這裏我在想,真是蛋疼,兩個表爲啥不結合爲一個表。所以只能首先在instance_actions中獲取操作id然後在events中再去刪

MariaDB [nova]> select id,action,instance_uuid from instance_actions where instance_uuid='09dca062-c577-469f-bff5-cccbe65a5b7c';

+-----+--------+--------------------------------------+
| id  | action | instance_uuid                        |
+-----+--------+--------------------------------------+
| 380 | create | 09dca062-c577-469f-bff5-cccbe65a5b7c |
| 382 | delete | 09dca062-c577-469f-bff5-cccbe65a5b7c |
| 383 | delete | 09dca062-c577-469f-bff5-cccbe65a5b7c |
| 384 | delete | 09dca062-c577-469f-bff5-cccbe65a5b7c |
| 385 | delete | 09dca062-c577-469f-bff5-cccbe65a5b7c |
| 386 | delete | 09dca062-c577-469f-bff5-cccbe65a5b7c |
+-----+--------+--------------------------------------+
MariaDB [nova]> delete from instance_actions_events where action_id='380'; /*我在儀表盤操作了基礎*/
MariaDB [nova]> delete from instance_actions_events where action_id='382';
MariaDB [nova]> delete from instance_actions_events where action_id='383';
MariaDB [nova]> delete from instance_actions_events where action_id='384';
MariaDB [nova]> delete from instance_actions_events where action_id='385';
MariaDB [nova]> delete from instance_actions_events where action_id='386'; /*刪除instance_action_events之後再去刪除instance_action*/

6. instance_faults,實例錯誤

7. instance_extra,沒有看錶的內容,不知道放的啥東西,只有一條記錄

8. instance_system_metadata,實例元數據,記錄蠻多的

9. instances,實例表,記錄所有實例,儀表盤的實例列表就是讀取這裏


上面的9個表格刪除完畢止之後,不要急着去刷新儀表盤,不然會提示無法獲取實例列表信息 - 蠻嚇人的!實例佔用的資源依然被佔用。

# systemctl restart openstack-nova-api openstack-nova-conductor /*重啓下服務*/

# nova list /*實例刪掉了,資源收回*/


最後如果每次都這麼手動的去搞,麻煩,那就寫個腳本:

# vim deletevm.sh

mysql -uroot -p << EOF
use nova;
delete from security_group_instance_association where instance_uuid='$1';
delete from instance_info_caches where instance_uuid='$1';
delete from block_device_mapping where instance_uuid='$1';
delete from instance_actions where instance_uuid='$1'; /*這個地方可能需要手工,SQL能力不強哎*/
delete from instance_faults where instance_uuid='$1';
delete from instance_extra where instance_uuid='$1';
delete from instance_system_metadata where instance_uuid='$1';
delete from instances where instance_uuid='$1';
EOF


# chmod +x deletevm.sh

# ./deletevm.sh instance_id /*以後用這個腳本來搞就快多了*/

# nova list /*最後可以再看看*/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章