How to replace a Amazon EC2 instance with a new instance without removing tomcat7
, mysql
and other setting done on the instance?
How to replace an Amazon EC2 instance with a new one?
Asked Answered
Simple:
- Stop the instance.
- Detach the volume(s) - if you just have one volume (the boot volume) detach that.
- Take a snapshot of the volume(s) for safekeeping (not strictly necessary in this case, but no-one ever got fired for taking backups of critical systems).
- Terminate the instance.
- Spin-up a new instance of the desired type (must be the same platform, i.e. x86 or x64, as the original).
- Wait until it's running, then stop it.
- Detach its' volume and delete it.
- Attach your original volumes to it (the boot volume must be /dev/sda1).
- Restart the new instance and re-assign Elastic IP if appropriate.
Then you can't do it - the boot volume has a loader specific to the architecture, so an x86 boot volume will not work with an x64 instance type, and vice-versa. The best you can do is detach any data volumes (which are platform-independent) and attach those to the new instance to preserve working data - but any software you've installed on the old instance will need to be re-installed on the new one (although you could attach the old boot volume as a data volume to track what needs installing, copy configs, etc). –
Dehydrate
you can modify an instance's type - you don't need to do the detaching/reattaching dance. You still have the x86/x64 issue obviously –
Luxuriate
@FrederickCheung You mean say there is an alternative to the answer submitted by Jonners. If yes, it will be great if you could explain, as an answer. Thanks. –
Gilson
The OP didn't ask about changing the type - the question asks how to replace an instance with another. A typical reason for doing this is if AWS pops an Event alert stating that an instance is running on degraded hardware and will be terminated (I had just this situation yesterday). In this case, you need to kill the endangered instance and spin-up a new one on good hardware, so transferring volumes this way is the only way to 'clone' the VM. –
Dehydrate
@darkcrow - using the 'Change Type' function in the AWS console does not allow you to switch from x86 to x64, and neither does it create a new instance - it simply alters the instance profile, e.g. from Small to Medium. –
Dehydrate
@Jonners if you get an Event Alert on your instance, and it is EBS backed, all you must do is restart the instance and it will be on new hardware, no need to go through this process. –
Fionafionna
@KevinWillock I have done that in the past - perhaps I was just unlucky, because the instance restarted on the same degraded hardware (or maybe another cluster that was also degraded). It may therefore have been a race condition, and by the time I'd cloned the instance I got allocated to a new cluster anyway. Possibly depends on how busy the AZ is... Still, good to mention it - I'll try that again next time. –
Dehydrate
© 2022 - 2024 — McMap. All rights reserved.
x86
and new instance has to bex64
? – Gilson