Linux Showroom

My daily dosis of linux usage

ejabberd on GNU/Linux OpenSuSE 11.0

Posted in Howto, Open Source, administration by Fabio on the November 24th, 2008

I heard about the successful usage of ejabberd from weblin’s CTO Heiner yesterday at lunch during BarCamp Hamburg 08.

I was thinking of deploying jabber services for podcast.de for a while now but couldn’t decide which server to take. I checked the ejabberd website. The software looks promising. So I give it a try.

# smart install ejabberd

Could not find any results. So I check OpenSuSE software search. Luckily it lists a source which I add to my smart sources.

# smart channel --edit


[Cyberorg]
type = rpm-md
name = Cyberorg
baseurl = http://download.opensuse.org/repositories/home:/cyberorg:/sugar/openSUSE_11.0/

On to install the ejabberd package:

# smart install ejabberd

I get a report that I am still missing a package for erlang as ejabberd is written in erlang. I use the OpenSuSE software search again which lists the following source:


[NicoK]
type = rpm-md
name = NicoK
baseurl = http://download.opensuse.org/repositories/home:/NicoK/openSUSE_11.0/

Now I can install ejabberd: ejabberd-2.0.0-2.11@x86_64
I also need one more package: erlang-R12B4-18.11@x86_64

The beauty of installing pre-compiled RPMs on OpenSuSE. You almost always get a rc-file along with the RPM (for server software that is).

# rce -> Tab -> rcejabberd

There it is. Great! Now I want to change the default configuration. I would expect a config file to sit in /etc/sysconfig but ejabberd brings its own directory under /etc/ejabberd where two config files reside: ejabberd.cfg and ejabberdctl.cfg.

I read before that ejabberd.cfg is the heart of ejabberd. So I edit this for local usage only ATM.

{hosts, [{ip, {127, 0, 0, 1}}]}.

I give it a try:

# rcejabberd start
Starting ejabberd done

Looks like it started. Too bad checking http://127.0.0.1:5280/admin does not work. I check for an error in the log dir /var/log/ejabberd/ just to find out no files have been created. ps aux shows me some erlang stuff is running: /usr/lib64/erlang/erts-5.6.4/bin/epmd -daemon but no jabber process(es) which I would suspect.

I am increasing the loglevel to debug (5):

{loglevel, 5}.

No change. I remove -detached in the run script and try again. This time I get debug messages on the shell:

# rcejabberd start
Starting ejabberd Erlang (BEAM) emulator version 5.6.4 [source] [64-bit] [smp:2] [async-threads:0] [hipe] [kernel-poll:false]
{”init terminating in do_boot”,{undef,[{ejabberd,start,[]},{init,start_it,1},{init,start_em,1}]}}
Crash dump was written to: erl_crash.dump init terminating in do_boot() failed

At this point I have to give up the experiment as I have no time to fiddle around with erlang problems.

Apache and lighttpd replaced by nginx for PHP application

Posted in Howto, Open Source, Software, administration by Fabio on the August 16th, 2008

A while back I wrote an article Switching from Apache HTTP Server to Lighttpd - Installing Lighttpd. Back then I migrated static stuff to lighttpd but left the dynamic stuff (PHP) with Apache.

I was never really satisfied with the speed of our system under load. I tried and tried. I optimized a lot of stuff in the backend and with the database. Most of the time I found a switch to make the system just a bit faster. Read Retrospective on three years of Seagull development if you are interested in the whole story.

In the last couple of weeks I ran out of ideas on where to improve next (without the need of rewriting too much code). I remembered using Squid years ago. I had a look at the newest version (3.0) and my interest in Squid stopped pretty soon after reading through the documentation. It was just not the software I needed.

I dived into spreading the load to multiple backends using HAproxy which by the way has a super active community. Check the mailinglist. The maintainer Willy is doing a great job. Learning about HAproxy I stumbled across the webserver nginx (pronounced engine x) numerous times. Learning about nginx I stumbled across the reverse proxy Varnish which is the proxy solution I hoped Squid would be. Furtherdown the line I ran into PHP-FPM - the PHP FastCGI Process Manager - which should not stay unmentioned.

So I read lots of blog posts, mails from mailinglists, documentation, articles, visited several forums and also learned many new things in a few wikis. So after getting the idea I had my stack together: Varnish -> HAproxy -> nginx -> PHP -> MySQL

Time to test it out! Varnish comes in a relatively uptodate package for my favorite distribution OpenSuSE (currently running 10.3 on 6 systems). HAproxy is available in a fresh version. nginx is theoretically available. It cannot install it though because of a package management conflict. So I downloaded the source for the newest stable version (0.6.3 as time of writing) and compiled it.

# wget http://sysoev.ru/nginx/nginx-0.6.32.tar.gz
# ./configure –prefix=/opt/software/nginx-0.6.32 –user=nginx –group=nginx –without-mail_pop3_module –without-mail_imap_module –without-mail_smtp_module
# make && make install

I did not need to install any extra packages. Frankly spoken I do have all the packages for compilation of C/C++ installed.

# cd /opt/software
# ln -s /opt/software/nginx-0.6.32 nginx

I always set a symlink to the currently used package. That way it is easy to replace the package when new versions come out. I can compile and install the new version and just switch the symlink.

Next thing I had to compile was a patched PHP version. So download the sources at php.net and the patches at the PHP-FPM site.

Unpack the PHP source:

# tar xjvf php-5.2.6.tar.bz2

Patch the source:

# gzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1

Configure PHP (adjust your settings accordingly):

