Write step by step procedure to configure a Linux machine to work with a network file system.

Using NFS to Share Files

NFS (Network File System) is another way of sharing files across a network. It is used primarily in Linux and UNIX systems, although there are NFS clients for Windows.

Installing NFS

1.    Use the following command to install NFS:

        yum -y install nfs-utils nfs-utils-lib

Configuring NFS

Configuration of NFS is pretty simple. You add the directories you wish to export to the file/etc/exports.

2.    Create a directory called /public with the following command:

        mkdir /public

3.    Populate it with three empty files:

       touch /public/nfs1 /public/nfs2 /public/nfs3

4.    Next, edit the file /etc/exports:

        vi /etc/exports

5.    Add the following line to /etc/exports:

       /public    *(ro,sync)

Here's an explanation of the fields in the command:
/public--The directory to be shared

*--The clients allowed to access the share. You can restrict it by IP address. For example, you could, instead of the asterisk, put 

192.168.0.0/24 to restrict it to clients on the 192.168.0.0/24 network.

ro--Read only access

sync--Reply to requests only after any changes have been committed to stable storage. This is a slower, but more stable option than alternatives.

In the following screen capture, you can see how I configured /etc/exports to share /public:

Figure 7: Configuring an NFS shared directory in /etc/exports.

6.    NFS requires the rpcbind service to be running. Start it with the following command:

        service rpcbind start

7.    Then, start the nfs server:

        /etc/init.d/nfs start

        (You could also use service nfs start.

8.    If you want NFS to start at boot, use the following command:

 chkconfig --levels 235 nfs on

9.    Enable the export immediately with the command exportfs -v. You can view the export with the command showmount -e.

If you are using a firewall, you must explicitly allow traffic from your local subnet to access the server.

For more information, see chapter 10 on Linux security.

Configuring the NFS Client

You must install the nfs package on the client with this command:

        yum -y install nfs-utils nfs-utils-lib

Once the package is installed, you can use the showmount command to view exports on an NFS server:

Figure 8: Viewing NFS shares with the showmount command.

You can also create a new directory on your client and mount the NFS export to the directory, thus giving you access to the files in the directory: 

Figure 9: Creating and viewing a mount point for the NFS share.

In the above example, I mounted the export from LinuxServer01 (/public) to a directory on my local client machine, called ubuntuServer02. As you can see, after it was mounted, I was able to view the contents of the exported directory locally.

Using rsync to Synchronize Files between Servers

When administering file servers, you may want to configure replication to help minimize the chance of data loss in the event of a server crash. One way to do that is with the rsync utility, which allows you to seamlessly move one or more files from one server to another. Unlike a simple file copy, however, rsync can perform differential file transfers, transferring only the data that has changed. A benefit of rsync is that mirroring occurs with only a single transmission in each direction.

Installing rsync

Use yum to install rsync with the command: yum install -y rsync. The rsync utility must be installed on both computers participating in the mirroring.

Basic rsync syntax

rsync <options> <source> <destination>

Some common rsync options

  • -a--archive mode, which allows copying files recursively, plus it preservers symbolic links, user and group ownership, file permissions, and timestamps
  • -e--specifies the remote shell to use. This option allows you to use SSH for the transfer
  • -h--human-readable which causes the system to output numbers in a human-readable format
  • -r--copy data recursively without preserving timestamps and permissions
  • -u--updates only files that have changed since the last rsync
  • -v--verbose
  • -z--compress data 

No comments

Powered by Blogger.