In this video, Kevin Dankwardt discusses file sytems on the network. We discuss NFS in particular and he demonstrates how to configure an NFS server and how to mount from NFS.
- [Instructor] All right, so let's talk about Network File Systems for a couple minutes here. So we mean a file system that resides on one or more servers and is remotely mounted to a client. That's different from a remote lock device. There's a couple different choices and they have issues to consider, security issues, stuff encrypted when it moves over the network, for example. And performance issues where the bottle necks.
What about locking of files to make sure things stay consistent. And what about scalability? How many of these can you have at a time? So, when we talk about file systems on a network, we have a single server sort of thing and we've got file systems distributed with redundancy across a network and we've got clustering. In this chapter, we're going to talk about really just a couple of choices for file system coming from one server and you just mount that into your tree.
Later on we'll talk about distributed and cluster sort of file systems. So, NFS is the unix-y way of doing network file systems. It's been around for a really long time. Folks still use it fairly often. It could be handy for home directories, for example. So, as folks move around, you know, in a company to different places, they can mount their home directory on different servers or their Linux laptop or whatever.
NFS is set up to allow computers to do the mounting. Not necessarily people. And when you mount the file system, and usual way into your local machine, the files have all the owner group stuff on 'em. And those are associated with user IDs and group IDs. So, you have to make sure that that's consistent. So, user ID 1007 is the same person on every computer that can mount that file system.
One nice thing about NFS that's handy sometimes with Linux is you can have Linux machines that don't have any kind of disk or aren't using their disk. They can just mount their file system with NFS, that's a feature of the Linux kernel. The other major sort of server-based network file system is CIFS. And on Linux there's a packet cifs-utils let's you mount things of type cifs. So commonly, this means folders from Microsoft Windows server.
Just like you can mount your folder on a different Windows machine, you can mount a Windows folder on a Linux machine. And if you want to make folders or directories, we usually call them on Linux, available to a Windows machine, then you would use Samba, and with cifs, then it comes down to a user password sort of permissions instead of computers. Let's look at a little example with NFS that's a little bit different and have us think about the idea of sharing.
What's going to happen if more than one process maybe on different computers are sharing a file that they've mounted with NFS? Let's see if it works any differently than sharing a file by two different processes on the same machine. So, I've done some configuration here already. If we look at my etc exports file, I'm making a directory temp shared available and I've started NFS and that's all available.
And I have a little program here, little C program that does a little bit of checking. Essentially what it's going to do is you run the program, you give it a file and you give it a string and it's just going to loop 200 times writing the string into the file. So it writes the string, it flushes it out with F sync and it sleeps a second then it writes the string. So, what we could do is run this program more than once and if the different processes are sharing a file, they'll both be writing to the file at the same time.
And we can get an idea of what goes on with that. All right, so that program is called Share F. So, if I just run that, on a file, and we'll tell this one to write an A into that file, and we'll start it in the background and then we're going to run this again and we're going to tell the second process to use the same file, but write a B and then we're going to use the watch command to every one second to cat that file.
And we can watch for a few seconds and see what's going on with that file. Is it all As or Bs or what? All right, so it's kind of mixed up there. We see B-A-B-A, a bunch of Bs, an A, a bunch more Bs and a bunch of As. So it looks like both processes are writing, writing into the file there, back and forth okay and it seems to make sense. So let's kill both of those.
And I'm going to wipe out that file. Just putting a greater than there as the shell, just truncate it to nothing, so now it's an empty file. So that directory is available via NFS so we could mount that on a directory and in fact I've mounted that twice via NFS. I've mounted it on temp sdir1 and on temp sdir2.
All right, so let's have two different processes run and this time we'll have one write to sdir1's copy of the file and the other write to sdir2's copy of the file, and then while they're running, we're going to look at our local copy and let's see if the behavior is pretty much the same or not. So, we'll have this one write to the file via the mounting at sdir1 and we'll have them write a C this time.
And then we'll start up another process. It'll go through sdir2, but they're both going to be talking to the NFS server. It'll write a D. And then we'll look at our local copy of the file, so we got three different ways we can get to that file. We had some Ds and now we got a bunch of Cs. More and more Cs. Lots of Cs.
So now they're going through the NFS server and the behavior is different. That doesn't mean it's wrong. In fact, we can't depend on the behavior. In either case, it's kind of up to the scheduler what stuff runs, but this case is a little bit different. It's not just the scheduler, it's when the NFS server decides to write to the file. Because the two processes that are writing are actually writing via the NFS server and the server's writing to the file.
In the first case, both processes are running to the file. We're getting a long string of Cs. So, definitely the behavior's a little bit different. Neither of these are really recommended, but it gives you an idea of something to think about. And a little different example of using NFS.
- Partitioning storage
- Creating, mounting, and unmounting file systems
- Formatting file systems
- Making volumes with LVM
- Adding storage security
- Managing swap spaces
- Backing up and recovering Linux storage systems
- Working with networked file systems like NFS and SSHFS