NFS service configuration linux

Configuration [ NFS ]

 

         NFS configuration is still quite simple, just need to edit the configuration file / etc / exports can be. Here the author to create a simple NFS server.

 

[root@localhost ~]# cat /etc/exports

 

/home/  10.0.2.0/24(rw,sync,all_squash,anonuid=501,anongid=501)

 

This configuration file is as simple as a line. Is divided into three parts, the first part is to be shared out local directory, the second part is allowed to access the host (can be an IP may also be an IP segment) The third part is a small parenthesis inside, for a number of option rights. On the third part, the author briefly explain:

 

RW  : read and write;

 

RO  : Read-only;

 

Sync  : synchronous mode, data is always written to the disk memory;

 

the async  : are not synchronized, the in-memory data written to disk on a regular basis;

 

no_root_squash  : After adding this option, root user will have supreme authority control over the shared directory, the directory is the same as the operation of the machine. Insecure, not recommended;

 

root_squash  : and above the corresponding options, root user permissions to the shared directory is not high, only normal user privileges that restrict root ;

 

all_squash  : Whether using NFS users who, his identity will be limited to become a regular user specified;

 

the anonuid / anongid  : and to root_squash  and  all_squash used together, used to specify NFS after a user defined uid and GID , provided that the machine / etc / passwd present in the uid and GID .

 

Describes the relevant authority of the above options, the author has just come to analyze the configuration of the / etc / exports file. Directory for which you want to share / Home , trusted hosts for the 10.0.2.0/24 network segment, permission to read and write, sync, define all users and defines the uid and gid are 501 .

 

Use [ NFS ]

 

         When finished editing the configuration file / etc / exports after, in relation to start NFS served. Start method:

 

[root@localhost ~]# service portmap start; service nfs start

 

NFS is relying on portmap , so we must first start portmap , and then start the NFS can be just the configuration to take effect. End Start NFS after, in relation to the use of NFS served.

 

[the root @ localhost ~] # the showmount -e 127.0.0.1  (with the client on)

 

Export list for 127.0.0.1:

 

/home 10.0.2.0/24

 

With shoumount -e  plus IP can view NFS shared case, the example above, you can see 127.0.0.1 shared directory is / Home , trusted hosts for the 10.0.2.0/24 network segment. Also this showmount  command there is a commonly used option is -a , and it means that the connection of the machine NFS 's client list all of them.

 

[root@localhost ~]# mount -t nfs 10.0.2.69:/home /mnt client上)

 

[the root @ localhost ~] # the showmount -a  ( NFS server)

 

All mount points on localhost:

 

10.0.2.69:/home

 

In front of the mount  command to mount the NFS shared directory, I believe you can read this format. showmount -a  command lists all Clinet .

 

NFS services as well as a frequently used commands that exportfs , which is commonly used options for [-aruv] .

 

-a  : All mount and unmount;

 

-r  : remount;

 

-u  : Uninstall a directory;

 

-v  : display the shared directory;

 

Use exportfs command when changing / etc / exports after the configuration file without restarting the nfs service directly with the exportfs can be.

 

[root@localhost ~]# cat /etc/exports

 

/tmp/   10.0.2.0/24(rw,sync,no_root_squash)

 

[the root @ localhost ~] # the exportfs -arv  ( NFS server)

 

exporting 10.0.2.0/24:/tmp

 

更改目录后,直接exportfs -arv即可生效。

 

在上面使用到了mount命令来挂载nfs,其实mount这个nfs服务还是有些说法的。首先是用-t nfs 来指定挂载的类型为nfs。另外在使用nfs时,常用一个选项就是nolock了,即在挂载nfs服务时,不加锁。

 

[root@localhost ~]# mount -t nfs -o nolock 10.0.2.69:/tmp /mnt/

 

[root@localhost ~]# showmount -a

 

All mount points on localhost:

 

10.0.2.69:/home

 

10.0.2.69:/tmp

 

另外我们还可以把要挂载的nfs目录写到client上的/etc/fstab文件中,挂载时只需要mount -a即可。

 

[root@localhost ~]# cat /etc/fstab

 

LABEL=/                 /                       ext3    defaults        1 1

LABEL=/boot             /boot                   ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

LABEL=SWAP-hda2         swap                    swap    defaults        0 0

10.0.2.69:/tmp          /mnt                    nfs     nolock          0 0

 

 

写完/etc/fstab文件后,只需要mount -a即可挂载nfs服务的共享目录。

 

[root@localhost ~]# umount /mnt/ 首先把刚才挂载的nfs卸载掉

 

[root@localhost ~]# mount -a

 

[root@localhost ~]# df -h

 

Filesystem            Size  Used Avail Use% Mounted on

/dev/hda3             7.3G  3.7G  3.3G  53% /

/dev/hda1              99M   12M   83M  12% /boot

tmpfs                  84M     0   84M   0% /dev/shm

10.0.2.69:/tmp        7.3G  3.7G  3.3G  53% /mnt

 

关于NFS部分就讲这么多,内容并不多,相信你很快就能掌握!

Guess you like

Origin www.cnblogs.com/pgh777/p/11692518.html