To me it is important to have a sustainable server startegy that will allow me to move my environment from server to server quickly. What is more everyone needs a new machine with exactly same set of attributes. It usually takes a good hour to set up everything without virtualization and the problem gets bigger and bigger the more your traffic increases.
What I use for a small protals is usually LXC. It is very lightweight, you can have 2 or more virtual containers on one machine and still access all files connecting to the parent machine via SSH or a program like winSCP.
To create/destroy LXC container
sudo lxc-create -t user -n C1 sudo lxc-destroy -n C1
To clone existing container
sudo lxc-clone -o C1 -n C2
Files created in container C1 in directory /home/user are then visible on a host machine in var/lib/lxc/CN/rootfs/home/user/, which is very convenient.
To start your container
sudo lxc-start -n C1 -d
If you want to start a container and connect to it immediately run:
sudo lxc-start -n C1
sudo lxc-ls returns the container in a second line it means that it’s been run and you can connect to it. There’s two methods to do that:
ssh <container's IP>– you need to check your IP using ifconfig when being in a container
sudo lxc-console -n C1
To stop existing container:
sudo lxc-stop -n C1
For reference how to rename your containers: http://www.bonusbits.com/main/HowTo:Rename_LXC_Container
Now the interesting part, to move your conatiner to another host you’ll most like do something like
lxc-create -n <new container>
rsync -avzr [old host:]"/var/lib/lxc/<old container>/*" [<new host>:]/var/lib/lxc/<new container>/ --exclude 'home/ubuntu/instance/' --exclude 'home/ubuntu/build/' --exclude 'nohup.out' --exclude "*.log*"
@rsync -avzr [old host:]/data/lxc/<old container>/rootfs/home/ubuntu/code/.metadata [<new host>:]/var/lib/lxc/<new container>/rootfs/home/ubuntu/code/
- in file
[<new host>:]/var/lib/lxc/<new container>/configchange all occurences of <old container> to <new container>, add bew IP and new hwaddr
- in file
[<new host>:]/var/lib/lxc/<new container>/rootfs/etc/hostnamezmień <old container> to <new container>
- in file
[<new host>:]/var/lib/lxc/<new container>/rootfs/etc/hostschange <old container> to <new container>
- in file
[<new host>:]/etc/hostsadd an entry <new container>
lxc-start -n <new container>
- Add a file to autostart on host:
ln -s /var/lib/lxc/<new container>/config /etc/lxc/auto/<new container>.conf
- If you want to forward any port (most likely 25) run
iptables -t nat -A PREROUTING -p tcp --dport 25 -j DNAT --to-destination <container's ip>:25.
If you're using any load balancing on nginx add this to your config on load-balancer:/etc/nginx/sites-enabled/routing
Command lists and a guide: https://help.ubuntu.com/12.10/serverguide/lxc.html
Introduction link: https://www.ibm.com/developerworks/linux/library/l-lxc-containers/