找回密码
 注册
查看: 4139|回复: 0

Recover from a failed compute node

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2018-12-20 02:02:18 | 显示全部楼层 |阅读模式
Recover from a failed compute node/ K7 Z. x& V  d7 \. C9 u
updated: 2018-12-18 05:07
: z* ]: h& K% C0 A* \! b( l) PRecover from a failed compute node¶+ g/ o7 l- v' J! v9 O
If you deploy Compute with a shared file system, you can use several methods to quickly recover from a node failure. This section discusses manual recovery.9 y) T9 [$ b% e8 K9 y3 ^! F

2 G! _7 N- u% ]7 }Evacuate instances¶
8 {) k& O' Q/ Z7 AIf a hardware malfunction or other error causes the cloud compute node to fail, you can use the nova evacuate command to evacuate instances. See evacuate instances for more information on using the command.
5 q% p8 q# S4 X: e% ?% U
* v3 }/ w, U6 n& l0 iManual recovery¶
. X8 G8 m4 u7 b: lTo manually recover a failed compute node:% E& j1 m/ [6 \$ T8 y

& c2 P  Y4 R' J, q% H) ^( \; v  DIdentify the VMs on the affected hosts by using a combination of the openstack server list and openstack server show commands or the euca-describe-instances command.7 Z) \* p" X+ u1 U9 e
2 w0 `* A7 W5 x( G8 \3 Y+ I
For example, this command displays information about the i-000015b9 instance that runs on the np-rcc54 node:7 u: w3 \* d0 d* s

7 ^! F% T9 }6 {+ j# u2 u! h$ euca-describe-instances
1 v& Z' F* O2 f* r3 |, n  ii-000015b9 at3-ui02 running nectarkey (376, np-rcc54) 0 m1.xxlarge 2012-06-19T00:48:11.000Z 115.146.93.603 o6 z# v7 N& @0 f6 \  T
Query the Compute database for the status of the host. This example converts an EC2 API instance ID to an OpenStack ID. If you use the nova commands, you can substitute the ID directly. This example output is truncated:
0 i; m$ o; K+ a' P- {8 `; [5 z7 Q3 z3 Y0 V( r( A, R- l' p
mysql> SELECT * FROM instances WHERE id = CONV('15b9', 16, 10) \G;
( }# H2 Q6 W! v/ C. @+ K7 _*************************** 1. row ***************************9 {2 e# R6 G5 p: Q
created_at: 2012-06-19 00:48:110 p9 F3 h2 {' T/ F# ^) Y1 ~3 s- U
updated_at: 2012-07-03 00:35:11
2 {. H* W/ {9 A5 V0 K8 `: X9 y' ?6 ydeleted_at: NULL& s" s, I! @5 ]* _9 A
...
( G  L' F2 Z+ w: t5 r$ j- yid: 5561; k% j( ?( V0 X1 ~1 y4 V3 h
...
" k5 @5 _! x& \5 p( o5 j( I& G6 epower_state: 5
2 |% j+ n1 y3 l7 lvm_state: shutoff; t0 m' ]: w& r, w; \
...
4 l5 Q/ d, M1 i  jhostname: at3-ui02
' ~6 L7 l5 B0 Ihost: np-rcc544 N) x' s0 w3 o  i# C0 c& F
...
; g* B# \- F( |8 E* X# D3 S! Cuuid: 3f57699a-e773-4650-a443-b4b37eed5a06; s$ [. V* P: M4 }. L
...% a* Z% f9 n! |3 u. n6 _
task_state: NULL
4 K* `: D, f1 h: G2 c. J% @...
% \  O& w  ^+ q; O8 r6 ~Note
# R3 H9 }) J2 ~
2 y6 ^( K  h# L2 e$ FFind the credentials for your database in /etc/nova.conf file.8 _; L  \4 N/ \; J5 \3 `" ?

; o2 B4 E0 w8 H2 M! ^8 oDecide to which compute host to move the affected VM. Run this database command to move the VM to that host:
/ U6 E) F2 @$ F  t% K/ ]; n5 c3 Q5 X7 W7 J* t- p/ [2 E
mysql> UPDATE instances SET host = 'np-rcc46' WHERE uuid = '3f57699a-e773-4650-a443-b4b37eed5a06';3 d3 z, r, H( K6 I3 [
If you use a hypervisor that relies on libvirt, such as KVM, update the libvirt.xml file in /var/lib/nova/instances/[instance ID] with these changes:! M' n# _/ w( t6 i% x' u
) E. g; r& m8 ~" h
Change the DHCPSERVER value to the host IP address of the new compute host.
" r0 D/ g8 l* zUpdate the VNC IP to 0.0.0.0.' y7 T" Q: _! l7 y: f( R
Reboot the VM:$ O; m; H: u: x: h5 N8 e6 f

0 P+ i& f7 A2 S& S* K: _. v7 G( P, ]+ j$ openstack server reboot 3f57699a-e773-4650-a443-b4b37eed5a06
2 L/ g1 H+ J6 g6 C  K6 ?8 R- eTypically, the database update and openstack server reboot command recover a VM from a failed host. However, if problems persist, try one of these actions:8 n# Q+ I9 o+ u: `3 B% }

" S5 d: K( {5 y; rUse virsh to recreate the network filter configuration.
; o3 j4 |( n- G+ {5 P( LRestart Compute services.
- b1 w* G# I6 a7 [Update the vm_state and power_state fields in the Compute database.
. Y$ g- V8 a- y5 q7 zRecover from a UID/GID mismatch¶
0 S) Z' }8 K3 b7 r! f/ t; Y( W$ LSometimes when you run Compute with a shared file system or an automated configuration tool, files on your compute node might use the wrong UID or GID. This UID or GID mismatch can prevent you from running live migrations or starting virtual machines.& {, h: N% i  P% P. g% A& V9 Y

- V5 o3 T8 {) LThis procedure runs on nova-compute hosts, based on the KVM hypervisor:
: b2 L# ^9 g2 V% ]& n9 s% F3 o: T: P+ t6 h) Q
Set the nova UID to the same number in /etc/passwd on all hosts. For example, set the UID to 112.& i% I; h: U& }( w* H* Y
( D( z# @+ J* k# U* M# y# V
Note
* F* R7 P0 D* \- T# a1 \( i  l0 B* t3 Z8 r6 w' `/ h
Choose UIDs or GIDs that are not in use for other users or groups.
# F; x$ l( Z8 _0 k3 ~
% @0 d- f, A9 f7 NSet the libvirt-qemu UID to the same number in the /etc/passwd file on all hosts. For example, set the UID to 119.
. Z5 R; X+ V4 ]/ v
. i% @1 b8 s0 k# m# I3 rSet the nova group to the same number in the /etc/group file on all hosts. For example, set the group to 120.
& y: ]9 D- \3 X: Q, s& P+ V8 g
Set the libvirtd group to the same number in the /etc/group file on all hosts. For example, set the group to 119.
9 i+ W' @: _& l6 ?1 X- d; c/ P7 f  D# _3 j% N& D7 l; v. k2 y
Stop the services on the compute node.! p; d+ n6 d; ^' ]( l1 H

6 D$ |: J4 H  w8 }9 B& B3 |+ iChange all files that the nova user or group owns. For example:
/ W1 h9 ]( v6 }: z
# }% }8 @5 l) @! f' d# K# L; V# find / -uid 108 -exec chown nova {} \;
, J/ I& l. O# |+ L. j% H# note the 108 here is the old nova UID before the change1 R: m' A5 q" w& Z  D; c
# find / -gid 120 -exec chgrp nova {} \;
* N3 q( }' Q1 O4 a: IRepeat all steps for the libvirt-qemu files, if required.
3 W. ~" X2 N, u9 y' }) o8 z0 W3 O( _' h5 ~( d
Restart the services.0 k. L4 p# b+ w! f1 X7 T3 R- R

5 X4 o0 M6 j- [3 VTo verify that all files use the correct IDs, run the find command.6 ~. W* w  d$ _+ K4 t# K
8 v3 \, u& g0 o+ |* ^( T
Recover cloud after disaster¶2 C3 ?* `6 a; I& k
This section describes how to manage your cloud after a disaster and back up persistent storage volumes. Backups are mandatory, even outside of disaster scenarios.0 M/ o. e* u  z9 i4 e

2 r% S$ f+ B5 Z) |/ ^7 ?' b8 ?$ _For a definition of a disaster recovery plan (DRP), see https://en.wikipedia.org/wiki/Disaster_Recovery_Plan.
% c" x- x& ], l& Y! z# m) p  C
7 L7 m* ]0 ^) F$ nA disk crash, network loss, or power failure can affect several components in your cloud architecture. The worst disaster for a cloud is a power loss. A power loss affects these components:: Y7 U% }; K: l9 W& n
, ~0 k5 r. P# f; x- U4 q
A cloud controller (nova-api, nova-objectstore, nova-network), ~1 c9 N& k2 ]. {3 v0 S
A compute node (nova-compute)0 x  `/ }: _' E8 i/ s# B4 f
A storage area network (SAN) used by OpenStack Block Storage (cinder-volumes)
1 W5 K% D0 O3 H2 s: ]. `# wBefore a power loss:
  r" \. L3 c% H$ l7 o) f- U+ o/ f: M; c8 T' R; G! b
Create an active iSCSI session from the SAN to the cloud controller (used for the cinder-volumes LVM's VG).& l8 I- Q4 Q0 s' F4 v. E
Create an active iSCSI session from the cloud controller to the compute node (managed by cinder-volume).
4 [& h: n& n% _$ {: ECreate an iSCSI session for every volume (so 14 EBS volumes requires 14 iSCSI sessions).! |3 [9 ^( o1 r' M4 H/ H
Create iptables or ebtables rules from the cloud controller to the compute node. This allows access from the cloud controller to the running instance.( s4 _6 D8 m8 W/ R3 L
Save the current state of the database, the current state of the running instances, and the attached volumes (mount point, volume ID, volume status, etc), at least from the cloud controller to the compute node.& }' n& B3 L1 U# Z+ Z' \5 }9 S. E1 E
After power resumes and all hardware components restart:* F( N% x; `) c9 N1 r- V! y

6 j0 \# A- d" B8 q1 e& c* TThe iSCSI session from the SAN to the cloud no longer exists.# ~# b, x0 l) m0 N
( Y5 L8 z9 b% `7 ^8 X3 c# C
The iSCSI session from the cloud controller to the compute node no longer exists.; _5 l% F7 r- y

/ E& r  x& h0 O. r- r8 Nnova-network reapplies configurations on boot and, as a result, recreates the iptables and ebtables from the cloud controller to the compute node.. ?5 M2 O3 r6 N: f" g/ x
0 M! Q) b/ C9 l% d* k( P
Instances stop running./ B3 u8 k$ D, Z3 z+ L  ]! E

2 w% u' }, P2 s7 C" G! N- jInstances are not lost because neither destroy nor terminate ran. The files for the instances remain on the compute node.
, F) t5 \! V5 Q: y. w- q
9 j2 }5 i+ r, t. o" f! eThe database does not update.  t& [+ E  T6 J/ p' ]' T

6 v1 r6 m: v! W. zBegin recovery
" o1 W" j2 ]$ @3 L; \" f' o/ u; J0 R
Warning
- M, F  ]  j4 B9 I1 [' i+ A* p9 n5 a" B( w; ]9 `8 ~+ |
Do not add any steps or change the order of steps in this procedure.
7 m2 z' N+ t3 U- l2 _5 ^3 R9 U- f6 h% W' {
Check the current relationship between the volume and its instance, so that you can recreate the attachment.
( m: V7 A: Z2 J- @. B/ P+ |# Q+ r0 T. x. f
Use the openstack volume list command to get this information. Note that the openstack client can get volume information from OpenStack Block Storage.
$ V% ?  s0 Z$ F+ Q& [# s  d1 z5 S, G, N) W
Update the database to clean the stalled state. Do this for every volume by using these queries:( H/ B# l: @5 W. _; {; _3 u( ?9 y

8 l4 l+ w: ]( D( t* l1 A: p1 K8 B- j7 w. bmysql> use cinder;
3 K$ a/ T; M, \! Nmysql> update volumes set mountpoint=NULL;
1 t8 a4 l. y- k5 ?) T) Umysql> update volumes set status="available" where status <>"error_deleting";+ N# B  d& g5 f! v/ u3 o  |* ^
mysql> update volumes set attach_status="detached";
2 @- Z+ P* {! A* Q$ f% }8 Kmysql> update volumes set instance_id=0;0 l! O% f% b* I
Use openstack volume list command to list all volumes.* c3 ~5 @" T8 M; w1 {$ Y3 A
: G# o$ f" g8 [+ E+ {
Restart the instances by using the openstack server reboot INSTANCE command.
5 D1 @" o) S. k1 ]0 K  T2 r
* v3 l! r5 Q+ ^# w; N, XImportant9 Q9 Z" `- M; ?( {  {% B: [6 k9 ]

9 @. M3 _1 j# N2 {; JSome instances completely reboot and become reachable, while some might stop at the plymouth stage. This is expected behavior. DO NOT reboot a second time.
+ {' |: M) m! `7 L! b8 [. i& h/ R# a& g
Instance state at this stage depends on whether you added an /etc/fstab entry for that volume. Images built with the cloud-init package remain in a pending state, while others skip the missing volume and start. You perform this step to ask Compute to reboot every instance so that the stored state is preserved. It does not matter if not all instances come up successfully. For more information about cloud-init, see help.ubuntu.com/community/CloudInit/.
) l. z9 T" _! Y! I  z7 T  |1 s
: [6 k, @. ^, A& _, hIf required, run the openstack server add volume command to reattach the volumes to their respective instances. This example uses a file of listed volumes to reattach them:
0 Y! U6 O) O+ X0 u* c1 B) i' p% ?/ i7 h0 r* H/ T
#!/bin/bash
' Y2 q& y1 [& r, ~! a$ u6 U" l$ F" k
while read line; do5 {$ m) a% t$ v7 H9 L
    volume=`echo $line | $CUT -f 1 -d " "`
! z/ v7 p0 z# T- s* N/ ?2 _    instance=`echo $line | $CUT -f 2 -d " "`& F' C2 r5 K; {
    mount_point=`echo $line | $CUT -f 3 -d " "`" q, C! N. |  q  R: D! f
        echo "ATTACHING VOLUME FOR INSTANCE - $instance"
. ]% C2 v8 @7 x0 m" y    openstack server add volume $instance $volume $mount_point
) V* c5 Y% _, \  m0 A1 S& n    sleep 25 c$ @4 l. _' _- v; g
done < $volumes_tmp_file) j4 P0 [% k3 }5 c
Instances that were stopped at the plymouth stage now automatically continue booting and start normally. Instances that previously started successfully can now see the volume.$ {+ z& U5 O6 l" S  @  W
# ^9 R- v8 G8 x4 Q- ?* c( u
Log in to the instances with SSH and reboot them.
) g$ o# B/ y, v3 q4 n# U! p, _+ T# T' L- R4 w# M/ R
If some services depend on the volume or if a volume has an entry in fstab, you can now restart the instance. Restart directly from the instance itself and not through nova:
( x' y. X/ ?" n: x' w8 W$ t) M& ]/ r' V
# shutdown -r now
" k- K1 B" d- s' `- FWhen you plan for and complete a disaster recovery, follow these tips:
6 E( ~) u2 i4 V& m* i# w" R# y. l1 B; s) U' V
Use the errors=remount option in the fstab file to prevent data corruption.4 V& k& s1 g. v( A3 W
5 \4 P/ F4 `5 R# C/ ^
In the event of an I/O error, this option prevents writes to the disk. Add this configuration option into the cinder-volume server that performs the iSCSI connection to the SAN and into the instances' fstab files.; |% |. q% g" q# X8 }
Do not add the entry for the SAN's disks to the cinder-volume's fstab file.0 G8 ]$ ~% E/ x: t5 L9 F2 O

! V6 L  e" u7 v# b; nSome systems hang on that step, which means you could lose access to your cloud-controller. To re-run the session manually, run this command before performing the mount:2 z; W' B, M' x' [3 j( Z; s

& n" _+ a! A) |  C1 ]6 ~& `- L; V# iscsiadm -m discovery -t st -p $SAN_IP $ iscsiadm -m node --target-name $IQN -p $SAN_IP -l7 j6 o7 q/ g1 {6 T1 L* z
On your instances, if you have the whole /home/ directory on the disk, leave a user's directory with the user's bash files and the authorized_keys file instead of emptying the /home/ directory and mapping the disk on it.1 B: D8 |; H4 t/ K  G6 P
3 ^- [2 L3 R) f
This action enables you to connect to the instance without the volume attached, if you allow only connections through public keys.9 c+ ]. |( y; j) z
( C6 A5 H( n' U
To script the disaster recovery plan (DRP), use the https://github.com/Razique bash script.' ], \2 u7 _- R0 \( p6 w* o

& V5 E1 w  |3 I; D& yThis script completes these steps:' x/ e% j' N, i( a' {! t

# J2 c3 L' u$ I, U* j1 o- ]# h% cCreates an array for instances and their attached volumes.. j8 d& l" N( I# b
Updates the MySQL database.9 X/ `/ n" Z. y* P! W- j
Restarts all instances with euca2ools.
) x) W- E4 c, c" Q& MReattaches the volumes.( R- [3 e& a- _, o: g5 a8 ^3 J
Uses Compute credentials to make an SSH connection into every instance.
7 z7 e- f" B+ b% K5 W8 l: uThe script includes a test mode, which enables you to perform the sequence for only one instance.3 H" v6 C1 m4 R) X6 |% f0 `

+ ?4 p  U  m$ Q' ]To reproduce the power loss, connect to the compute node that runs that instance and close the iSCSI session. Do not detach the volume by using the openstack server remove volume command. You must manually close the iSCSI session. This example closes an iSCSI session with the number 15:. J/ z8 n: v3 M/ Z; h

2 q# d& ^3 K4 h2 h! \* b# iscsiadm -m session -u -r 15# T! X* O# B' A9 ~, |
Do not forget the -r option. Otherwise, all sessions close.
' r8 A1 y, n( f  M' m
9 g& y0 |( @. ^1 t# a+ @Warning1 x- S7 Q; h6 K  N4 n

7 b) A6 k, `+ X! Y: I8 LThere is potential for data loss while running instances during this procedure. If you are using Liberty or earlier, ensure you have the correct patch and set the options appropriately.
: V0 F/ g9 X3 ?2 O' N$ J3 T. w. |
updated: 2018-12-18 05:07
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 02:23 , Processed in 0.018950 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表