Saturday, July 30, 2011

The 5 Minute Guide to Running OpenVZ on CentOS 6.x

As much as I like Debian (and the fact that it has OpenVZ kernels in the repos, for now...) CentOS is really the best distribution for running this container-based virtualization environment. This assumes a minimal CentOS 6.0 install.

1) Add the OpenVZ repos

See the Quick Installation guide and ensure that:
[root@opti330 yum.repos.d]# cat /etc/yum.repos.d/openvz.repo
name=OpenVZ utilities

name=OpenVZ RHEL6-based kernel

2) Install the packages (after updating of course)

# yum install openvz-kernel-rhel6 vzctl vzquota bridge-utils

3) Update /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.proxy_arp = 1

This ARP proxying is really only needed if you are doing veth networking (the default we'll use below)

4) Reboot

You kernel should now be:
[root@opti330 yum.repos.d]# uname -a
Linux opti330 2.6.32-042stab024.1 #1 SMP Tue Jul 26 15:23:12 MSD 2011 x86_64 x86_64 x86_64 GNU/Linux

5) Update /etc/sysconfig/iptables to allow traffic to/from venet0 (only if you are using venet)

-A FORWARD -i venet0 -o eth0 -j ACCEPT
-A FORWARD -i eth0 -o venet0 -j ACCEPT

Or something close. You will also want to update your iptables policy or disable it or disable it.

6) Now you can create your VE's per the instructions on my OpenVZ Wiki Page.

Thursday, July 28, 2011

Creating Debian Packages with FPM for the Impatient

So I've been aware of FPM for a while, but I actually hadn't got around to using it. This is an example on Debian but it should work on Ubuntu just fine.

1) Use the package maintainers version of Ruby and RubyGems.

root@debian64-10:~/tmp# apt-get install ruby ruby-dev rubygems
Get:1 squeeze/main rubygems1.8 all 1.3.7-3 [202 kB]
Get:2 squeeze/main rubygems all 1.3.7-3 [66.7 kB]
Fetched 269 kB in 0s (518 kB/s)
Selecting previously deselected package rubygems1.8.
(Reading database ... 50363 files and directories currently installed.)
Unpacking rubygems1.8 (from .../rubygems1.8_1.3.7-3_all.deb) ...
Selecting previously deselected package rubygems.
Unpacking rubygems (from .../rubygems_1.3.7-3_all.deb) ...
Processing triggers for man-db ...
Setting up rubygems1.8 (1.3.7-3) ...
Setting up rubygems (1.3.7-3) ..

2) Install FPM

root@debian64-10:~/tmp# gem update; gem install fpm
Updating installed gems
Nothing to update
Building native extensions. This could take a while...
Successfully installed json-1.5.3
Successfully installed fpm-0.3.7

3) This installed it but where does the script go? It isn't in /usr/local/bin. Nah that would be too obvious.

root@debian64-10:/# find / -name "fpm"

4) Update your path to included the gem wrappers and confirm that it runs

root@debian64-10:/# export PATH=$PATH:/var/lib/gems/1.8/bin
root@debian64-10:/# fpm
Missing package target type (no -t flag?)
Missing package source type (no -s flag?)
There were errors; see above.

Usage: fpm [options]
-p, --package PACKAGEFILE Th

To make it interesting, let's create a package that requires a dependency. The app I'm doing this for at work requires Java unfortunately, but I'll do Mono here for fun.

(I'm skipping the part here where I google for a lame Hello World C# app because I haven't touched the language since 2005 but the bottom line is I end up with .exe that will go in /usr/local/bin) so we have something like.

root@debian64-10:~/hellomono# pwd
root@debian64-10:~/hellomono# ls -al usr/local/bin/hellomono.exe
-rwxr-xr-x 1 root root 4096 Jul 28 21:39 usr/local/bin/hellomono.exe

All we are doing here is specifying the source (a directory) and a destination target (.deb). I assume we could do the same thing for an RPM or even creepier build a Ruby gem that contained a Mono app.

root@debian64-10:~/hellomono# fpm -s dir -t deb -d mono-runtime .

This created a .deb based on your current directory

tar: ./build-deb-hellomono_1.0_amd64.deb/data.tar: file is the archive; not dumped
Created /root/hellomono/hellomono_1.0_amd64.deb
root@debian64-10:~/hellomono# ls
hellomono_1.0_amd64.deb usr

And if we open it up

root@debian64-10:/tmp# ar -x hellomono_1.0_amd64.deb
root@debian64-10:/tmp# ls
control.tar.gz data.tar.gz debian-binary hellomono_1.0_amd64.deb hsperfdata_root
root@debian64-10:/tmp# tar xzvf control.tar.gz
root@debian64-10:/tmp# cat control
Package: hellomono
Version: 1.0
Architecture: amd64
Depends: mono-runtime
Standards-Version: 3.9.1
Section: default
Priority: extra
Description: no description given
root@debian64-10:/tmp# ls
control control.tar.gz data.tar.gz debian-binary hellomono_1.0_amd64.deb hsperfdata_root md5sums
root@debian64-10:/tmp# tar xzvf data.tar.gz

Now I scp it over to an Ubuntu LTS box and install

virtual@ubuntu14:~$ sudo dpkg -i hellomono_1.0_amd64.deb
[sudo] password for virtual:
Selecting previously deselected package hellomono.
(Reading database ... 73505 files and directories currently installed.)
Unpacking hellomono (from hellomono_1.0_amd64.deb) ...
dpkg: dependency problems prevent configuration of hellomono:
hellomono depends on mono-runtime; however:
Package mono-runtime is not installed.
dpkg: error processing hellomono (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:

Fix the dependencies

virtual@ubuntu14:~$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree
Setting up hellomono (1.0) ...
Setting up libmono-system2.0-cil (2.4.4~svn151842-1ubuntu4) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

And it runs!

virtual@ubuntu14:~$ /usr/local/bin/hellomono.exe
Hello World
virtual@ubuntu14:~$ dpkg -l | grep hello
ii hellomono 1.0 no description given