Monthly Archives: August 2013

The Most Awesome Animation About Quantum Computers You Will Ever See | Quantum Frontiers

The Most Awesome Animation About Quantum Computers You Will Ever See | Quantum Frontiers.


Distributed Replicated Block Device (DRBD)

I cannot be more explicit than the documentation.  But I like to report my own experience:) with DRBD.

If you’re looking for something to copy blindly your partition blocs and synchronize it with another partition without caring about the filesystem and data details, go for DRBD. it’s very cool, easy to implement, just get your disks and your gigabyte ethernet card ready :D.

DRBD stands between the filesystem and I/O scheduler layer of the operating system, thus didn’t care about high level layers like the filesystem. That’s why I said, it copies blindly xd xd.


Depending on your linux distribution, you’ll get DRBD on your server. I did it on CentOS 6.

After having set my ressources, and started DRBD. I faced some difficulties mainly because I didn’t understand how DRBD works!!!

The idea was so simple but look at me, I was so hesitating kinda of couldn’t figure out some so very simple things like:

  • Do not know what to mount: device or disk? /dev/drbd1 or /dev/sda2?

When I needed to mount  my DRBD partition named as in the following configuration code,

resource r0 {
  on node1 {
    device    /dev/drbd1;
    disk      /dev/sda2;
    meta-disk internal;
  on node2 {
    device    /dev/drbd1;
    disk      /dev/sda7;
    meta-disk internal;

I tried:

mount /dev/sda2

Which is so stupid. Wanna know why? We only mount a filesystem to a point of the whole filesystem. Let’s
look at how DRBD sees /dev/sda2. in fact, filesystem or no filesystem on the partition is viewed by DRBD
as just an information about data on the partition. Plus, DRBD needs to store some meta data about the
replicated partition. By defaults, DRBD uses the same partition to save these metadata. So trying to mount
/dev/sda2 is something like mounting [metada format+filesystem] which is nonesense. That’s explain why
one needs to zero out a partition so that DRBD can use it. After that, you can create your file system
on the DRBD device /dev/drbd1 and mount it if you like to.

  • Couldn’t restart my server:

I needed that my DRBD partition be mounted on OS startup. So, as always, I jumped to the /etc/fstab, added joyfully this line:

/dev/sda2       /mountpoint           ext3    defaults        0       2

Restarting my server, boot process stopped at fsck checks of the DRBD partition and didn’t start.No,No,

The only thing I could do is restarting my server at rescue mode with a live CD, everything was ok, though
my system won’t start. Why?

Look at my /etc/fstab line:

The option is defaults which implicitly means mount at boot,
The sixth fied is 2, which tells fsck to check filesystem of my partition at boot time;

So the thing was that the DRBD partition:/dev/sda2 is mounted at boot time. Thus couldn’t start my server
because it hanged out trying to mount a partition that contains no recognizable filesystem.

And even if, I used noauto option, I couldn’t start it because it hanged out while fsck checked a
non-coherent filesystem!!!!

So the solution was to use noauto option with 0 at the sixth field preventing any fsck checks at boot

DRBD is cool and fun, you can use drbdadm utility to manage it and with cat /proc/drbd, you can see the
status of the replication and nodes. I actually used it to write a script monitoring DRBD 8.4 by following
the documentation and doing some logic for cases to monitor;
I also found a good article describing how to use DRBD to do MySQL replication. It’s cool compared to the
master/slave replication done in high level of the O/S, just think to include your mysql configuration
files in the partition to be replicated.

This is in brief, how was my first contact with DRBD. I can also add that DRBD guys at IRC were very
generous and ready to answer every question, thank you guys :).

Bash to add many users (linux+MySQL) at one time.

I had a list of username and database to create and could not afford creating them manually. Well, I thought it was a good idea to do some bash scripting and let the machine do the dirty work xd xd.

First, I needed to read arguments from a file/list, then I had some trouble with mysql and all the crop of escaping special character and interpreting variables within single quotes. But I managed to get my users and databases added as intended.

Genrating UNIX accounts:

#!/bin/bash -xv
LIST="~/list"    #list of users

#add users
touch ulogin # file to hold passwords for newly created users
while read line # Loop and read from the list
account=`echo $line | cut -d":" -f1`
uaccount=`echo $line | cut -d":" -f2`
upass=`generate some pass with your preferred function`

useradd -m -g users -u $uaccount $account
echo "$account:$upass" | chpasswd
echo -e "Login FTP:$account \t Password:$upass" >>ulogin

done <$LIST

Genrating MySQL databases and users with privileges granted:

#!/bin/bash -xv
touch dblogin
while read dbname
ddbname=`echo $dbname | sed -e 's/[ \t]*//'` #delete any space or tab
pas=`generate your password with your preferred function ` # I use pwgen
pass=" '$pas' "
dbname=" '$ddbname' "
mysql -uroot -p`cat /root/.hiddenpass` -e "CREATE DATABASE \`$ddbname\`;"
mysql -uroot -p`cat /root/.hiddenpass` -e "CREATE USER $dbname@'%' IDENTIFIED BY $pass;"
mysql -uroot -p`cat /root/.hiddenpass` -e "GRANT ALL PRIVILEGES ON  \`$ddbname\`.* TO $dbname@'%' IDENTIFIED BY $pass; FLUSH PRIVILEGES;"
echo -e "Login/BDD:$ddbname \t Password:$pass" >> dblogin
done <$DB