Quantcast
Channel: More Mind Spew-age from Harold Spencer Jr. » cloud images
Viewing all articles
Browse latest Browse all 2

Zen Load Balancer + Eucalyptus == Open Source Load Balancer Appliance in the Cloud

$
0
0

Recently, I had the opportunity to sit in on a few meetings at Eucalyptus Systems, Inc. discussing Elastic Load Balancing implementation ideas for Eucalyptus 3.3.  Elastic Load Balancing is under the “Future Development Directions” on the Eucalyptus Cloud Roadmap.  Part of my involvement was to evaluate the Zen Load Balancer.   The first question that I asked myself was “Can this open source load balancer appliance be tested in the cloud?”  I figured this would be a great way to not only test the appliance, but also give some insight as to how users would expect to interact with the load balancer in the cloud – similar to how AWS users interact with Elastic Load Balancing in EC2.

As the title mentions, this application can be made as an Eucalyptus Machine Image (EMI), and used in Eucalyptus as a load balancer.  This blog entry will focus on the creation of the KVM EMI from a VirtualBox (VDI) image.  Since the Zen Load Balancer is an appliance based off of Debian, it was really straight-forward to convert to an EMI.  A follow-up blog entry will discuss how to use the appliance in Eucalyptus to load balance traffic for a group of instances (e.g. HTTP/HTTPS traffic).

Creating the VirtualBox Image

To create the raw disk image needed for the EMI in Eucalyptus, I used VirtualBox on my machine, which is a MacBook Air running Mac OS X 10.8.2.  After downloading and installing VirtualBox, I went through the following steps to create a Zen Load Balancer VirtualBox image:

  1. I started up VirtualBox and I am presented with the following Window: 
    VirtualBox Welcome UI

    VirtualBox Welcome GUI

     

  2. Select “New” in the upper right-hand corner of the screen, and the GUI below will be displayed.  In this example, the name of the VM will be “ZenLoadBalancer”, the type is “Linux”, and the version is “Debian (64-bit). Select “Continue” after the fields have been filled in.
    Create Virtual Machine - Name and Operating System

    VirtualBox UI to select Name and Operating System

     

  3. Select the amount of RAM need for the VM.  In this example, I used 1024 MB. Select “Continue”.
    Create Virtual Machine - Memory Size

    Create Virtual Machine UI – Memory Size

     

  4. Select the hard drive file type.  Here, I selected VirtualBox Disk Image (VDI).  Select “Continue” once a selection has been made.
    Select Hard Drive File Type

    Select Hard Drive File Type

     

  5. Select to make the physical hard drive fixed, then select “Continue”.
    Select Fixed or Dynamic Hard Drive Type

    Select Fixed or Dynamic Hard Drive Type

     

  6. Select the name of the VM image file, and the size of the image.  In this example, the name is “ZenLoadBalancer” using the default location for storing the image, and 3 Gigs was allocated for the image.
    Create Virtual Hard Drive - Location and Size

    Create Virtual Hard Drive – Location and Size

     

  7. Now we need make sure that the network interface is configured and to add the Zen Load Balancer ISO as a CD-ROM device to the VM. To configure these options, start with the Basic Configuration GUI.
    ZenLoadBalancer - Basic Configuration GUI

    ZenLoadBalancer – Basic Configuration GUI

     

  8. Select the “Network” Icon in the top menu. Select “Adapter 1″, and make sure “Enable Network Adapter” is set.  Set “Attached to:” to “Bridged Adapter”, and select the adapter that the bridge will be connected to.  In this example, its en0.  Make sure no other adapters are enabled.  This is important for creating the EMI from this VM.
    Configuring Network Adapter - ZenLoadBalancer

    Configuring Network Adapter – ZenLoadBalancer

     

  9. Select the “Storage” icon in the menu.  Select the “+” sign next to “Controller:IDE” in the right-hand sidebar.
    Adding New IDE

    Adding New IDE

     

  10. Confirm to add new CD/DVD drive to controller IDE by selected ‘Choose disk’, then select the Zen Load Balancer ISO.  Select “Open”. Select “OK” on the main menu when the IDE has been attached.
    Confirming adding new controller IDE

    Confirming adding new controller IDE

    Selecting ZenLoadBalancer ISO

    Selecting ZenLoadBalancer ISO

     

  11. Its now time to power on the VM.  Select “Start” in the main GUI.
    Starting the VM

    Starting the VM

     

  12. The Zen Load Balancer boot-up screen will be presented.
    Zen Load Balancer Splash Screen

    Zen Load Balancer Splash Screen

     

  13. Select “Install”, and begin the static network configuration on the appliance.  In this example, I select 192.168.1.130 as the IP for the VM, and 192.168.1.1 as my gateway.  Even though this is static, we will use some /etc/rc.local magic to dynamically change this information per instance when its used as an EMI.
    Configuring Static IP

    Configuring Static IP

     

  14. After completing those steps, the command-line prompt will be presented.
    Zen Load Balancer Log-In Prompt

    Zen Load Balancer Log-In Prompt

     

  15. Log into the VM, and install the latest linux-headers-*-amd64, linux-image-*-amd64, curl, and isc-dhcp-client using apt.
  16. To make sure that the image can take advantage of using VirtIO, add “virtio”, “virtio_pci”, “virtio_net” and “virtio_blk” virtio modules to the /etc/initramfs-tools/modules file, then run

    update-initramfs -u

