Javi

AWS: create RAID1+0 disk with four EBS volumes

Aug 22nd, 2013
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #RAID under linux summary: http://www.ducea.com/2009/03/08/mdadm-cheat-sheet/
  2. #RAID with EC2: http://bruun.co/2012/06/06/software-raid-on-ec2-with-mdadm
  3. #Why RAID10 instead of RAID0: http://blog.9minutesnooze.com/raid-10-ebs-data/
  4. #EBS durability: http://aws.amazon.com/ebs/ (durability section, between 0.1% and 0.5% Anual Failure Rate)
  5.  
  6. #Initial situation:
  7. #root: dev/sda1
  8. #ebs volumes (1GBx4): /dev/sdb /dev/sdc /dev/sdd /dev/sde
  9.  
  10. #Script to create and test RAID10:
  11.  
  12. #Show devices
  13. ls -l /dev/sd* /dev/xv*
  14.  
  15. #Avoid race lock
  16. sudo udevadm control --stop-exec-queue
  17. #Create RAID
  18. sudo mdadm --create /dev/md0 --run --level=10 --raid-devices=4 --chunk=64 /dev/sdb /dev/sdc /dev/sdd /dev/sde
  19. sudo udevadm control --start-exec-queue
  20.  
  21. #Now there's an entry under /dev/md/* with the name of the device, for example /dev/md/ip-10-251-94-61:0
  22. #Use it to update the /etc/fstab file adding a line like this one:
  23. #/dev/md/ip-10-251-94-61:0 /media/ebs xfs defaults 0 0
  24.  
  25. #prewarm with 0s
  26. sudo time shred -vfz -n 0 /dev/md0
  27.  
  28. sudo yum install -y xfsprogs
  29.  
  30. #Format and mount
  31. #BTW, in order to freeze the fs for backups see the xfs_freeze command
  32. sudo mkdir -p /media/ebs
  33. sudo mkfs.xfs /dev/md0 -f
  34. sudo mount -t xfs /dev/md0 /media/ebs
  35. sudo chown ec2-user:ec2-user /media/ebs/
  36.  
  37. #show available space
  38. df -h
  39.  
  40. #Get 821.7 megabytes of data:
  41. cd /media/ebs
  42. wget http://dumps.wikimedia.org/eswiki/20120906/eswiki-20120906-abstract.xml
  43. head eswiki-20120906-abstract.xml
  44.  
  45. #status (U means it's OK, F means it's in failed status)
  46. cat /proc/mdstat
  47. #alternative
  48. mdadm --detail /dev/md0
  49.  
  50. #mark a volume as failed:
  51. sudo mdadm --fail /dev/md0 /dev/sdc
  52. sudo mdadm --remove /dev/md0 /dev/sdc
  53.  
  54. #Now is safe to detach de volume (using the ec2 console)
  55.  
  56. #Check it's still working
  57. cp eswiki-20120906-abstract.xml eswiki-20120906-abstract2.xml
  58.  
  59. #Create another volume (or reattach the old one) with the name /dev/sdx
  60.  
  61. #Add the new volume
  62. sudo mdadm --add /dev/md0 /dev/sdx
  63. #A mdadm --detail should indicate all four disk are available and in clean state after a while
  64.  
  65. #In case you cannot access de device after a reboot:
  66. sudo mdadm --stop --scan
  67. sudo mdadm --assemble --scan
  68. sudo mount /dev/md0 ebs
Advertisement
Add Comment
Please, Sign In to add comment