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
以后,虚拟机会再次重启,进入正常的运行状态,此时界面上的虚拟机的状态变回运行中。