Web Directories Spread Thin on LVM Toast. Yum!

John set a fire in my pants. That fire was the passion to organize the way I store websites on my server.

Basically, we setup a logical volume for each virtual server. Here's the directory layout:

  • www
    • dev
    • eat8bit
      • htdocs
      • logs
      • includes

The directories dev and eat8bit are actually mounted as separate logical volumes.

So let's start at the beginning, setting up your partition.

Mark That Shit Son!

First and foremost, you must mark your partition as Linux LVM. So fire up the console and enter the commands as follows:

root@dangerunit0~# fdisk /dev/hde

Command (m for help): p

Disk /dev/hde: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hde1               1       14593   117218241   83  Linux

We can see that our drive has a partition that is marked as a standard Linux partition, we'll have to change that. The Id for a Linux LVM is 8e, so let's change it now:

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e

Command (m for help): p

Disk /dev/hde: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hde1               1       14593   117218241   8e  Linux LVM

Command (m for help): w

You should do this for each disk/partition you plan to use in your volume group.

Now that we've successfully labeled are partition(s) as Linux LVM we can move forward to step 2, creating physical volumes.

Create the Volume, Physically

Pretty straight forward. We just execute the below command for each partition we marked above.

root@dangerunit0~# pvcreate /dev/hde1

Add Them to Your Volume Group

Now we add the partitions to our volume group. I called my group “WebVG0”

root@dangerunit0~# vgcreate WebVG0 /dev/hde1

The Final Steps: Creating the Logical Volumes

That empty volume group is looking mighty fertile. Let us plant the seed:

root@dangerunit0~# lvcreate -L 500M -n eat8bit WebVG0

Then we must make it a filesystem.

root@dangerunit0~# mke2fs -j /dev/WebVG0/eat8bit

I'm using ext3, so modify this step according to your filesystem of choice

and mount it

root@dangerunit0~# mount /dev/WebVG0/eat8bit /www/eat8bit

You're going to want to add this to your fstab also. For further reference, check out LVM HowTo - Common Tasks

And that's it. Your new web directory is ready for use, so let's make the directories and edit our apache config.

Setting Up the Web Directory

Let's make the directories:

root@dangerunit0~# mkdir /www/eat8bit/htdocs /www/eat8bit/includes /www/eat8bit/log

And now we edit our vhosts config file:

root@dangerunit0~# vi /etc/httpd/extra/httpd-vhosts.conf

# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
        ServerName eat8bit.com
        DocumentRoot /www/eat8bit/htdocs
        ServerAlias www.eat8bit.com
        ServerAdmin abledanger@eat8bit.com
        ErrorLog /www/eat8bit/log/error_log
        CustomLog /www/eat8bit/log/access_log common
</VirtualHost>

Write the new VirtualHost directive to the file then restart apache:

root@dangerunit0~# apachectl restart

Congratulations!!! You have now completed the setup of your Web Directory on its own LV. For each additional website, just repeat the process from the lvcreate command down.

linux/server/lvm.txt · Last modified: 2008/02/09 09:43 by brent
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki