How to: Set up a few virtual servers on your desktop
This is an attempt at a how-to for getting a few servers up and running that can talk to each other as well as with your host desktop machine all with vitrtualization. This has been a personal desire for some time and I have read documentation about how to do this and have tried multiple times, and every time it seems that the job is complex and error prone. So this how-to will describe how I finally was able to get it working with almost no effort! Yeah!
First of all, let's set the scene and give ourselves a goal: We want to have a VM web server and a VM database server running on our desktop that runs a simple web application. The two machines need to talk to each other. And we want to be able to open our desktop web browser and access the web application running on these VMs. And do all that without any complex configuration or breaking your desktop's network settings.
The first thing we will use in this setup is VirtualBox (http://www.virtualbox.org/)
First of all, let's set the scene and give ourselves a goal: We want to have a VM web server and a VM database server running on our desktop that runs a simple web application. The two machines need to talk to each other. And we want to be able to open our desktop web browser and access the web application running on these VMs. And do all that without any complex configuration or breaking your desktop's network settings.
The first thing we will use in this setup is VirtualBox (http://www.virtualbox.org/)
There are packages of VirtualBox for many linux distrobutions, or you can download it from their site. The key to this how-to is to make sure you get the latest version. The latest at the time of this writing, and which I am using is 2.1.0. This version "fixes" the complexities of virtual networking.
Once that is downloaded and installed, fire it up. Next we'll need to create 2 virtual machines. This process is pretty simple. You will need the install disc(s) for your desired OS. I like CentOS for servers because I am used to administering RHEL at work. You can use real CDs or DVDs through your computer's CDROM drive, or you can use ISO images on your hard drive. Either will work. As you go through the wizard for creating the virtual machine, it will ask mainly about the OS and have you set up a virtual hard drive. After you've done all that, select the machine in the list and click on Settings.
Select "Network" in the list on the left.

For the drop down "Attatched to", select Host Interface. You should see at least one of your desktop's interfaces in the list below. Mine says wlan0, because I am only on wireless at the moment- so my virtual servers share my wireless network interface.
Go through the rest of the setup and save your VM's coinfig. Make sure that you either mount the ISO for your install or that you enable the CDROM to access your install disc. Now boot up your machine and go through the install process using your OS' install process. This shouldn't be too tough for you.
That's pretty much it. When it comes time in your OS' install for you to configure the networking for your server, leave them set for DHCP, they will go out to the same DHCP server that your desktop uses, Cool eh?
Now after all these steps, you should have a completed VM with the OS installed. When it boots for the first time after all the install stuff is done, log into the VM and find out what the VM's ip address is. Usually ifconfig will do the trick.
Now, from your desktop open up a terminal and ping that IP. Bingo! One thing to remember- your VM is like any other machine on your network now and just was freshly installed. There maybe a default firewall or SE linux setup that will need some adjustment to allow access to it. I generally turn off both SE linux and iptables on my VMs since they are playgrounds anyway and I'm not too concerned with them.
You should be able to ssh to root@ your VM's ip address from your desktop and get in. Once you have installed and configured your web server you should be able to point your desktop's web browser to your VM's ip address too! Cool huh?
Now go through the process of creating another VM and get it up and running like the other one. Yes, you can have more than one running at a time. And yes, they can all use Host Interface networking. Once you've got 2 machines up and running, find out what each one's ip address is and see if they can ping each other.
They should be able to see and talk to each other as well as see and talk to your desktop all as if they were each separate real machines all on the same DHCP network!
I also keep things a little simplified by hacking at my desktop's /etc/hosts and manually add enties for my VM's and give them names. That way I can use names for my VM's in ssh and in my browser. The only problem with this is that I have to check the ip addresses each time I start everything up again. But that's not that big a deal.
Once that is downloaded and installed, fire it up. Next we'll need to create 2 virtual machines. This process is pretty simple. You will need the install disc(s) for your desired OS. I like CentOS for servers because I am used to administering RHEL at work. You can use real CDs or DVDs through your computer's CDROM drive, or you can use ISO images on your hard drive. Either will work. As you go through the wizard for creating the virtual machine, it will ask mainly about the OS and have you set up a virtual hard drive. After you've done all that, select the machine in the list and click on Settings.
Select "Network" in the list on the left.
For the drop down "Attatched to", select Host Interface. You should see at least one of your desktop's interfaces in the list below. Mine says wlan0, because I am only on wireless at the moment- so my virtual servers share my wireless network interface.
Go through the rest of the setup and save your VM's coinfig. Make sure that you either mount the ISO for your install or that you enable the CDROM to access your install disc. Now boot up your machine and go through the install process using your OS' install process. This shouldn't be too tough for you.
That's pretty much it. When it comes time in your OS' install for you to configure the networking for your server, leave them set for DHCP, they will go out to the same DHCP server that your desktop uses, Cool eh?
Now after all these steps, you should have a completed VM with the OS installed. When it boots for the first time after all the install stuff is done, log into the VM and find out what the VM's ip address is. Usually ifconfig will do the trick.
Now, from your desktop open up a terminal and ping that IP. Bingo! One thing to remember- your VM is like any other machine on your network now and just was freshly installed. There maybe a default firewall or SE linux setup that will need some adjustment to allow access to it. I generally turn off both SE linux and iptables on my VMs since they are playgrounds anyway and I'm not too concerned with them.
You should be able to ssh to root@ your VM's ip address from your desktop and get in. Once you have installed and configured your web server you should be able to point your desktop's web browser to your VM's ip address too! Cool huh?
Now go through the process of creating another VM and get it up and running like the other one. Yes, you can have more than one running at a time. And yes, they can all use Host Interface networking. Once you've got 2 machines up and running, find out what each one's ip address is and see if they can ping each other.
They should be able to see and talk to each other as well as see and talk to your desktop all as if they were each separate real machines all on the same DHCP network!
I also keep things a little simplified by hacking at my desktop's /etc/hosts and manually add enties for my VM's and give them names. That way I can use names for my VM's in ssh and in my browser. The only problem with this is that I have to check the ip addresses each time I start everything up again. But that's not that big a deal.
0 TrackBacks
Listed below are links to blogs that reference this entry: How to: Set up a few virtual servers on your desktop.
TrackBack URL for this entry: http://spencerchristensen.com/mt/mt-tb.cgi/13

Leave a comment