Over this past summer I had the pleasure of cobbling together a few spare parts in order to build a Network Attached Storage (“NAS”) box based on FreeNAS. This device has more than fulfilled my initial requirements for reliable file storage and media server in my network. This post will describe how I configured this FreeNAS box to store web files and serve as a document root for the Apache http server implemented in my Ubuntu server. This approach places my local web files on a solid, reliable and centralized RAID 5 disk storage system, and provides good logical and physical separation between file storage and file server functionality.
The versions for the software used in this post were as follows:
FreeNAS v0.7.1 Shere (revision 5127) Ubuntu Server v10.04 LTS (x64) Apache v2.1.14 nfs-common v1:1.2.0-4ubuntu4 portmap v6.0.0-1ubuntu2 Configuring the FreeNAS Server
I began by creating the directory www on /mnt/files, an existing mount point. This directory would serve as my new Apache document root. Then, I enabled the Network File System (“NFS”) service in FreeNAS so that /mnt/files/www could be accessed from the Ubuntu server. To do this, navigate to Services->NFS->Settings and make sure that the check box for enabling NFS is checked and specify the number of servers that will run (the default value of four should easily handle dozens of users). Now select “Save and Restart.” Next, navigate to Services->NFS->Shares and select the “+” icon, where you are presented with the configuration screen for creating a new NFS share. Enter the path to be shared; the network that is authorized to access this shared path; and, make sure that the “All dirs” checkbox selected. The remaining options can retain their defaults (See Figure 1). Now select “Add” then “Apply changes.”
Configuring the Ubuntu Server
To configure the Ubuntu server I needed to add a couple of packages in order to mount the NFS shared path without error. The nfs-common package is needed when a host acts as an NFS client, and includes a number of processes that ensure a particular NFS connection is allowed and may proceed. Because NFS relies upon remote procedure calls to function, the package portmap is also needed to map RPC requests to the NFS service:
This concludes the post on how to configure a FreeNAS server as an Apache document root, providing a reliable way to store your web files, while at the same time utilizing the Ubuntu and Apache servers for what they do best – serving up those files.
The versions for the software used in this post were as follows:
I began by creating the directory www on /mnt/files, an existing mount point. This directory would serve as my new Apache document root. Then, I enabled the Network File System (“NFS”) service in FreeNAS so that /mnt/files/www could be accessed from the Ubuntu server. To do this, navigate to Services->NFS->Settings and make sure that the check box for enabling NFS is checked and specify the number of servers that will run (the default value of four should easily handle dozens of users). Now select “Save and Restart.” Next, navigate to Services->NFS->Shares and select the “+” icon, where you are presented with the configuration screen for creating a new NFS share. Enter the path to be shared; the network that is authorized to access this shared path; and, make sure that the “All dirs” checkbox selected. The remaining options can retain their defaults (See Figure 1). Now select “Add” then “Apply changes.”
Configuring the Ubuntu Server
To configure the Ubuntu server I needed to add a couple of packages in order to mount the NFS shared path without error. The nfs-common package is needed when a host acts as an NFS client, and includes a number of processes that ensure a particular NFS connection is allowed and may proceed. Because NFS relies upon remote procedure calls to function, the package portmap is also needed to map RPC requests to the NFS service:
sudo apt-get install nfs-common portmapNext, I created a directory so I could mount the NFS shared path. Here you must include the IP address of the FreeNAS server as well as the directory created on it previously:
sudo mkdir /media/wwwIn order for the shared path to mount automatically at boot time, I added the following lines to the /etc/fstab file:
sudo mount 192.168.10.5:/mnt/files/www /media/www
###Start iceflatlineI made sure the directory permissions were set correctly, and modified the owner and group associated with /media/www so that the Apache http server could access it:
#Mount the FreeNAS directory /mnt/file/www for use as an Apache document root
192.168.10.5:/mnt/files/www /media/www nfs defaults 0 0
###End iceflatline
sudo chmod 755 /media/wwwThen edited the /etc/apache2/apache2.conf file, adding an alias for /media/www and a directory directive to the end of the file:
sudo chown www-data -R /media/www
sudo chgrp www-data -R /media/www
###Start iceflatlineI created an index.html file and moved it to /media/www to test the above configuration, and made sure the file permissions were set correctly:
#Alias and directive for FreeNAS directory /mnt/file/www
Alias /www “/media/www”
<Directory “/media/www”>
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
###End iceflatline
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<body>
<h1>
The FreeNAS document root works!
</h1>
</body>
</html>
sudo chmod 644 /media/www/index.htmlFinally, I restarted the Apache http server:
sudo /etc/init.d/apache2 restartConclusion
This concludes the post on how to configure a FreeNAS server as an Apache document root, providing a reliable way to store your web files, while at the same time utilizing the Ubuntu and Apache servers for what they do best – serving up those files.
No comments:
Post a Comment