openstack虚拟机rescue模式

时间:2021-07-28 07:04:16

nova rescue vm_instance

which option system is linux

lin.wang 20190426

	openstack环境中的虚拟机的救援模式,在ceph作为cinder backend情况下测试通过.

nova rescue命令使用帮助

[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:

这里最好要指定密码,并且作为一个通用救援密码rescue_password,该虚拟机有第一次rescue之后rescue密码就不能改变了,以后再对该虚拟机进行救援,只能使用这个密码了,下次再设置是无效的。

Cause: rescue虚拟机会在ceph里生成一个用指定镜像(如果没有指定则是使用虚拟机的源镜像)创建的卷,rebuild一个newVM,并将原虚拟机的卷作为vdb挂载给newVM,如果已经存在rescue的卷则不会再次生成,所以第二次rescue的密码并不能修改,除非手动删除该rescue卷.

[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的卷一并删除.

此时虚拟机会进行重启,Horizon界面的虚拟机状态变为"救援",nova list命令看到虚拟机也会变成RESCUE状态.

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

之后,虚拟机会再次重启,进入正常的运行状态,此时界面上的虚拟机的状态变回运行中。