📜 ⬆️ ⬇️

Debian 5.0 Lenny + XEN + LVM + Routing Step-by-Step Installation Guide on Hetzner DS3000

Introduction


Recently, I needed to transfer several sites of different clients to a normal dedicated server (not virtual). I have long been choosing where to rent the server and the choice was the German company Hetzner Online and its DS 3000 tariff plan (AMD Athlon 64 X2 4200 + / 2Gb DDR / 2x160Gb HDD - as it turned out later - there were two 320GB hard drives on the server).

But I did not want to host all on the same server. Therefore, it was decided to make virtual machines based on XEN technology (besides, in addition to the server on the DS DS 3000 Hetzner Online, it issues 6 IP addresses that will look very convenient for individual projects). On the Web, you can find a lot of information on the configuration topic and XEN itself on Debian and setting up routing on it, raising virtual machines on LVM (lvm gives you more speed than virtual files based on image files), even on the company’s wiki itself about this (but in German - Google Translate help us). But. There was one "But." She was all scattered and in pieces. I could not find an intelligent step-by-step guide for setting “from” and “to” anywhere.

Therefore, to all who are interested in this topic,

"Server from the 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”, we will save the password, which will be shown to us. Then go to the “Reset” tab and select “Send CTRL + ALT + DEL to the server”. After 2 minutes after that, you can connect via SSH to our server using the IP address that was originally issued. Log in as the “root” user and previously saved password.
')
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 will 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 to change some for 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 convenient for me 
 [...] 
 PART swap swap 4G 
 PART / ext3 10G 
 PART / data ext3 all

In our case, we do 4Gb swap, 10Gb is left for Dom0 (Host in XEN terminology), and all the rest is given 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 
              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 log in to your new system with 
   the same password as you logged in to the rescue system. 
 root @ rescue ~ #

Everything. We can reboot into our freshly installed system.

 root @ rescue ~ # shutdown -r now

“Getting used to a new place”


After logging in to the system (for which we use the login “root” and the previously saved password), the first step 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. To begin with, we will try to install the package itself (if suddenly for some reason it was not installed, in my case everything was installed right away):

 root: ~ # apt-get install lvm2

Unmount the LVM section created during the installation:

 root: ~ # umount / data /

Also from the file "/ etc / fstab" delete the line that was responsible for mounting this section (the line that starts with "/ dev / md2").

Create in its place a section LVM:

 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 6 additional IP addresses?”


Before setting up XEN, we need to get additional addresses (which are so kindly = given out for free by Hetzner). To do this, go back to the control panel ( https://robot.your-server.de/server , select your server and the “IP” tab). At the bottom, 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 or so), a message in two languages ​​will fall on the contact email stating that the subnet is highlighted and its parameters. Parameters can be approximately the same (we will use them in the further configuration):

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 the 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

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 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 want to specify 
 # LVM volume group here instead 
 # 
 ## 
 lvm = vgvm # Here we specify the name of the logical group that we created earlier with the command "vgcreate"

 [...] 

 ## 
 # Disk and Sizing options. 
 ## 
 # 
 size = 32Gb # The default disk size for the virtual machine.
 memory = 256Mb # Default RAM 
 swap = 1024Mb # Default swap size
 # noswap = 1
 fs = ext3 # File system for partition
 dist = lenny # Default distribution
 image = sparse

 [...] 

 ## 
 # Networking setup values. 
 ## 

 # 
 # Uncomment and adjust your network settings 
 # 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 want to interactively setup 
 # a new root password for images. 
 # 
 passwd = 1 

 [...] 

 # 
 # The architecture to use when using debootstrap, rinse, or rpmstrap. 
 # 
 # This is the most useful it’s 
 # 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’ve been using the Xen guest kernel you will 
 # need to make sure you use the hvc0 for the guest serial device, 
 # and 'xvdX' instead of 'sdX' for serial devices. 
 # 
 # You may want to specify here: 
 # 
 serial_device = hvc0 #default 
 # serial_device = tty1 
 # 
 disk_device = xvda #default 
 # disk_device = sda 

 [...]

In order to configure routing for XEN virtual machines, we need to add another address from the issued subnet to the eth0 network interface on the host machine (because the initial address is completely different, for example, my server had approximately like 213.239.234.?7, and the issued subnet is 78.46.242.?8).

To set up an additional address, I used a shell script, taken from here http://wertarbyte.de/debian/ifupdown/addresses . At the beginning of the script itself there is a README, which describes where to put it and what to write next.

But if in Russian, then you need to put it in "/etc/network/if-up.d/", calling the same way - "addresses", make the link ("ln -s") in the directory "/ etc / network / if-down.d / "to remove the address when the server restarts, make this script executable (“ chmod + x /etc/network/if-up.d/addresses ”), and then in“ / etc / network / interfaces ” write something like this:

 [...]
 # 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 restart the server with the new XEN-core and the settings made:

 root: ~ # shutdown -r now

“Well, where are the virtual machines themselves?” - “Already here!”


Here, in fact, almost everything. We 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 is 256MB by default).

After this command, it will take 3-4 minutes, you will be asked for a password with confirmation for root (not for the root of the host machine, but for root on the new virtual machine).

After that, you can start the virtual machine itself, see what it appeared in the list of running (besides, the amount of available RAM on the Dom0-machine will immediately decrease):

 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 log in to the console of this machine and start configuring it the way we want it to:

 root: ~ # xm console example

If the information presented in this guide proves to be useful to anyone, I would be pleased. I think that I did a good job, having collected many different ones in one tutorial.

The English version will be located here: wiki.summercode.com

Source: https://habr.com/ru/post/83656/


All Articles