Apache WebDAV as storage

Nic Benders xac at slackworks.com
Tue Sep 12 14:50:54 UTC 2006


Here are three snippets that I found useful when setting up MogileFS 
with Apache as the storage backend on Red Hat Enterprise Linux.  For 
Debian, change logwatch to logreaper and the apache user to www-data.  I 
also had to manually create the test-write/ directory under each dev 
when setting it up the first time, and of course make sure that 
everything under dev* was writable by the web server user.

/etc/httpd/conf.d/mogilefs.conf
------------------------------
Listen 7500
<VirtualHost *:7500>
  DocumentRoot /var/mogilefs
  CustomLog logs/mogilefs_log common

  <Directory /var/mogilefs>
    Options +Indexes +FollowSymLinks
  </Directory>

  <Location />
    DAV On
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
    Allow from X.X.X.X
    Allow from Y.Y.Y.Y
  </Location>
</VirtualHost>



/etc/cron.d/mogilefs
--------------------
# Remove old test-write/ files
57 * * * * apache /usr/sbin/tmpwatch 1 /var/mogilefs/dev*/test-write

# Update the disk usage file
* * * * * apache /opt/mogilefs/update-usage.pl /var/mogilefs



/opt/mogilefs/update-usage.pl
-----------------------------
#!/usr/bin/perl -w

use strict;

die "Usage: $0 <mog_root>\n" unless $#ARGV == 0;

my $path = $ARGV[0];
$path =~ s!/$!!;

# find all devices below us
my @devnum;
if (opendir(D, $path)) {
    @devnum = grep { /^dev\d+$/ } readdir(D);
    closedir(D);
} else {
    print STDERR "Failed to open $path: $!\n";
}

foreach my $devnum (@devnum) {
    my $rval = `df -k -l -P $path/$devnum`;
    foreach my $l (split /\r?\n/, $rval) {
        next unless $l =~ /^(.+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.+)\s+(.+)$/;
        my ($dev, $total, $used, $avail, $useper, $disk) = ($1, $2, $3, $4, 
                                                            $5, $6);

        unless ($disk =~ m!$devnum/?$!) {
            $disk = "$path/$devnum";
        }

        # create string to print
        my $now = time;
        my $output = {
            time      => time(),
            device    => $dev,    # /dev/sdh1
            total     => $total,  # integer: total KiB blocks
            used      => $used,   # integer: used KiB blocks
            available => $avail,  # integer: available KiB blocks
            'use'     => $useper, # "45%"
            disk      => $disk,   # mount point of disk (/var/mogdata/dev8),
                                  # or path if not a mount
            };

        # open a file on that disk location called 'usage'
        my $rv = open(FILE, ">$disk/usage");
        unless ($rv) {
            print STDERR "Unable to open '$disk/usage' for writing: $!\n";
            next;
        }
        foreach (sort keys %$output) {
            print FILE "$_: $output->{$_}\n";
        }
        close FILE;
    }
}




More information about the mogilefs mailing list