- 积分
- 16840
在线时间 小时
最后登录1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?开始注册
x
Recover from a failed compute node" b, C0 y$ H/ X& ]
updated: 2018-12-18 05:07
. [9 G# K" G0 y2 T; LRecover from a failed compute node¶
4 x; [( G( p8 }8 ?' X* r, wIf 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.
# D: T+ n4 u! g" n6 r/ m3 s6 r7 y5 r) o+ \$ B$ a9 {
Evacuate instances¶# U2 T) E) j, l5 _- t8 r# S1 T
If 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.
9 o" _! }& a( t( D4 i" w7 H4 Q' s' w: G
Manual recovery¶
+ O7 |3 \' O7 S/ A% |- CTo manually recover a failed compute node:
3 r$ i g: M- I5 `' R$ ^$ H7 r9 U4 C- s# O2 y# ^/ E& C) G% q d8 M5 ~
Identify 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.6 } A: j, R$ ~3 l/ t9 ~
- P1 z8 v5 Y% G8 l5 zFor example, this command displays information about the i-000015b9 instance that runs on the np-rcc54 node:
% g# a5 S y3 i; Y( o ~: o& [2 M T3 n# B4 w( R' v
$ euca-describe-instances% }' O; Z( K$ f' n( S7 L' S
i-000015b9 at3-ui02 running nectarkey (376, np-rcc54) 0 m1.xxlarge 2012-06-19T00:48:11.000Z 115.146.93.60: \; H! T5 I3 J3 e; i
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:( Q6 ~8 F5 Q; V. i+ A7 y3 S
/ ^4 z0 S/ Y6 Z+ |/ S5 b
mysql> SELECT * FROM instances WHERE id = CONV('15b9', 16, 10) \G;
; b C5 K$ q8 P; X9 s*************************** 1. row ***************************/ Y- Z' F. v/ H' `" ^/ a
created_at: 2012-06-19 00:48:11
! t) l. U% j' {; ^- P6 Cupdated_at: 2012-07-03 00:35:11& U1 c3 W$ x! X6 @1 F
deleted_at: NULL
8 Q0 X& J6 M) Z$ r' @ [& d# ?...8 X, m( l) i0 P& {1 m- r; B8 Y9 k; j
id: 5561
7 Y) z6 ~3 K$ e$ q/ Q0 F...
9 h. W3 ^4 M2 W$ O! d' fpower_state: 5
1 \8 f" L5 _3 x+ L0 X1 [vm_state: shutoff
& i6 ~" C& r6 b( l! O. Q...
8 A P0 j+ _$ W- V/ |hostname: at3-ui02
& n/ V% C# A' @1 f8 ]8 S4 Bhost: np-rcc54
% G' H9 s5 }7 J; `6 |+ I% K...
- d3 j7 x$ N/ }! i' _uuid: 3f57699a-e773-4650-a443-b4b37eed5a06
8 D0 {$ \, P# I2 Z4 I2 z2 D* c/ n...0 U' @7 } d G( B
task_state: NULL
/ _) D- Y1 I% e; F' \- E1 G% U...
7 u; e5 C2 m& `8 {Note
* U, i- B' F0 o) p) Q* k
# m7 ]/ O3 k f' j* iFind the credentials for your database in /etc/nova.conf file.
, I& [7 r q& e2 k0 L A/ J# R2 C) ?- A
Decide to which compute host to move the affected VM. Run this database command to move the VM to that host:, A# E4 X8 M, f3 u
6 B/ G8 G# ~# s1 F) S2 ~mysql> UPDATE instances SET host = 'np-rcc46' WHERE uuid = '3f57699a-e773-4650-a443-b4b37eed5a06';
: f) X. f+ U. n8 @8 |7 dIf 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:
: h- ~ o2 B2 c. ^
1 M) B7 G1 q1 N3 z2 I# mChange the DHCPSERVER value to the host IP address of the new compute host.4 D3 S" z5 f3 z
Update the VNC IP to 0.0.0.0.1 H/ g; i# [, n7 H! o* \/ ?5 P
Reboot the VM:
$ c2 R$ h6 ~( }4 p/ s F! Y: a7 K: k+ g( J8 I2 q& L* z3 u
$ openstack server reboot 3f57699a-e773-4650-a443-b4b37eed5a06
7 g/ }( [ m1 R4 F/ gTypically, the database update and openstack server reboot command recover a VM from a failed host. However, if problems persist, try one of these actions:0 u* M/ y! G& S; j( v
5 }% h: p+ v- Q7 ?: a" FUse virsh to recreate the network filter configuration.7 s0 @9 S8 ^9 [6 C5 O; m
Restart Compute services.
1 j! N) L" [& E' U1 q6 B9 PUpdate the vm_state and power_state fields in the Compute database.
4 M. o6 u Q" `, B; W0 LRecover from a UID/GID mismatch¶; _0 z- R: H+ f8 b- y
Sometimes 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.+ G& J/ o$ E% ^+ W4 Q
: R) _) j! f" N2 K9 d d8 O
This procedure runs on nova-compute hosts, based on the KVM hypervisor:7 C: C( j! c4 w& T
9 R8 E4 G$ |( R4 b. m* kSet the nova UID to the same number in /etc/passwd on all hosts. For example, set the UID to 112.- c1 u1 _# a- N6 w
( V2 z; k$ g2 [) {7 y& INote/ s6 c. f) s5 T' m- g3 \& O8 c
+ j g; g! P3 E( x0 M6 l5 xChoose UIDs or GIDs that are not in use for other users or groups.( n% y7 p% }9 [+ ^) R3 F
5 V/ z" @; r- u! ~2 y
Set the libvirt-qemu UID to the same number in the /etc/passwd file on all hosts. For example, set the UID to 119.
* X* @1 C0 c2 g5 o7 q2 F
4 O9 s l% X( q' e. DSet the nova group to the same number in the /etc/group file on all hosts. For example, set the group to 120.6 s4 o4 e+ m: Z X4 l3 n
, p; n( Q) G6 j* g2 fSet the libvirtd group to the same number in the /etc/group file on all hosts. For example, set the group to 119.5 P. V/ Y8 f. |7 H3 y) h# _
' l) y1 B* Z8 I9 o$ y6 @, w |, YStop the services on the compute node.
. \$ C" e g2 D6 Q6 I6 A) P' j1 O, k2 Q
Change all files that the nova user or group owns. For example:
+ `4 A c- e, |& E) D; X6 f; h O; n* l9 Q# n
# find / -uid 108 -exec chown nova {} \;' q9 K; E' b8 m( i+ F7 P- b! A
# note the 108 here is the old nova UID before the change* I- t$ r; h7 s8 u4 F
# find / -gid 120 -exec chgrp nova {} \;% p- T& M- _8 ?5 n9 x- _4 I- ^# W
Repeat all steps for the libvirt-qemu files, if required.! r. c m1 D5 @* G* r7 A1 a# ]
8 i. ~2 @; [. n& t
Restart the services.
+ H! v |" K8 w) O* P- Y4 @+ P4 j3 S
To verify that all files use the correct IDs, run the find command.; V$ L, \7 d5 ]+ F
9 r$ W% J) Y+ B/ g
Recover cloud after disaster¶# K- }4 S% d% K2 f, \& t- z
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.
' c! a& U) ]# J4 a8 K
5 t7 t2 ]- f' B% g) x; P: ~For a definition of a disaster recovery plan (DRP), see https://en.wikipedia.org/wiki/Disaster_Recovery_Plan.
2 h: p* E& |* m* c+ c
, ]$ R5 a" _7 p- jA 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:
- b* Y K2 x+ x* Q* E3 T: N5 C5 j: _% k
A cloud controller (nova-api, nova-objectstore, nova-network)
6 e* c. h: r3 F0 T* o- }A compute node (nova-compute)
9 z0 x& Y' L1 B) \; p W. Q. ]9 TA storage area network (SAN) used by OpenStack Block Storage (cinder-volumes)1 W, Q! Y! _7 U
Before a power loss:; F' E' n" ~% z! U: G
$ h# k" q* e% q3 JCreate an active iSCSI session from the SAN to the cloud controller (used for the cinder-volumes LVM's VG).* {# ~. D/ {) J: m" @" @7 W0 n. f
Create an active iSCSI session from the cloud controller to the compute node (managed by cinder-volume).
) N; S1 v1 @- b9 z& FCreate an iSCSI session for every volume (so 14 EBS volumes requires 14 iSCSI sessions).# O3 q, j ]9 G0 u; A3 f4 M
Create iptables or ebtables rules from the cloud controller to the compute node. This allows access from the cloud controller to the running instance.9 u/ x1 F# ^1 E% X1 j4 k
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.3 n2 f; Z" n I6 l
After power resumes and all hardware components restart:- F+ C% x: e5 g, E7 q
5 D* U# f$ Y& J- \/ H) |. w
The iSCSI session from the SAN to the cloud no longer exists.
% f' d3 l0 h- J' T" J0 ~# S4 }
6 R3 C' z/ K* l' qThe iSCSI session from the cloud controller to the compute node no longer exists.* P3 H; S8 y! T8 \3 J
+ R3 g2 S$ D- }# X5 F0 W0 Qnova-network reapplies configurations on boot and, as a result, recreates the iptables and ebtables from the cloud controller to the compute node.
3 T7 F( W" u$ f& i$ h+ r. e
$ E! b7 z2 k9 N3 ~Instances stop running.4 W. W, C$ b, a- U
* Z! T, k4 U+ e7 P d. O5 O* O
Instances are not lost because neither destroy nor terminate ran. The files for the instances remain on the compute node.
: h. c2 a' _; D% g! X) K6 T9 K3 l' G. b6 i7 y8 Y
The database does not update.
0 i1 K3 M) _, ]% t# r) b% b {, t, c% f' S( D( A% d, X
Begin recovery
; ?8 G& G6 Z( O
7 Q& r& d! r0 j- @# x/ `3 Q& PWarning
3 b4 |& P3 M. @8 I9 E6 }) [, H: t$ G; t
Do not add any steps or change the order of steps in this procedure.! W! P- p2 L" p, N
5 e& ]! M. `, ]- l- k7 p3 _1 jCheck the current relationship between the volume and its instance, so that you can recreate the attachment.% e0 x/ R7 u! t$ B. a" c
7 i1 R* @/ n5 O7 k: X! QUse the openstack volume list command to get this information. Note that the openstack client can get volume information from OpenStack Block Storage.
; N% C& d8 q& p, _& r: }( s* [
7 \9 P% \! k# B+ V7 @" {( cUpdate the database to clean the stalled state. Do this for every volume by using these queries:
0 t+ N3 N4 |! B9 Y, x4 a3 \* P3 ?) T/ m
mysql> use cinder;
{( @3 ]' A- Z! ^mysql> update volumes set mountpoint=NULL;
0 s+ b# l0 K" y2 J& M" a/ omysql> update volumes set status="available" where status <>"error_deleting";
4 j& |$ Y2 p) E# d$ s1 t4 o9 qmysql> update volumes set attach_status="detached";
& G3 |2 L9 y' c) cmysql> update volumes set instance_id=0;
6 R# r l/ K$ {; @0 LUse openstack volume list command to list all volumes.
& g$ w& x9 @( Y' p; `7 i4 M* z: J/ X7 |, G: @ Y
Restart the instances by using the openstack server reboot INSTANCE command.
* F" R+ |' { W' E4 Y3 h! |% d' z2 K0 ~
Important
! J1 @4 o' m5 P2 m& X7 G, \/ x: }. Q: t$ t3 Y0 h( W% z0 i
Some instances completely reboot and become reachable, while some might stop at the plymouth stage. This is expected behavior. DO NOT reboot a second time.
M4 u; D( N6 ~+ t
^+ c( k r1 yInstance 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/.
5 M1 J9 p/ \; I. P# f% X. ?" q
1 r; P3 J* M3 D% L1 Z# V6 G' k) xIf 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:. q) z7 r& P; ]6 z/ s
1 M7 w S) _* @+ d: U; H#!/bin/bash2 b- s2 R: ? v( \6 Y& S" \, p
# C: X9 o! _5 ?+ K6 z( q; vwhile read line; do
' Z4 j1 X2 ~, i% ^! l/ b& w; G volume=`echo $line | $CUT -f 1 -d " "`' a! m: r( U, ^
instance=`echo $line | $CUT -f 2 -d " "`, w7 B+ T5 m' O I; z; _
mount_point=`echo $line | $CUT -f 3 -d " "`
3 J+ p% K. |+ Y/ Z$ ] echo "ATTACHING VOLUME FOR INSTANCE - $instance"
5 f$ O4 P- O5 i+ |: I7 n+ B openstack server add volume $instance $volume $mount_point& K* j' s" h9 X" F2 L9 Q) p; F7 ~
sleep 2
( }7 ^2 g) d! O9 Udone < $volumes_tmp_file7 D: A8 G0 ^( y6 \3 {
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.& Q% D8 ]8 c1 B
! D& n1 W4 ^/ W. wLog in to the instances with SSH and reboot them.4 x3 w# z0 N- q p) ^& C
7 s/ k! d( a S1 w0 \" I5 s6 nIf 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:+ Y! Z+ y8 ^- Y# E
- |; K8 r0 r; U, }* C, s
# shutdown -r now
- g- `$ I' O) y( q! Q- i$ ~When you plan for and complete a disaster recovery, follow these tips:
3 g8 X5 i7 w/ ]9 k
/ _* y3 }8 R. o; p/ Y) VUse the errors=remount option in the fstab file to prevent data corruption.
3 E" |" Z2 E8 _8 ^ }" a8 E( J7 A& ]' \' X" f
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.! k; H: r8 w! j1 }9 C/ J
Do not add the entry for the SAN's disks to the cinder-volume's fstab file.
8 D; D2 Y* E8 d( ~5 G# g+ ?4 g& [( p! m4 g
Some 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:
1 E/ T& O" Z! R/ s* Q: o
6 ?, ?/ `+ y: O9 _$ {4 T# a8 [# iscsiadm -m discovery -t st -p $SAN_IP $ iscsiadm -m node --target-name $IQN -p $SAN_IP -l
, K- C, U% Q7 h) w, h1 MOn 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.
[7 X4 q; k% s% g; I9 v1 M! G9 a" X( D6 D" L( @: _: U$ i( [
This action enables you to connect to the instance without the volume attached, if you allow only connections through public keys.( t ~( d6 N' H
8 S5 I8 X* z A. x) k- n
To script the disaster recovery plan (DRP), use the https://github.com/Razique bash script.
2 \6 c% F5 G) Y& p p$ I9 o
d" P" D9 d$ \7 k" mThis script completes these steps:
* o8 K* l5 v+ H! Q4 n
# m& p2 f4 k: y% K- r3 Y, B0 JCreates an array for instances and their attached volumes.
0 q5 k# C6 c* ]; }Updates the MySQL database.
& T3 x% }2 U& I7 tRestarts all instances with euca2ools.
) f' `# S) I* X* c6 C8 ]1 dReattaches the volumes.
$ D5 A* D7 G- S/ p$ V7 hUses Compute credentials to make an SSH connection into every instance.' k+ j/ H% Q$ q0 o
The script includes a test mode, which enables you to perform the sequence for only one instance.
- F& D7 P8 C0 ?* ^# u/ P4 Z c- M7 `
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:9 [. W$ `( l: r o8 u
) F7 S; F$ o2 v0 ~& h7 o$ K( ?: R# iscsiadm -m session -u -r 15
1 b( y9 n& u" V0 E9 vDo not forget the -r option. Otherwise, all sessions close.& K2 p7 S& r2 P+ S( N2 b; L
2 U& E$ }2 k/ B3 a
Warning. q+ B% S1 [1 D: i# t% ^+ B
4 q5 P! H6 Z5 g" K5 ?) g9 MThere 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.
; F4 N: e- ~) k! I' R+ x' M+ M% Q8 F9 k' ^5 a& E
updated: 2018-12-18 05:07 |
|