LDFLAGS=”-L/usr/lib64″ ./configure –with-curl –disable-debug –enable-libxml –enable-session –with-pcre-regex –enable-xml –with-bz2 –with-zlib –enable-exif –enable-inline-optimization –enable-soap –enable-sockets –with-xmlrpc –without-pear –with-libdir=lib64 –with-mysql –with-mysqli –enable-mbstring –with-mcrypt –with-mhash –with-mime-magic –with-jpeg-dir=/usr/lib64 –with-png-dir=/usr/lib64 –with-gd –enable-gd-native-ttf –with-ttf –with-freetype-dir –enable-ftp –enable-zend-multibyte –with-openssl –enable-force-cgi-redirect –with-pcre-regex –without-sqlite –without-mm –enable-fastcgi –enable-bcmath –enable-fpm –quiet –prefix=/opt/software/php5.2.6-fpm

Compile and install:

# make & make install

Adjust the PHP-FPM settings to fit your needs. You can find more info on this and related subjects in the PHP-FPM documentation.

# vim /opt/software/php/etc/php-fpm.conf

Start PHP-FPM:

# /opt/software/php/bin/php-cgi –fpm

Have a look in the log files:

# /opt/software/php/logs/php-fpm.log

Now you can connect through your webserver to fast-cgi processes. I use nginx as webserver (see above). Advantages and disadvantes of fast-cgi vs. mod-based approaches et al have been covered elsewhere. For me this makes perfectly sense and works extremly well.

After playing around with Varnish for a while I decided I do not need HAProxy ATM. Varnish can do all the decisions I need to make based on HTTP headers. I configured Varnish’s config file (here: vcl.conf) by reading lots of examples on the net and trial and error.

If I find more time and anyone is interested I post more details on the configuration of nginx and Varnish. But for now I want to publish this post as it has been sitting here for a while already.

PS: If people say content is king they are absolutely right. But never forget in the internet speed is Kaiser!

Solved: Miro won’t start - missing video directory

Posted in Howto by Fabio on the March 31st, 2008

A couple of days ago a brand new version of Miro the open video podcatcher was released. I was eager to try it out. It is supposed to be faster than the previous release. I had to wait a few days for a rpm for my linux distribution to be released. Thanks to the great work of the PackMan crew this happended pretty soon after the release. Bummer! Miro won’t start. It seems I cleaned up to good after uninstalling the previous release. Miro complained that the video directory is missing. I checked the Miro Forums but could not find anything related to Linux. There were some tips for Mac OS X but nothing for linux. I checked the source, followed strace, used Google Linux but nothing turned up. I thought the fix would be as easy as finding what directory Miro is looking for. Finding the directory was not easy. I was close to giving up before I tried the unittest switch for Miro.

# miro  –unittest

What shall I say? That did the trick! The unittest failed but it created the missing directory (structure):

# ~/Movies/Democracy/Incomplete Downloads/

Now Miro starts. It still looks like it is not running properly but it is a start.

PS: I use OpenSuSE 10.3 and KDE3.

How to add a custom user-agent string to Konqueror

Posted in Howto, KDE by Fabio on the March 29th, 2008

You can easily set a custom user-agent string for a specific site through a predefined list of user-agent strings. If you want to define your own custom user-agent string I did not find a gui for that. The solution I found is the following. Launch your favorite text editor and open the file

~/.kde/config/kio_httprc

Just add two lines to the file. Here is an example. I wanted Konqueror to identify as an iPhone for m.podcast.de. The original iPhone has the following user-agent string:

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

So I added  the following two lines to the file

[m.podcast.de]

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

That’s all. Save the file. Relaunch Konqueror and you are done!

DNS does not resolve www.google.com - quick fix

Posted in Howto by Fabio on the December 5th, 2007

Surfing the web today and already yesterday in some cases one website wouldn´t load: www.google.com. This makes it difficult to login to Google AdWords and impossible to login to AdSense. For searching I can use the localized version www.google.de. That works just fine. But I use my browser´s (Mozilla Firefox) integrated search box quiet frequently. Using Google there leads to the .com version. www.google.com is working just fine (When did they have their last downtime? Did they ever have one?) so things with the DNS (Domain Name System) could be messed up. The system does not find an ip address for the url www.google.com anymore. The solution could be to set a fixed ip address for the url. This is also good for having local urls, e.g. my.system.

Would you need to do is edit the file /etc/hosts with an editor of your choice. As you need root rights you probably have to do this using a shell. Try vim, joe, emac or whatever you prefer.

Add a line

209.85.135.103 www.google.com

to your hosts file and you are ready to load Google in your browser again.

Switching from Apache HTTP Server to Lighttpd - Installing Lighttpd

Posted in Howto, Software by Fabio on the November 19th, 2007

For our main web project we struggle to serve the pages as fast as we want and as people aspect. Server load is too high most of the time. We did many different kinds of optimization. Starting with rewriting part of the code, squeezing the database, compiling the software we need instead of installing precompiled packages, using all kind of cache strategies (database, template, bytecode), buying servers with more powerful cpus (dual core instead of single core, 64bit instead of 32 bit), stocking up on ram (up to 8 GB RAM now) and now exchanging certain layers of software.

Setting up my first lighttpd server was easy. Configure runs through as wanted with just a few options:

LDFLAGS=”-L/usr/lib64″ ./configure –prefix=/usr/local/lighttpd-1.4.18 –with-pcre –with-bzip2 –with-rewrite –with-redirect –with-zlib –disable-ipv6

I took the few configurations options I needed from the official docs. Everything works as aspected and is pretty straight forward. You can check the syntax with the -t switch:

sbin/lighttpd -f lighttpd.config -t