We have finished all the prep work for the image.  Now, we just stop the VM, and get ready to convert this VDI to an EMI.

Creating the Eucalyptus Machine Image

After stopping the VirtualBox VM, we are now ready to convert it to an EMI.  Since the VirtualBox VM image is a VDI, we need to pull out the root filesystem from the raw disk image, and use that as the EMI.

  1.  To get us started, lets  convert the VDI to a raw image.   On my MacBook Air, I opened up good ol’ iTerm.  and ran the following command:  

    $ VBoxManage internalcommands \
    converttoraw /Users/haroldspencerjr/VirtualBox\ VMs/ZenLoadBalancer/ZenLoadBalancer.vdi \
    ZenLoadBalancer.img
  2. After that completes, you end up with raw image that has the following characteristics:

    $ file ZenLoadBalancer.img
    ZenLoadBalancer.img: x86 boot sector; partition 1: ID=0x83, active, 
    starthead 32, startsector 2048, 5924864 sectors; partition 2: ID=0x5,
     starthead 15, startsector 5928958, 360450 sectors, code offset 0x63

     We need to grab the root file system out.  Since I wanted to use parted to figure out which section of the image I needed to pull out using dd, I moved the image to the frontend of my Eucalyptus cloud – which is running on CentOS 6.3.  Once I had it on that machine, I ran parted on the image.  The output looks like the following:

    # sudo parted ZenLoadBalancer.img
    
    GNU Parted 2.1
    
    Using /root/ZenLoadBalancer.img
    
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    
    (parted) u
    
    Unit?  [compact]? b
    
    (parted) p
    
    Model:  (file)
    
    Disk /root/ZenLoadBalancer.img: 3221225472B
    
    Sector size (logical/physical): 512B/512B
    
    Partition Table: msdos
    
    Number  Start        End          Size         Type      File system     Flags
    
    1      1048576B     3034578943B  3033530368B  primary   ext3            boot
    
    2      3035626496B  3220176895B  184550400B   extended
    
    5      3035627520B  3220176895B  184549376B   logical   linux-swap(v1)
    (parted)
  3. As you can see, the root file system is in partition 1.  Note the values for “Start” and “Size” (in this example, the start is 1048576B and the Size is 3033530368B).  This is what you will need to use with dd to pull out the root file system.  When using dd, the bs option can be used to speed up the process.  In this example, I used bs=512.  Since I used that, I had to divide that against the “Start” and “Size” values, and use those values for “skip” and “count”.  The root filesystem that I pull out will be called “ZenLB-rootfs.img”.

    # sudo dd if=ZenLoadBalancer.img of=ZenLB-rootfs.img bs=512 skip=2048 count=5924864

    After it completes, I will end up with ~3 Gig image:

    # du -sh ZenLB-rootfs.img2.9G ZenLB-rootfs.img
  4. Next, I need to mount the root device to the loopback to do some additional preparations to the root filesystem, and get the ramdisk and kernel.  Mount the image (in this example, I used /mnt/debian):

    # sudo mount -o loop ZenLB-rootfs.img /mnt/debian
    
    # sudo mount -o bind /proc /mnt/debian/proc
    
    # sudo mount -o bind /sys /mnt/debian/sys
    
    # sudo mount -o bind /dev /mnt/debian/dev
    
    # sudo mount -o bind /dev/pts /mnt/debian/dev/pts
  5. Once its been mounted, chroot into /mnt/debian.

    # sudo chroot /mnt/debian
  6. We need to remove /etc/init.d/zenloadbalancer from being ran on start-up.  Use update-rc.d to remove it from the start-up scripts.

    # sudo update-rc.d -f zenloadbalancer remove
  7. We have to remove the udev rules for networking to make sure we don’t cause any confusion for the image when its launched as an instance:

    # rm -rf /etc/udev/rules.d/70-persistent-net.rules
  8. Now, we have to edit /etc/network/interfaces to make sure when the eth0 interface is activated, it uses dhcp.  Add the following to the /etc/network/interfaces file:  

    auto eth0
    iface eth0 inet dhcp
  9. To get the image ready for the cloud, we need to add/update the /etc/rc.local file.  Copy and paste the contents of the rc.local file from the eucalyptus/Eucalyptus-Scripts repo on github to the /etc/rc.local file.
  10. We need to add one more edit to the /etc/rc.local file.  This addition allows us to configure the Zen Loadbalancer application using the metadata service provided by Eucalyptus. With your favorite editor (e.g. vi, emacs, nano, etc.), open up /etc/rc.local, and add the following lines before the “exit 0″:

    # set IP information for ZenLoadBalancer
    
    ZENLB_GATEWAY="`route -n | grep UG | awk '{print $2}'`"
    
    ZENLB_IP_INFO="eth0::${META_IP}:255.255.255.0:${ZENLB_GATEWAY}:up::"
    
    echo ${ZENLB_IP_INFO} > /usr/local/zenloadbalancer/config/if_eth0_conf
    
    echo "ZenLoadBalancer IP/Gateway Configuration:"
    
    echo "****************************************"
    
    cat /usr/local/zenloadbalancer/config/if_eth0_conf
    
    echo "****************************************"
    
    ZENLB_GATEWAY="`route -n | grep UG | awk '{print $2}'`"
    
    sed --in-place 's/$defaultgw="192.168.1.1";/$defaultgw="${ZENLB_GATEWAY}";/' /usr/local/zenloadbalancer/config/global.conf
    
    
    # start zenloadbalancer
    
    /etc/init.d/zenloadbalancer start
  11. Exit out of the chroot environment by typing “exit”.  Copy the ramdisk and kernel from the boot directory where the image is mounted (i.e. /mnt/debian/boot):

    # sudo cp /mnt/debian/boot/vmlinuz-2.6.32-5-amd64 .
    # sudo cp /mnt/debian/boot/initrd.img-2.6.32-5-amd64 .
  12. Unmount all the mounts associated with /mnt/debian:

    # sudo umount /mnt/debian/dev/pts; sudo umount /mnt/debian/dev;\
     sudo umount /mnt/debian/sys;\
     sudo umount /mnt/debian/proc; sudo umount /mnt/debian
  13. Now that we have the root filesystem image, kernel and ramdisk, lets prepare these images to be bundled, uploaded and registered using eustore.  Create a directory for these images (in this example, ZenLoadBalancer), and a directory inside that directory for the kernel and ramdisk.  To work with eustore, the directory needs to have the name format “hypervisor type”-kernel.  Since we are using KVM, the directory created is “kvm-kernel”.  

    mkdir -p ZenLoadBalancer/kvm-kernel
  14. Move the root filesystem image (ZenLB-rootfs.img) into the ZenLoadBalancer directory, and then move the kernel and ramdisk into the ZenLoadBalancer/kvm-kernel directory. *NOTE* Make sure the images are owned by the current user if you are not the root user.  This can be done using “chown”. After moving the images to those locations, the layout should look similar to the following:

    # ls ZenLoadBalancer/*
    
    ZenLoadBalancer/ZenLB-rootfs.img
    
    ZenLoadBalancer/kvm-kernel:
    
    initrd.img-2.6.32-5-amd64  vmlinuz-2.6.32-5-amd64
  15. Now all we have to do is tar-gzip up the ZenLoadBalancer directory:

    # tar -zcvf \
    ZenLoadbalancer-x86_64.tgz ZenLoadBalancer
  16. Use eustore to bundle, upload, and register the ramdisk (ERI), kernel (EKI) and root filesystem image (EMI):

    # eustore-install-image -t ZenLoadbalancer-x86_64.tgz -b zenloadbalancer-debian-x86_64 \
    -s "ZenLoadbalancer V2 Stable 1" -k kvm -a x86_64
    
    Unbundling image
    
    going to look for kernel dir : kvm-kernel
    
    Bundling/uploading ramdisk
    
    Checking image
    
    Compressing image
    
    Encrypting image
    
    Splitting image...
    
    Part: initrd.img-2.6.32-5-amd64.part.00
    
    Generating manifest /tmp/NJMRYf/initrd.img-2.6.32-5-amd64.manifest.xml
    
    Checking bucket: zenloadbalancer-debian-x86_64
    
    Creating bucket: zenloadbalancer-debian-x86_64
    
    Uploading manifest file
    
    Uploading part: initrd.img-2.6.32-5-amd64.part.00
    
    Uploaded image as zenloadbalancer-debian-x86_64/initrd.img-2.6.32-5-amd64.manifest.xml
    
    zenloadbalancer-debian-x86_64/initrd.img-2.6.32-5-amd64.manifest.xml
    
    eri-31D33872
    
    Bundling/uploading kernel
    
    Checking image
    
    Compressing image
    
    Encrypting image
    
    Splitting image...
    
    Part: vmlinuz-2.6.32-5-amd64.part.00
    
    Generating manifest /tmp/NJMRYf/vmlinuz-2.6.32-5-amd64.manifest.xml
    
    Checking bucket: zenloadbalancer-debian-x86_64
    
    Uploading manifest file
    
    Uploading part: vmlinuz-2.6.32-5-amd64.part.00
    
    Uploaded image as zenloadbalancer-debian-x86_64/vmlinuz-2.6.32-5-amd64.manifest.xml
    
    zenloadbalancer-debian-x86_64/vmlinuz-2.6.32-5-amd64.manifest.xml
    
    eki-B420361A
    
    Bundling/uploading image
    
    Checking image
    
    Compressing image
    
    Encrypting image
    
    Splitting image...
    
    Part: ZenLB-rootfs.part.00
    
    Part: ZenLB-rootfs.part.01
    
    Part: ZenLB-rootfs.part.02
    
    Part: ZenLB-rootfs.part.03
    
    Part: ZenLB-rootfs.part.04
    
    Part: ZenLB-rootfs.part.05
    
    Part: ZenLB-rootfs.part.06
    
    Part: ZenLB-rootfs.part.07
    
    Part: ZenLB-rootfs.part.08
    
    Part: ZenLB-rootfs.part.09
    
    Part: ZenLB-rootfs.part.10
    
    Part: ZenLB-rootfs.part.11
    
    Part: ZenLB-rootfs.part.12
    
    Part: ZenLB-rootfs.part.13
    
    Part: ZenLB-rootfs.part.14
    
    Part: ZenLB-rootfs.part.15
    
    Part: ZenLB-rootfs.part.16
    
    Part: ZenLB-rootfs.part.17
    
    Part: ZenLB-rootfs.part.18
    
    Part: ZenLB-rootfs.part.19
    
    Part: ZenLB-rootfs.part.20
    
    Part: ZenLB-rootfs.part.21
    
    Part: ZenLB-rootfs.part.22
    
    Part: ZenLB-rootfs.part.23
    
    Part: ZenLB-rootfs.part.24
    
    Part: ZenLB-rootfs.part.25
    
    Part: ZenLB-rootfs.part.26
    
    Part: ZenLB-rootfs.part.27
    
    Part: ZenLB-rootfs.part.28
    
    Part: ZenLB-rootfs.part.29
    
    Part: ZenLB-rootfs.part.30
    
    Part: ZenLB-rootfs.part.31
    
    Part: ZenLB-rootfs.part.32
    
    Part: ZenLB-rootfs.part.33
    
    Part: ZenLB-rootfs.part.34
    
    Part: ZenLB-rootfs.part.35
    
    Part: ZenLB-rootfs.part.36
    
    Part: ZenLB-rootfs.part.37
    
    Part: ZenLB-rootfs.part.38
    
    Part: ZenLB-rootfs.part.39
    
    Part: ZenLB-rootfs.part.40
    
    Part: ZenLB-rootfs.part.41
    
    Part: ZenLB-rootfs.part.42
    
    Part: ZenLB-rootfs.part.43
    
    Part: ZenLB-rootfs.part.44
    
    Generating manifest /tmp/NJMRYf/ZenLB-rootfs.manifest.xml
    
    Checking bucket: zenloadbalancer-debian-x86_64
    
    Uploading manifest file
    
    Uploading part: ZenLB-rootfs.part.00
    
    Uploading part: ZenLB-rootfs.part.01
    
    Uploading part: ZenLB-rootfs.part.02
    
    Uploading part: ZenLB-rootfs.part.03
    
    Uploading part: ZenLB-rootfs.part.04
    
    Uploading part: ZenLB-rootfs.part.05
    
    Uploading part: ZenLB-rootfs.part.06
    
    Uploading part: ZenLB-rootfs.part.07
    
    Uploading part: ZenLB-rootfs.part.08
    
    Uploading part: ZenLB-rootfs.part.09
    
    Uploading part: ZenLB-rootfs.part.10
    
    Uploading part: ZenLB-rootfs.part.11
    
    Uploading part: ZenLB-rootfs.part.12
    
    Uploading part: ZenLB-rootfs.part.13
    
    Uploading part: ZenLB-rootfs.part.14
    
    Uploading part: ZenLB-rootfs.part.15
    
    Uploading part: ZenLB-rootfs.part.16
    
    Uploading part: ZenLB-rootfs.part.17
    
    Uploading part: ZenLB-rootfs.part.18
    
    Uploading part: ZenLB-rootfs.part.19
    
    Uploading part: ZenLB-rootfs.part.20
    
    Uploading part: ZenLB-rootfs.part.21
    
    Uploading part: ZenLB-rootfs.part.22
    
    Uploading part: ZenLB-rootfs.part.23
    
    Uploading part: ZenLB-rootfs.part.24
    
    Uploading part: ZenLB-rootfs.part.25
    
    Uploading part: ZenLB-rootfs.part.26
    
    Uploading part: ZenLB-rootfs.part.27
    
    Uploading part: ZenLB-rootfs.part.28
    
    Uploading part: ZenLB-rootfs.part.29
    
    Uploading part: ZenLB-rootfs.part.30
    
    Uploading part: ZenLB-rootfs.part.31
    
    Uploading part: ZenLB-rootfs.part.32
    
    Uploading part: ZenLB-rootfs.part.33
    
    Uploading part: ZenLB-rootfs.part.34
    
    Uploading part: ZenLB-rootfs.part.35
    
    Uploading part: ZenLB-rootfs.part.36
    
    Uploading part: ZenLB-rootfs.part.37
    
    Uploading part: ZenLB-rootfs.part.38
    
    Uploading part: ZenLB-rootfs.part.39
    
    Uploading part: ZenLB-rootfs.part.40
    
    Uploading part: ZenLB-rootfs.part.41
    
    Uploading part: ZenLB-rootfs.part.42
    
    Uploading part: ZenLB-rootfs.part.43
    
    Uploading part: ZenLB-rootfs.part.44
    
    Uploaded image as zenloadbalancer-debian-x86_64/ZenLB-rootfs.manifest.xml
    
    zenloadbalancer-debian-x86_64/ZenLB-rootfs.manifest.xml
    
    Installed image: emi-826F3A01

