实验名称:配置NFS服务


实验过程:


步骤1:基本环境搭建


一台服务器一台主机足矣

步骤2:配置NFS实现共享

首先查看是否安装


[root@dc ~]# rpm -q nfs-utifs portmap


package nfs-utifs is not installed


portmap-4.0-65.2.2.1


[root@dc ~]#


已经安装好了,这样我们就可以直接开启服务。



[root@dc ~]# service portmap restart


启动 portmap:                                             [确定]


关闭 NFS mountd:                                          [确定]


关闭 NFS 守护进程:                                        [确定]


关闭 NFS quotas:                                          [确定]


关闭 NFS 服务:                                            [确定]


启动 NFS 服务:                                            [确定]


关掉 NFS 配额:                                            [确定]


启动 NFS 守护进程:                                        [确定]


启动 NFS mountd:                                          [确定]


Stopping RPC idmapd:                                       [确定]


正在启动 RPC idmapd:                                      [确定]


[root@dc ~]#


进入配置文件


[root@dc ~]# vim /etc/exports


做如下配置,


1 /root 192.168.50.99(rw,sync,)


这样我们就把根目录下的root目录共享给了192.168.50.99主机。并让其拥有可读可写权限,sync表示同步写入。


接下来进入客户机开启nfs服务。并查看已经开启的共享


[root@localhost ~]# showmount -e 192.168.50.253


Export list for 192.168.50.253:


/root 192.168.50.99


[root@localhost ~]#


将共享目录挂载到所需文件


192.168.50.253:/root /mnt/


进入目录


[root@localhost ~]# cd /mnt


bash: cd: /mnt: 权限不够


[root@localhost ~]#


我们发现权限不够,这就对了,因为还有一个参数没有设置。


回到配置文件做如下配置


1 /root 192.168.50.99(rw,sync,no_root_squash)


重启服务。


[root@localhost ~]# cd /mnt


[root@localhost mnt]# ls


111  anaconda-ks.cfg  b.c  c  Desktop  install.log  install.log.syslog


[root@localhost mnt]#


这样我们就进入了共享文件夹。



实验结果:共享的时候要注意权限的问题,如果不小心将重要目录的权限开错了,后果很严重。


实验名称:nfs实现更深层次的文件共享


步骤1:搭建基本环境


打开虚拟机,开一台服务器,两台主机,保证同一网段,我的实验是在4网段完成的。


步骤2:配置nfs


首先,进入服务器,查看nfs是否安装,装了就忽略,没装就安装之,通过YUM或者RPM


[root@dc ~]# rpm -q nfs-utils portmap


nfs-utils-1.0.9-66.el5


portmap-4.0-65.2.2.1


[root@dc ~]# vim /etc/exports


由于我的服务器安装了nfs,所以直接进入配置界面修改。进行如下配置。


#将/root共享给192.168.4.1,并让其具有可读可写权限,同步写入,并且保留root权限


1 /root 192.168.4.1(rw,sync,no_root_squash)


#将/usr/src/共享给192.168.4.0网段,让其具有可读可写权限,同步写入,同时为这个网段中的192.168.4.2主机共享,但是保留root权限。


 2 /usr/src/ 192.168.4.0/24(rw,sync)  192.168.4.2(rw,sync,no_root_squash)


由于实验单单分享一个文件夹太简单,这里我结合起来一起做了。


保存后开启服务,切记要先开启portmap在开启nfs,在运维工作中,我们一般配置完成一个服务后都要将其设为开机启动操作如下。


[root@dc ~]# service portmap start


启动 portmap:                                             [确定]


[root@dc ~]# chkconfig portmap on


[root@dc ~]# service nfs start


[root@dc ~]# service nfs restart


关闭 NFS mountd:                                          [确定]


关闭 NFS 守护进程:                                        [确定]


关闭 NFS quotas:                                          [确定]


关闭 NFS 服务:                                            [确定]


启动 NFS 服务:                                            [确定]


关掉 NFS 配额:                                            [确定]


启动 NFS 守护进程:                                        [确定]


启动 NFS mountd:                                          [确定]


Stopping RPC idmapd:                                       [确定]


正在启动 RPC idmapd:                                      [确定]


[root@dc ~]# chkconfig nfs on


[root@dc ~]#


接下来进入客户机,开启portmap服务和nfs服务。后showmount查看一下


[root@localhost ~]# service portmap start


启动 portmap:                                             [确定]


[root@localhost ~]# service nfs start


启动 NFS 服务:                                            [确定]


启动 NFS 守护进程:                                        [确定]


启动 NFS mountd:                                          [确定]


Stopping RPC idmapd:                                       [确定]


正在启动 RPC idmapd:                                      [确定]


[root@localhost ~]# showmount -e 192.168.4.253


Export list for 192.168.4.253:


/root    192.168.4.1


/usr/src 192.168.4.2,192.168.4.0/24


[root@localhost ~]#


步骤3


接下来挂载,测试


[root@localhost ~]# mkdir -p /nfs/root/


[root@localhost ~]# mount 192.168.4.253:/root/ /nfs/root


[root@localhost ~]# ls /nfs/root


111  anaconda-ks.cfg  b.c  c  ddd  Desktop  install.log  install.log.syslog


[root@localhost ~]#


这样就OK了,下面通过192.168.4.2主机访问/usr/src/目录,


[root@localhost ~]# ifconfig eth0 192.168.4.2


[root@localhost ~]# showmount -e 192.168.4.253


Export list for 192.168.4.253:


/root    192.168.4.1


/usr/src 192.168.4.2,192.168.4.0/24


配置好IP并查看以后


[root@localhost ~]# mount 192.168.4.253:/usr/src /mnt


[root@localhost ~]# ls /mnt


aria2-1.17.1  debug  httpd-2.2.25  kernels  vmware-tools-distrib  webmin-1.630


[root@localhost ~]#


发现是可以的。


本来还需要开一台主机,不过为了防止太卡,我就直接进入配置文件将192.168.4.2root权限恢复成一般,重启服务测试之,发现可以访问共享文件夹,但是建立的文件


[root@localhost ~]# showmount -e  192.168.4.253


Export list for 192.168.4.253:


/root    192.168.4.1


/usr/src 192.168.4.0/24


[root@localhost ~]# mount 192.168.4.253:/usr/src /mnt


[root@localhost ~]# ls /mnt


aria2-1.17.1  debug  httpd-2.2.25  kernels  vmware-tools-distrib  webmin-1.630


[root@localhost ~]# touch /mnt/1.txt


touch: 无法触碰 “/mnt/1.txt: 权限不够


[root@localhost ~]#


这就证明了我们的配置文件权限设置时很严谨的,之所以能访问,是因为这台主机位于192.168.4.0网段,由于它是nfsnobody权限,所以很多操作会受限。




实验结果:结果证明,NFS是很方便快捷实用的,这类配置出来后,要做到秒杀,不需要考虑就配置好了。