Setup DRBD for master/master

At my job at OpenSky we have a common NFS share that is failed over to a slave nfs node if the master dies. It was setup so that the slave would just rsync from the master. This was done to save time. Not that I have some time, I decided to finally setup drbd on the two nodes to keep the files always in sync.

So below are my nodes with hostnames/ips and drive information

Node1
host: nfs1.domain.com
ip: 192.168.1.46
partition: /dev/sdb1

Node2
host: nfs2.domain.com
ip: 192.168.1.47
partition: /dev/sdb1

So once drbd is installed setup the following file

/etc/drbd.conf

To look something like this. You will want to change a few things in red. Put this file on both nodes.

global {
  usage-count yes;
}
common {
  protocol C;
}
resource nfs {
  meta-disk internal;
  device     /dev/drbd1;
  syncer {
    verify-alg sha1;
  }
  net {
    allow-two-primaries;
  }
  on nfs1.domain.com {
    disk       /dev/sdb1;
    address    192.168.1.46:7789;
  }
  on nfs2.domain.com {
    disk       /dev/sdb1;
    address    192.168.1.47:7789;
  }
}

I choose to use protocol C. You can see the following protocols below. Also the on nfs1.domain.com has to match the output of a hostname command

http://www.drbd.org/users-guide/s-replication-protocols.html

Now on both nodes you want to init the drbd partition. Make sure this is a blank partition. It will wipe out everything that is one it. I called my resource nfs. If you changed it the commands will be a bit different based on what name you gave your resource

drbdadm create-md nfs

You should get an output like

initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success

Now make sure drbd can be run on startup and start it up now

chkconfig drbd on
service drbd start

Once you start drbd on both nodes it will connect to both. If you just start one and not the other.. the other will wait for the second node to come alive.

You can now make a filesystem. Make sure it is a filesystem for clustering. I recommend ocfs2 but gfs2 also works.

A better Jira init.d script for Redhat/CentOS

I wrote a bit better init.d script for Jira for Redhat/CentOS

The first thing you want to do is create a sysconfig file. Below is the filename

/etc/sysconfig/jira

The file has the following contents in it

#
# The user Jira runs as
#
JIRA_USER=jira

#
# The home directory of Jira
#
JIRA_HOME=/opt/jira/current

Now create the init.d script

/etc/init.d/jira

It has the following contents in it.

#!/bin/sh
#
# JIRA startup script
#
# chkconfig: 2345 80 05
# description: JIRA

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/jira ]; then
    . /etc/sysconfig/jira
fi

prog=jira
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        /bin/su -m $JIRA_USER -c "cd $JIRA_HOME/logs && $JIRA_HOME/bin/startup.sh &> /dev/null"
        RETVAL=$?
        if [ $RETVAL = 0 ]
        then
                echo $! > /var/run/jira.pid
                echo_success
        else
                echo_failure
        fi

        echo

        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        /bin/su -m $JIRA_USER -c "$JIRA_HOME/bin/shutdown.sh &> /dev/null"
        RETVAL=$?
        if [ $RETVAL = 0 ]
        then
                rm -f /var/run/jira.pid
                echo_success
        else
                echo_failure
        fi
        echo

        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                sleep 5
                start
                ;;
        *)
                echo $"Usage: /etc/init.d/$prog {start|restart|stop}"
                exit 1
                ;;
esac

exit $RETVAL

Now make permissions correct

chmod +x /etc/init.d/jira

Now you can chkconfig it

chkconfig jira on

This will make it look a bit more Redhat/CentOS like.

Install fabric on Redhat/CentOS 5

Fabric is a great tool for helping deploy applications. It is written in Python and still in it’s early stages. The big issue is that fabric will not run on python v2.4. That is a problem since Redhat/CentOS v5 ships with v2.4 so we have to make it work.

So the first thing to do is install python 2.5. I found great rpms here. I am going to mirror the RPMS on my blog just in case. You also need to install tkinter25 which I provide for you also. These are only for 64bit. You can do some googling to find the 32 bit versions I am sure. You also need to install libtk and libTix.

Install some dependancies

yum install tk tix

Now lets install python and tkinter

mkdir python
cd python
wget http://zcentric.com/files/python25-2.5.1-bashton1.x86_64.rpm
wget http://zcentric.com/files/python25-devel-2.5.1-bashton1.x86_64.rpm
wget http://zcentric.com/files/python25-libs-2.5.1-bashton1.x86_64.rpm
wget http://zcentric.com/files/python25-test-2.5.1-bashton1.x86_64.rpm
wget http://zcentric.com/files/python25-tools-2.5.1-bashton1.x86_64.rpm
wget http://zcentric.com/files/tkinter25-2.5.1-bashton1.x86_64.rpm
rpm -ivh *.rpm

Remove all the python25 rpms

rm -rf *.rpm

Now you have v2.4 and v2.5 installed. Now lets download the needed fabric dependancies and fabric. I built these to run for python25

wget http://zcentric.com/files/fabric-0.9-0.1.b1.noarch.rpm
wget http://zcentric.com/files/python25-setuptools-0.6c5-2.noarch.rpm
wget http://zcentric.com/files/python25-paramiko-1.7.6-1.noarch.rpm
wget http://zcentric.com/files/python25-crypto-2.0-1.rf.x86_64.rpm
rpm -ivh *.rpm
Now we just need to edit the fab file to change the python version it will run as by default
vi /usr/bin/fab
Change
#!/usr/bin/python
To
#!/usr/bin/python25
Now you can run fab and you should get something like
[root@dev1 ~]# fab
Fatal error: Couldn’t find any fabfiles!
Aborting.
More blog posts to come on how to use fabric