Instructor: Network file system,
which also stands for NFS.
This is one of the biggest and major topics,
and I am including this lesson in our module of disks,
because it is actually about sharing your disk,
or sharing your directory, or sharing your files
with other computers and other users.
So Network File System,
as I have explained to you previously,
there are different type of file system,
like ext2, ext3, XFS, NTFS in Windows,
or FAT, FAT file system, that's also in Windows.
Just like that, there is another file system
that is called Network File System.
Now, this file system, again,
it's not local to your computer.
It's called a NAS, which is also a network attached storage.
So NFS is part, is one of the protocol that is part of NAS.
So let's see, NFS stands for network file system,
a file system developed by Sun Microsystems.
Sun Microsystems, if you guys don't know this,
this was a company who actually had
one of the biggest operating system called Solaris.
That Solaris operating system runs on Unix environment,
and it still exists, but now,
Sun Microsystems is being bought out by Oracle.
Anyway, our focus is not Sun or Oracle,
our focus is NFS,
which is one of the Linux or Unix services
to share your file system between servers.
Now, it is a client server system
that allows users to access files across a network
and treat them as if they resided in a local file directory.
It's just that simple.
When you mount it from one system to another,
the other system will see it
as if it actually mounted locally on its own system.
Now, for example,
if you are using a computer
linked to a second computer via NFS,
you could access files on the second computer
as if they resided in a directory on the first computer.
This is accomplished through the process of exporting.
So you export from the server
that is sharing the file system,
the process by which an NFS server provides remote clients
the access to its files,
and mounting, the process by which client,
which is the other computer, the other end,
client map NFS shared filesystem.
So this is how basically NFS works,
and I hope you understand.
If you do not understand,
and you're still confused what NFS is,
please don't worry, I'm here.
Don't worry about it, I will take you every step of the way,
and I will show you how NFS works.
Okay, so now let me show you real quickly
through the pictures, through the diagram,
because pictures speaks a thousand words, right?
So you have a machine, a computer.
It's probably, nowadays, it could be either Linux,
or could be Unix, or could be Windows.
This machine wants to attach a file system
that is being shared from another computer.
So what it does is it sends an NFS request.
That NFS request goes to a server
that is hosting that file system.
So if that file system is hosting,
let's say ABC file system,
or whatever the name of the file system
that is being hosted on this server,
then based on the rules that are defined on the server,
meaning the policies which server to share with,
which server to trust, and all that, once that is satisfied,
then the server is gonna send the approved request
back to its client, and it's gonna say,
"Hey, I know you are asking me
to share my file system with you.
Now, first of all, let me see
if the file system that you want me to share with you,
if I am authorized to share, first of all.
Second, if you are authorized to view that file system."
And of course, there are other options that can be defined,
which we will discuss later on.
Moving on, the Network File System,
what are the steps that we need to do?
Well, there is a server
that is gonna share its file system,
and then there is a client
which is gonna mount that file system, right?
So what are the steps we need to take on the server side?
So in these slides, I'm actually gonna show you
what are the steps we need to take.
Once I'm done with this slide,
then actually I will log into the machine
and we'll do the real work.
So steps are, first on the server side now.
We need to install NFS packages,
and those NFS packages are nfs-utils libnfsidmap.
These are the two packages that you need
on your latest Red Hat or CentOS version 7 servers.
Most likely, they are installed in your machine,
but the way you could check it,
you could check it by running rpm -qa and grepping for NFS,
and you will see if these packages are installed.
We'll check that together, so no worries.
Next thing we will have to do
once these packages are installed,
enable and start NFS services.
So you know that enabling any service,
meaning you are telling that service to start at boot time.
So you want these two services to start at boot time.
That's why we are using the option enable.
Once we enable them,
then I'm going to start the services,
rpcbind, nfs-server, rpc-statd, and nfs-idmapd.
These are four services that I want to start.
I put them all in one line,
but make sure when you are running your command,
they shouldn't be in one line,
because it will give you an error.
I am trying to save some space here,
that's why I'm putting everything in one line.
Okay, moving on.
Then, create NFS shared directory and assign permissions.
So once we are on the NFS servers,
we are gonna create a directory,
or if you already have a directory that you want to share,
then you don't need to do this part
where you have to create and assign permissions.
So in our lab,
we are assuming that we are creating,
or we are sharing a new file system, a new directory.
So I'm gonna name it mypretzels,
and I'm gonna assign the permissions of that to mypretzels.
So mypretzels, I just picked a name,
you could pick anything.
I like this word pretzels,
because that's one of my favorite lines from Seinfeld
that says, "These pretzels are making me thirsty."
So I just picked that name.
Anyway, then we have to modify the permissions
for that mypretzels directory.
Then we had to modify the /etc/exports file,
because the reason we wanted to modify that
is because if you want to have this file system
to be shared, I have to have certain option in it.
So as you could see,
I have put in the IP address, 192.168.12.7.
It means I want mypretzels to be shared
only with the server that has this IP,
and it will have the read write permission.
So let's look at them one by one.
So here is my NFS share,
that's the NFS share that I'm sharing.
Then, here is the IP address of the client machine
from which I'm gonna share my file system with.
Now, what if you wanted to share with everybody?
Then you could just simply put star, the asterisk, yes.
Then next thing, read and write,
you are giving permission to your clients
to read that file system as well as write to it.
Then there's another option, sync.
Sync is telling that all changes
to the according file system
are immediately flushed to the disk.
The respective write permissions,
write operations are being waited for.
So don't wait any longer
when you're writing to this file system from a client,
just write it to the disk right away.
Then the last option we have right here says
root on the client machine
will have the same level of access
to the files on the system as a root server.
So the root server, which this NFS server is coming from,
will have the same permissions as the client root,
so that's what it's saying.
So now, of course, this is for one host,
because we have specified the host name, or the IP address.
But if you want to specify everybody, not just one computer,
then you will use Linux, mylinuxshare...
Oh, sorry, this is not mylinuxshare,
you have to change it to mypretzels.
I had it using before mylinuxshare,
but to make it more meaningful,
I changed it to mypretzels.
Anyway, if the mylinuxshare, whatever Linux share is,
asterisk, and the entire line of options,
that is to give it to everybody.
Then once that is done, you edited the /etc/exports file,
then you export the NFS filesystem
by running the command exportfs, space, -rv.
So what all these different options,
r is to republish everything that is inside of /etc/exports,
and v is to show a verbose mode.
So hopefully you understand this NFS configuration
on the server side,
the server which is trying to share its file system.
So in our example, our NFS server
is our lab server that we have built for this training.
And remember, the host name for that lab server
is MyFirstLinuxVM, right?
That's the one we created, right?
So let me go to my Linux VM, and let me log in real quick.
Okay, and let's do hostname.
You see, MyFirstLinuxVM,
this is the Linux VM that we've been working on, right?
So this is going to be our NFS server
where we will create our file system
to be shared with other servers, okay?
So now we will export it, we will enable, sorry,
we'll install the packages, enable these services,
start the services,
create what we need to create, what we need to share,
change the permissions,
then modify the /etc/exports file to have that shared.
Moving on to the next slide,
now, steps for NFS client configuration.
Now of course, you have one server,
which is MyFirstLinuxVM, right, that server configuration.
Now we are going to create another machine
that will actually mount that file system
on its mounted point, whichever that you need to define.
So what we are gonna do is
we are gonna install these packages,
yum install nfs-utils rpcbind,
same packages as NFS server.
Then we are gonna start, once the packages are installed,
enable and start rpcbind service.
You have to make sure
only this service has to be up and running, rpcbind start.
Then, make sure there's no firewall or IP tables
running in your system, the client.
Then we'll do a showmount command
to see what is available for me to mount.
Then create a mount point, like mkdir /mnt/app,
or /mnt/, let's say kramer,
whatever that you wanted to do, you could do that.
Just like that, I have it right here.
So mount the file system, like mount.
The name of the IP address of the NFS server,
/mypretzels, which is the shared file system,
mount to kramer, or mount to app,
or whatever the mount point that you want to make.
Then verify the mounted file system
by running the command df -h,
and to unmount that file system is umount /mnt/kramer.
So that's it, folks.
Enough talking now.
I'm sure we probably heard a lot of things.
Now let's do the real work.
Let me go back to my NFS server configuration,
and that's where we are gonna start off with.
So I am going into my Linux machine,
and the Linux machine is MyFirstLinuxVM.
How I am logged in, whoami,
and which directory I'm in,
and which host I'm on.
Verified everything, perfect.
Now, go ahead and become root.
Okay, we are root.
Now, before you install these packages,
you could run rpm command
to verify if these packages already exist or not.
And you see, it tells you that nfs-utils
and libnfsidmap are already installed.
Now, if you try to install it with yum command,
let's say say yum install nfs-utils,
it'll go out on the repository,
but it'll say, right here, see,
this package nfs-utils already installed
and has the latest version, perfect.
So we've been through the first install NFS package.
Okay, done.
Second thing, we need to enable the rpcbind
and NFS server service.
So the command to do that is systemctl enable rpcbind.
Perfect.
You get the prompt back, it means it worked.
Then you do the same thing by doing the up arrow key.
Instead of rpcbind, do nfs-server,
because it's nfs-server, right, yes.
Hit Enter.
Okay, created symbolic link, this, this, this.
Why I didn't create it before, maybe we have already,
or I have already enabled that rpcbind previously,
and that's why the the link was there.
But anyway, I am enabling
this nfs-server for the first time,
and that's why it's saying created symbolic link,
which is what it's supposed to do.
Okay, anyway, so now the time to start the service,
systemctl start rpcbind.
Okay, it started, see, it didn't give me any error message.
If I wanted to check the status of that service,
I'll do status, systemctl status rpcbind, and you'll see,
it says right here, active, loaded, and running.
This is what we wanted to see, perfect.
Now, next service I wanted to start is nfs-server.
See right here, it says nfs-server.
Hit Enter.
This should start the service, rpc-statd, right?
Let's confirm, rpc-statd, yes, hit Enter.
Okay, it is up and running, perfect,
and I could just do start again.
It started.
Let's check the status, running, okay, perfect.
Next one, nfs-idmapd.
It started, now let's check the status.
Active and running, perfect.
Now it's time to create our shared file system.
So I'm gonna go into my cd / directory.
You see I am in / cd, /, just /.
Now I'm gonna create a directory called mkdir mypretzels.
Okay, I am in /, and ls -l,
and you'll see it is created right here,
and I could do ls -ltr to see it at the bottom.
Now I need to assign the proper permission.
So I'll do chmod a, for all, +rwx mypretzels.
Hit Enter.
See, these are all the rights.
Okay, perfect.
Now I already have my directory,
let me go into mypretzels directory.
Okay, what's inside mypretzels directory, nothing right now.
Okay, I could create a couple of files, like touch a b c.
All right, perfect.
I could also create a file called touch kramer,
and I could echo into the file.
These pretzels are making me thirsty.
And I'm gonna output to kramer, kramer file.
Perfect, let's echo kramer file.
Cat, sorry, cat kramer file.
And you'll see these pretzels are making me thirsty.
Now, this directory, mypretzels has how many files?
Four, a, b, c, and kramer.
So that's good enough for our testing.
Now, what we need to do?
The next thing we have to edit the /etc/exports.
So vi /etc/exports.
Since we are doing that for the first time,
you will see this file is empty.
Be very careful.
To modify it, I always, what I'll do is
I always do cpy /etc/exports,
and then /etc/exports, underscore,
I put a date in, like 08082020.
So this way, if I make a mistake,
I could always copy it back to its original version.
So now I could go into vi /etc/exports.
But anyway, this was empty.
So now what do I want to export?
First of all, what I'm trying to export,
I am going to export /mypretzels.
Okay, perfect.
Who am I exporting it to?
I want to export it to everyone.
If you want to export it to your other Linux machine,
which we will build later on,
and you have the IP, and you want to come back here
and specify the IP, you could do it,
but for now, I'm just gonna do asterisk.
Now, then I have to specify asterisk, parentheses,
rw, read, write, comma, sync, comma, no_root_squash.
And that's it, this is what we need.
So if you guys need to know the exact instruction,
I'll try to put it in,
this entire instructions right here you see on my slide,
I'll put it into the notes folder, the notes section.
Okay, so now that file is edited,
go ahead and save that file.
Perfect.
What do we need to do, the last thing?
Export that file system.
Okay, go ahead and type the command exportfs -rv.
Again, r stands for to republish everything,
whatever's in there, publish it again,
doesn't, I don't really care.
And then v is the verbose mode.
Hit Enter, and now it is telling you that exporting,
it is exporting the file system to everybody,
and the file system is mypretzels.
Okay, so you have created it, your NFS server is ready,
it is exporting to other machines.
Now the question is,
I do not have another Linux machine
to test mounting this file system to another machine.
So what I'm going to do
is I am going to build another machine,
which is going to be client,
and I will show you how to build that.
The whole thing I'm gonna do
by building another Linux machine,
I'm gonna do it really fast.
I'm gonna fast forward it,
because since you guys have already
have experience of creating another Linux virtual machine.
So I'm gonna go do it really fast.
So right now, if you could see,
if I go into my Oracle VM VirtualBox,
then I'm gonna go ahead and create new.
I'm gonna name it monk, monks.
Monks is a name of Seinfeld show,
that's a restaurant where everybody goes.
So it's like a shared environment,
so I'm using this as a client name, so monks.
And Windows, Microsoft Windows.
I'm gonna pick Linux,
because you're building a Linux machine.
And now pick Linux 2.6/3.x/4.x 64-bit.
Now go ahead, click Next.
Memory size, leave it default.
Create new disk.
New disk dynamically created, Next, you already know that.
The size of the disk that will be created is eight gig,
leave it default, Create.
It is created.
Now, monks, the VM is created, now go ahead and power on.
This is asking you where is your ISO image?
Remember, we actually downloaded our CentOS ISO image.
If you do not have that ISO image right now, it's okay.
You could go ahead and download again from the Internet.
And once you have that downloaded,
come back and start again from this lesson
on how you could select it.
And I'm sure you know this, how to select it.
So here, go ahead and pick the location,
I already have the location picked,
and it is this Windows, CentOS 7.
I'm gonna click Open, and Start.
Now this is going to start the installation.
By default, it tells you this,
test media and install CentOS,
so go ahead, hit up arrow key,
and click on install CentOS, and hit Enter.
Okay, from this time, from this point on,
I am going to fast forward the entire installation.
Okay, so you notice I am going to pick the minimum install.
What minimum install means
that there is not gonna be any GUI installed.
I don't really need GUI at this time.
I just wanna test my mounting NFS file system,
and that's why I'm gonna leave it default.
The installation destination, you can click on it,
and select the disk, and leave everything as is,
automatically configured partitioning, go up and click Done.
And then come down, you'll see the network host name.
It says not connected, click on it.
Go up, turn this on, and now give it a host name.
I pick the VM host name as monks,
so I'm gonna use the same name, monks.
Click Apply, and it'll say the current host name is monks.
Go up, click Done.
So everything is set up, Americas/New York timezone.
You could pick different timezone according to your region.
Language, installation source, local media,
software installation minimum.
As I said, we don't need a GUI,
and we don't need any other extra softwares.
Come down, installation destination, we picked it already,
which is the default, everything is default.
And now go ahead and click Begin installation.
Once it begins installation, click on root password,
specify the root password.
If it's weak, you will have to enter,
you have to click Done twice.
User creation, I don't wanna create any user right now.
Okay, so now you'll see
it is going through the installation process
of installing 303 packages,
and right now, it is at 15 packages,
so it's gonna take time.
I'm gonna fast forward again from here,
and when we come back, we should have a built up machine.
All right, everyone, our machine,
the second machine, client monks is being built.
Go ahead and log in as root.
So now check the IP address of this machine.
Okay, it does not have the network utilities that you need
to check the ifconfig,
but there is another command that we learned previously,
it's ip, ip addr, yes.
So you notice you have an IP address of 10.0.15.
So if your IP address is different in the other servers,
let's check our server.
My IP address here is, ifconfig, it is 192.168.1.18,
and its IP address,
the other machine's IP address is different.
The reason is we have to change the setting
on the VirtualBox.
So that's the machine, go to Settings.
Go to Network, and you see it's right here,
it says attached to NAT?
Change it to bridged network adapter,
and Broadcom NetXtreme Gigabit Ethernet.
If you have a Wi-Fi, you pick that one, click Okay.
Now it should have a new address.
If it doesn't,
then run the command systemctl restart network.
It has restarted.
Now you check ip addr,
and you'll see the new IP I have right here is 192.168.1.11.
So from here, make sure you press right click
to get out of this machine box.
So you could go ahead and ping 192.168.1.11,
just to make sure you could, oh, not one, 11,
make sure you could ping it.
Yes, you see you're getting a response back.
Perfect.
So now let's go back to our machine.
Also try to do ping www.google.com,
to make sure your machine can get to the Internet,
yes, it can.
Go ahead and clear the screen.
Now we'll get back to our lesson,
where we have to actually go to the client.
So we have to install nfs-utils rpcbind.
yum install nfs-utils.
It found one package, 15 dependencies.
Go ahead and hit Y as yes, hit Enter.
Perfect, it's finished.
Now, the next thing, we have to do rpcbind.
yum install rpcbind, one word.
And this time, do -y option.
Okay, it says it's already installed, perfect,
so we don't need any of these more packages,
so now what next?
We have to start that rpcbind service.
So do, instead of service,
you have to do systemctl,
because service is an older command
that works with Red Hat 6, or CentOS 6, start rpcbind.
It is started, you could check by doing ps -ef, grep rpc,
and you'll see it is up and running now.
Let's make sure the firewall or IP tables is not running.
ps -ef, egrep, firewall or IP table.
So we see that both, no, only firewalld is running,
so let's stop that.
So systemctl stop firewalld.
This is going to stop that,
also disable that service to start at boot.
Okay, it is disabled.
showmount.
showmount from which machine?
showmount -e.
What is the IP address of our other server,
NFS server machine?
So let's go to our other NFS machine,
and check our IP address, ifconfig, or ip addr,
whichever command you prefer.
It's 192.168.1.18.
So let's go back and do showmount 192.168.1.18.
And this should return
what is being shared from that server.
Okay, it's saying unable to receive, error number 113,
no route to host.
So let's ping first, 68.1.18.
I can ping it, but I cannot, it's not showing me the mount.
Let's check on the server side,
if the server side is running IP tables.
Oh, so there's a firewall
on the server side that is running, we have to disable that.
Okay, so now that firewall is disabled,
let's check on the client side again,
and see if you could view the showmount.
Ah, perfect.
Now we see the showmount.
So now let's go to our document.
We have verified it, now we have to create a directory
where we have to mount it on our client.
So let's clear the screen, and now create a directory.
We call it mkdir, under mnt, we'll call it kramer.
All right, so let's do ls -l /mnt, we'll see the kramer.
Let's do the mount, mount 192.168.1.18:/mypretzels.
And map it where?
Map it to /mnt/kramer.
Okay, we got the prompt back, perfect,
it means it did mount.
Hit df -h, or type df -h,
and you'll see right at the bottom,
it's coming up as /mnt/kramer.
Now, if I go to cd /mnt/kramer, and do ls -ltr,
you see I have the same files now
that I created on my server, which is right here.
And if you go to cd /mypretzels, ls -ltr.
So these are the file systems.
So now, if I wanted to write something to this,
let's say from the client side,
I'm gonna create a file called touch david, hit Enter.
Verified, and it created on the client side.
Now let's see if it shows up on the server side,
and you see it's showing up on the server side.
The last thing that I want to cover here
is you verified it,
and if you want to unmount that from the client,
then you could just simply do umount /mnt/kramer.
You can mount the mount point,
or you can mount the file system, whichever way you like.
So when you hit Enter, it's gonna say device is busy, why?
Because you are already inside of that directory.
So you get out of that directory, do cd, hit Enter.
Now you're not in that directory.
Now hit up arrow key, and do the umount,
and it has unmounted.
Do a df -h, and you'll see it is not there, it is gone.
So guys, that's how you do the NFS.
Try it.
It's a very, very important lesson,
and a lot of people ask for NFS services,
and I'm including this in this training
because a lot of students have asked me on NFS,
so that's why I decided to create that for you.
All right guys, good luck.