Test the Zen LoadBalancer Eucalyptus Machine Image

We are now ready to test out the newly bundled image.  Make sure and source your Eucalyptus creds (i.e. source .eucarc) so that we can create a security group for the load balancer, and then launch the image.

First, create the security group, and authorize ports for SSH (22), ping (ICMP), and ZenLoadBalancer admin UI (444).


# euca-create-group zenloadbalancer -d "Security Group for Zen Loadbalancer"

GROUP zenloadbalancer Security Group for Zen Loadbalancer

# euca-authorize -P tcp -p 22 -s 0.0.0.0/0 zenloadbalancer

GROUP zenloadbalancer

PERMISSION zenloadbalancer ALLOWS tcp 22 22 FROM CIDR 0.0.0.0/0

# euca-authorize -P tcp -p 444 -s 0.0.0.0/0 zenloadbalancer

GROUP zenloadbalancer

PERMISSION zenloadbalancer ALLOWS tcp 444 444 FROM CIDR 0.0.0.0/0

# euca-authorize -P icmp -t -1:-1 -s 0.0.0.0/0 zenloadbalancer

GROUP zenloadbalancer

PERMISSION zenloadbalancer ALLOWS icmp -1 -1 FROM CIDR 0.0.0.0/0

# euca-describe-group zenloadbalancer

