Centos7安装配置NFS服务和挂载
一、安装 NFS 服务器所需的软件包:
yum install -y nfs-utils
二、编辑exports文件,添加从机
vim /etc/exports
/home/nfs/ 192.168.10.0/24(rw,sync,fsid=0)
同192.168.10.0/24一个网络号的主机可以挂载NFS服务器上的/home/nfs/目录到自己的文件系统中
我自己写了*
内容如下
[root@nfs ~]# cat /etc/exports
/home/nfs/ *(rw,sync,no_subtree_check,no_root_squash,fsid=0)
#w表示可读写;sync表示同步写,fsid=0表示将/data找个目录包装成根目录;no_root_squash表示如果用户是root登陆的该挂载目录,那么他也拥有对应的路径下的root权限
三、启动nfs服务
先为rpcbind和nfs做开机启动:(必须先启动rpcbind服务)
systemctl enable rpcbind.service
systemctl enable nfs-server.service
然后分别启动rpcbind和nfs服务:
systemctl start rpcbind.service
systemctl start nfs-server.service
确认NFS服务器启动成功:
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
rpcinfo -p
检查 NFS 服务器是否挂载我们想共享的目录 /home/nfs/:
exportfs -r
#使配置生效
exportfs
#可以查看到已经ok
/home/nfs *
四、在从机上安装NFS 客户端
首先是安裝nfs,同上,然后启动rpcbind服务
yum install -y nfs-utils
先为rpcbind做开机启动:
systemctl enable rpcbind.service
然后启动rpcbind服务:
systemctl start rpcbind.service
注意:客户端不需要启动nfs服务
检查 NFS 服务器端是否有目录共享:showmount -e nfs服务器的IP
[root@nfs ~]# showmount -e 192.168.10.160
Export list for 192.168.10.160:
/home/nfs *
五、测试NFS
在从机上使用 mount 挂载服务器端的目录/home/nfs到客户端某个目录下:
cd /home && mkdir nfs
mount -t nfs 192.168.248.208:/home/nfs /home/nfs
df -h 查看是否挂载成功。
[root@localhost home]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 18G 33G 35% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 145M 870M 15% /boot
/dev/mapper/centos-home 46G 33M 46G 1% /home
tmpfs 379M 0 379M 0% /run/user/0
192.168.10.160:/home/nfs 24G 32M 24G 1% /home/nfs
已经存在挂载点
测试创建文件是否会产生在nfs服务器上
创建完毕之后
umount -t nfs 192.168.248.208:/home/nfs /home/nfs
查看测试服务器上/home/nfs下有没有数据,nfs服务器的/home/nfs上有没有数据。结果是测试服务器上的文件夹是空的,nfs服务器上有创建的数据,证明数据是存储在nfs服务器上的。