openstack虛擬機rescue模式

nova rescue vm_instance

which option system is linuxhtml

lin.wang 20190426node

   openstack環境中的虛擬機的救援模式,在ceph做爲cinder backend狀況下測試經過.

nova rescue命令使用幫助linux

[root@node-1 ~]# nova help rescue 
usage: nova rescue [--password <password>] [--image <image>] <server>

Reboots a server into rescue mode, which starts the machine from either the
initial image or a specified image, attaching the current boot disk as
secondary.

Positional arguments:
  <server>               Name or ID of server.

Optional arguments:
  --password <password>  The admin password to be set in the rescue
                         environment.
  --image <image>        The image to rescue with.

在控制節點執行以下命令nova rescue vm_uuid瀏覽器

[root@node-1 ~]# nova rescue 473fbedd-73e3-4163-a859-4010b0e8c4ae --password passw0rd
+-----------+----------+
| Property  | Value    |
+-----------+----------+
| adminPass | passw0rd |
+-----------+----------+

Note:ssh

這裏最好要指定密碼,而且做爲一個通用救援密碼rescue_password,該虛擬機有第一次rescue以後rescue密碼就不能改變了,之後再對該虛擬機進行救援,只能使用這個密碼了,下次再設置是無效的。測試

Cause: rescue虛擬機會在ceph裏生成一個用指定鏡像(若是沒有指定則是使用虛擬機的源鏡像)建立的卷,rebuild一個newVM,並將原虛擬機的卷做爲vdb掛載給newVM,若是已經存在rescue的卷則不會再次生成,因此第二次rescue的密碼並不能修改,除非手動刪除該rescue卷.ui

[root@node-1 ~]# rbd ls compute|grep 473fbedd-73e3-4163-a859-4010b0e8c4ae
473fbedd-73e3-4163-a859-4010b0e8c4ae_disk
473fbedd-73e3-4163-a859-4010b0e8c4ae_disk.rescue

在刪除該虛擬機的時候會將rescue的卷一併刪除.lua

此時虛擬機會進行重啓,Horizon界面的虛擬機狀態變爲"救援",nova list命令看到虛擬機也會變成RESCUE狀態.url

rescue的過程,會用建立虛擬機的image做爲引導鏡像來引導虛擬機,並把虛擬機做爲一個vdb盤,掛載到虛擬機上,進入虛擬機後能夠經過lsblk能夠看到日誌

[root@wl-test2 ~]# lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    253:0    0  10G  0 disk 
└─vda1 253:1    0  10G  0 part /
vdb    253:16   0  60G  0 disk 
└─vdb1 253:17   0  60G  0 part

Note:

如何進入rescue模式的虛擬機,此時能夠經過ssh鏈接並使用root/rescue_password 進入虛擬機。比例如:

nova ssh vm_uuid (此方式須要虛擬機有一個物理節點能通訊的ip,或者從命名空間ssh鏈接)

或者經過vnc的方式,頁面上不顯示vnc標籤頁,只能經過命令獲取vnc地址:

nova get-vnc-console 473fbedd-73e3-4163-a859-4010b0e8c4ae novnc

[root@node-1 ~]# nova get-vnc-console 473fbedd-73e3-4163-a859-4010b0e8c4ae novnc
+-------+----------------------------------------------------------------------------------------+
| Type  | Url                                                                                    |
+-------+----------------------------------------------------------------------------------------+
| novnc | https://sz.easystack.cn/novnc/vnc_auto.html?token=f3974443-9541-4447-bc0b-c5f3bfb5c65a |
+-------+----------------------------------------------------------------------------------------+

這裏獲取的https://...這個url直接複製到瀏覽器便可打開虛擬機的vnc界面.

將vdb即虛擬機的磁盤掛載給/mnt目錄(目錄能夠任意指定),掛載命令以下:

mount -o nouuid /dev/vdb1 /mnt

此時cd /mnt後,能夠看原虛擬機的全部目錄

[root@wl-test2 ~]# ls /mnt
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

修復場景:

1. 忘記了root密碼

[root@wl-test2 ~]# chroot /mnt
[root@wl-test2 /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@wl-test2 /]# passwd
Changing password for user root.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

此時root密碼已經修改完成

退出rescue狀態後,便可使用新密碼登陸虛擬機root用戶

2. xfs文件系統損壞

xfs_repair /dev/vdb1

若是此時有報錯 ERROR: The filesystem has valuable metadata changes in a log which needs to be replayed. ....

執行

xfs_repair -L /dev/vdb1 清理掉xfs的日誌信息(可能會丟失一些還沒有完成的日誌數據),再修復.

退出rescue模式:

修復完成後,退出rescue模式,在控制節點執行nova unrescue vm_uuid

[root@node-1 ~]# nova unrescue 5ec5fed5-90ac-464e-a584-6b303c29ff0a

以後,虛擬機會再次重啓,進入正常的運行狀態,此時界面上的虛擬機的狀態變回運行中。

相關文章
相關標籤/搜索