GROUP 345590850920 zenloadbalancer Security Group for Zen Loadbalancer

PERMISSION 345590850920 zenloadbalancer ALLOWS tcp 22 22 FROM CIDR 0.0.0.0/0

PERMISSION 345590850920 zenloadbalancer ALLOWS tcp 444 444 FROM CIDR 0.0.0.0/0

PERMISSION 345590850920 zenloadbalancer ALLOWS icmp -1 -1 FROM CIDR 0.0.0.0/0

Now, lets launch an instance under the “zenloadbalancer” group.


# euca-run-instances -k admin emi-826F3A01 -g zenloadbalancer

Run “euca-describe-instances” to see when the instance gets into a running state:


# euca-describe-instances i-BF33466F
RESERVATION r-7D23418A 345590850920 zenloadbalancer
INSTANCE i-BF33466F emi-826F3A01 euca-192-168-55-105.wu-tang.euca-hasp.eucalyptus-systems.com euca-10-106-45-14.wu-tang.internal running admin 0 
m1.small 2012-11-28T17:32:44.184Z enter-the-wu eki-B420361A eri-31D33872 
monitoring-disable euca-192-168-55-105.wu-tang.euca-hasp.eucalyptus-systems.com euca-10-106-45-14.wu-tang.internal instance-store

Once, the instance is up, access the Zen Load Balancer Admin UI - https://euca-192-168-55-105.wu-tang.euca-hasp.eucalyptus-systems.com:444/ – and log-in using the username “admin” and password “admin” – as per the Zen Load Balancer Administrator’s Guide:

Zen Load Balancer Admin UI Login

Landing Page – Zen Load Balancer Admin UI

And thats it.  You now have an Open Source Load Balancer ready for cloud use.  The follow-up blog to this will show how to use the Zen Load Balancer in Eucalyptus.  Hope you found this helpful.  Enjoy!


Filed under: Infrastructure, Interests, Private Cloud Computing, System Adminstration Tagged: cloud computing, cloud images, dd, elb, eucalyptus, eustore, eustore-install-image, load balancing appliance, metadata service, parted, virtualbox, zenloadbalancer

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images