每天五分钟轻松学运维2019-05-21: NFS服务器部署–技术流ken

部署NFS服务器实现linux与linux 之间的文件共享
服务器端配置:
第一步:下载nfs和rpcbind
[root@ken test]# yum install nfs-utils rpcbind -y
第二步:配置nfs的文件
[root@ken ~]# vim /etc/exports
/test 192.168.64.5/24(rw)
第三步:重启nfs和rpcbind
[root@ken ~]# systemctl restart rpcbind nfs
客户端配置:
第四步:客户端下载nfs-utils
如果不下载nf会报如下的错误:
[root@ken ~]# mount -t nfs 192.168.64.4:/test /test
mount: wrong fs type, bad option, bad superblock on 192.168.64.4:/test,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog – try
dmesg | tail or so.
[root@ken ~]# yum install nfs-utils -y
第五步:查看共享的文件信息
[root@ken ~]# showmount -e 192.168.64.4
Export list for 192.168.64.4:
/test 192.168.64.5/24
第六步:挂载NFS至本地目录
[root@ken ~]# mount -t nfs 192.168.64.4:/test /test
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.5G 16G 9% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 14M 474M 3% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /mnt
192.168.64.4:/test 17G 1.5G 16G 9% /test
解决NFS文件共享无法创建文件的问题
第一步:客户端测试
[root@ken test]# touch test1
touch: cannot touch ‘test1’: Permission denied
第二步:服务器端更改共享文件的属主
[root@ken test]# chown -R nfsnobody: /test
第三步:客户端再次进行测试
[root@ken test]# touch test1
[root@ken test]# ls
ken test test1
NFS共享给多个客户端
方法一:
[root@ken test]# cat /etc/exports
/test 192.168.64.5/24(rw) 192.168.64.7/24(rw)
方法二:
[root@ken test]# cat /etc/exports
/test 192.168.64.0/24(rw)
方法三:
[root@ken test]# cat /etc/exports
/test *(rw)
NFS服务器共享多个目录
第一步:
[root@ken test]# cat /etc/exports
/test 192.168.64.5/24(rw)
/test1 192.168.64.7/24(rw)
第二步:客户端挂载
[root@ken test]# cat /etc/exports
/test 192.168.64.5(rw)
/test1 192.168.64.7(rw)
第三步:客户端进行验证
[root@ken ~]# mount -t nfs 192.168.64.4:/test1 /test
mount.nfs: access denied by server while mounting 192.168.64.4:/test1
[root@ken ~]# mount -t nfs 192.168.64.4:/test /test
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.5G 16G 9% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 14M 474M 3% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /mnt
192.168.64.4:/test 17G 1.5G 16G 9% /test