
Debian 5.0 Lenny + XEN + LVM + Routing Hetzner DS3000 Walkthrough
Introduction
Recently, I needed to transfer several sites of different clients to a normal dedicated server (not virtual). I have long been choosing where it is better to rent a server and the German company Hetzner Online and its DS 3000 tariff plan became the choice (AMD Athlon 64 X2 4200 + / 2Gb DDR / 2x160Gb HDD - as it turned out later - there were two 320 GB hard drives on the server).
But I did not want to host all on the same server. Therefore, it was decided to create virtual machines based on XEN technology (in addition to the server on the DS 3000 TP, Hetzner Online gives out 6 IP addresses for free, which will be very convenient for individual projects). On the Web, you can find a lot of information on the topic of configuring XEN itself on Debian and setting up routing on it, raising virtual machines on LVM (lvm gives faster performance than virtual machines based on image files), even the company’s wiki had information about this (but in German - Google Translate to help us). But. There was one "But." She was all scattered and in pieces. I couldn’t find a smart walkthrough for setting “from” and “to” anywhere.
Therefore, everyone who is interested in this topic,
“Server from the very beginning”
We go to https://robot.your-server.de/server , select our server and click on the “Rescue” tab, our choice will be “Linux”, “64 bit”, save the password that will be shown to us. Then go to the “Reset” tab and select “Send CTRL + ALT + DEL to the server”. 2 minutes after this, you can connect via SSH to our server at the IP address originally issued. We come in as the user "root" and the password saved earlier.
After we have successfully logged in, we will see something like this and all that is required of us is to run “installimage”:
[...] Hardware data: CPU Athlon 64 X2 Dual Core 4200+ CPU Athlon 64 X2 Dual Core 4200+ RAM 1946 MB Disk / dev / sda: 320.0 GB (=> 305 GIB) Disk / dev / sdb: 320.0 GB (=> 305 GIB) root @ rescue ~ # installimage
From the menu we select “Debian” ⇒ “Debian-50-lenny-64-minimal” (we don’t need more).
After that, we will be shown a configuration file that will guide the installation script. We need to check several lines in it, and also change some to our needs:
SWRAID 1 # check these lines - must be equal to 1! SWRAIDLEVEL 1 # check these lines - must be equal to 1! [...] HOSTNAME root.domain.com # may not be root, but it’s so convenient for me [...] PART swap swap 4G PART / ext3 10G PART / data ext3 all
In our case, we make a 4Gb swap, leave 10Gb for Dom0 (Host in XEN terminology), and give the rest to the / data directory, which will later be converted to LVM.
Ok, then we have the program: [F10], [Yes], [Yes].
Hetzner Online AG - installimage Your server will be installed now, this will take some minutes You can abort at any time with CTRL + C ... : Reading configuration done 1/13: Deleting partitions done 2/13: Creating partitions and / etc / fstab done 3/13: Creating software RAID level 1 done 4/13: Formatting partitions : formatting / dev / md0 with swap done : formatting / dev / md1 with ext3 done : formatting / dev / md2 with ext3 done 5/13: Mounting partitions done 6/13: Extracting image (local) done 7/13: Setting up network for eth0 done 8/13: Executing commands inside chroot done 9/13: Setting up miscellaneous files done 10/13: Setting root password done 11/13: Installing bootloader grub done 12/13: Running some debian specific functions done 13/13: Clearing log files done INSTALLATION COMPLETE You can now reboot and log in to your new system with the same password as you logged in to the rescue system. root @ rescue ~ #
All. We can reboot into our freshly installed system.
root @ rescue ~ # shutdown -r now
“Getting to know a new place”
After logging into the system (for which we use the “root” login and the password saved earlier), the first thing is to change the root password:
root: ~ # passwd Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Then update the system:
root: ~ # apt-get update root: ~ # apt-get dist-upgrade
LVM
Next in line: creating an LVM partition. First, let's try to install the package itself (if suddenly for some reason it was not installed, in my case everything was installed immediately):
root: ~ # apt-get install lvm2
We unmount the section created at the installation stage under LVM:
root: ~ # umount / data /
Also from the file "/ etc / fstab" we will delete the line that was responsible for mounting this section (the line that starts with "/ dev / md2").
Let's create the LVM section in its place:
root: ~ # pvcreate / dev / md2 Physical volume "/ dev / md2" successfully created
Create a group:
root: ~ # vgcreate vgvm / dev / md2 Volume group "vgvm" successfully created
“Where are the promised additional 6 IP addresses?”
Before setting up XEN, we need to get additional addresses (which are so kindly = given free by Hetzner). To do this, go again to the control panel ( https://robot.your-server.de/server , select your server and the “IP” tab). In the lower part, click on the link “Ordering of additional IP, failover IP or subnet” and order an additional subnet for our server. After some time (on weekdays from an hour and a half force), a message in two languages about the subnet and its settings will be sent to the contact email. The parameters can be something like this (we will use them in further settings):
IP: 78.46.242.?8
Mask: 255.255.255.248
Broadcast: 78.46.242.?5
(question mark - so, extra protection from prying eyes)
Install and configure XEN
Install xen itself and its environment:
root: ~ # aptitude install xen-hypervisor xen-linux-system-2.6.26-2-xen-amd64 xen-utils xenstore-utils xenwatch xen-shell xen-tools
In the file "/ etc / modules" you need to correct the line "loop":
[...] loop max_loop = 64
We fix the configuration file "/etc/xen/xend-config.sxp": comment out the lines "(network-script network-dummy)" and "(vif-script vif-bridge)", and then add (just below the commented out "(vif -script ... "):
[...] (network-script 'network-route netdev = eth0') (vif-script vif-route) [...]
In the file "/etc/xen-tools/xen-tools.conf" we will make the following changes:
[...] ## # # If you don't wish to use loopback images then you may specify an # LVM volume group here instead # ## lvm = vgvm # Here we indicate the name of the logical group that we created earlier using the "vgcreate" command [...] ## # Disk and Sizing options. ## # size = 32Gb # Disk size for default virtual machine memory = 256Mb # Default RAM swap = 1024Mb # Default swap size # noswap = 1 fs = ext3 # The file system for the partition dist = lenny # The default distribution image = sparse [...] ## # Networking setup values. ## # # Uncomment and adjust these network settings if you wish to give your # new instances static IP addresses. # gateway = 78.46.242.?9 netmask = 255.255.255.248 broadcast = 78.46.242.?5 [...] # # Uncomment the following line if you wish to interactively setup # a new root password for images. # passwd = 1 [...] # # The architecture to use when using debootstrap, rinse, or rpmstrap. # # This is most useful on 64 bit host machines, for other systems it # doesn't need to be used. # arch = amd64 [...] # # The default mirror for debootstrap to install Debian-derived distributions # mirror = http://ftp2.de.debian.org/debian/ [...] # # If you're using the lenny or later version of the Xen guest kernel you will # need to make sure that you use 'hvc0' for the guest serial device, # and 'xvdX' instead of 'sdX' for serial devices. # # You may specify the things to use here: # serial_device = hvc0 #default # serial_device = tty1 # disk_device = xvda #default # disk_device = sda [...]
In order to configure routing for XEN virtual machines, on the host machine (Dom0), we need to add another address from the given subnet to the eth0 network interface (because the initial address is in a completely different subnet, for example, my server had approximately 213.239.234.?7, and the issued subnet is 78.46.242.?8).
I used a shell script to configure the additional address, taken from here http://wertarbyte.de/debian/ifupdown/addresses . At the beginning of the script itself is README, which describes where to “put” it and what-where to write later.
But if in Russian, then you need to put it in "/etc/network/if-up.d/", calling it the same as "addresses", make link ("ln -s") in the directory "/ etc / network / if-down.d / "so that the address is removed when the server reboots, make this script executable (" chmod + x /etc/network/if-up.d/addresses "), and then in" / etc / network / interfaces " write something like the following:
[...] # device: eth0 auto eth0 iface eth0 inet static address 213.239.234.?7 broadcast 213.239.234.?1 netmask 255.255.255.248 gateway 213.239.234.?5 addresses 78.46.242.?9/29 # we added this line [...]
Now fix our sysctl.conf:
### Hetzner Online AG installimage # sysctl config net.ipv4.ip_forward = 1 net.ipv4.conf.all.rp_filter = 1 net.ipv4.icmp_echo_ignore_broadcasts = 1 net.ipv6.conf.all.forwarding = 1 net.ipv4.conf.default.proxy_arp = 1
And now we will reboot the server with the new XEN kernel and the settings made:
root: ~ # shutdown -r now
“Well, where are the virtual machines themselves?” - "Already here!"
Here, in fact, almost everything. We have come to the most important thing, the creation and launch of virtual machines.
Let's create our first virtual server and assign it a free IP address from the issued subnet:
root: ~ # xen-create-image --hostname = example --ip = 78.46.242.? 0 --memory = 512 --role = udev
When creating an image, we can reassign certain parameters, as, for example, in this case we gave our virtual server 512MB of RAM (and in the config it defaults to 256MB).
After this command 3-4 minutes will pass, you will be asked for a password with confirmation for root (not for the root of the host machine, but for root in the new virtual machine).
After that, you can start the virtual machine itself, see what it appears in the list of running ones (besides this, the amount of available RAM will immediately decrease on the Dom0 machine):
root: ~ # xm create /etc/xen/example.cfg Using config file "/etc/xen/example.cfg". Started domain example root: ~ # xm list Name ID Mem VCPUs State Time (s) Domain-0 0 1485 2 r ----- 123.3 example 1 512 1 r ----- 1.7
Now we can enter the console of this machine and begin to configure it the way we want:
root: ~ # xm console example
If the information presented in this guide is at least useful to someone, then I will be pleased. I think that I did a good job by collecting many different ones in one tutorial.
The English version will be located here: wiki.summercode.com