NFS搭建
Posted suffergtf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NFS搭建相关的知识,希望对你有一定的参考价值。
一、环境
nfsserver01:192.168.127.100 centos7.3
nfsclient01:192.168.127.101 centos7.3
二、NFS原理
三、安装测试
1、nfsserver安装
[[email protected] ~]# yum install rpcbind nfs-utils -y
[[email protected] ~]# mkdir /Share
[[email protected] ~]# chmod 755 /Share
[[email protected] ~]# ll -d /Share
drwxr-xr-x. 2 root root 6 8月 16 10:42 /Share
[[email protected] ~]# mkdir /Share
[[email protected] ~]# chmod 755 /Share
[[email protected] ~]# ll -d /Share
drwxr-xr-x. 2 root root 6 8月 16 10:42 /Share
[[email protected] ~]# vim /etc/exports
#######shared for test by suffergtf at 2018-8-16######
/Share 192.168.127.0/24(rw,sync)
[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# systemctl enable rpcbind
[[email protected] ~]# netstat -lntup|grep rpcbind
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 10432/rpcbind
tcp6 0 0 :::111 :::* LISTEN 10432/rpcbind
udp 0 0 0.0.0.0:855 0.0.0.0:* 10432/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 10432/rpcbind
udp6 0 0 :::855 :::* 10432/rpcbind
udp6 0 0 :::111 :::* 10432/rpcbind
[[email protected] ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[[email protected] ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 40390 status
100024 1 tcp 56253 status
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 50142 nlockmgr
100021 3 udp 50142 nlockmgr
100021 4 udp 50142 nlockmgr
100021 1 tcp 32899 nlockmgr
100021 3 tcp 32899 nlockmgr
100021 4 tcp 32899 nlockmgr
[[email protected] ~]# showmount -e localhost
Export list for localhost:
/Share 192.168.127.0/24
2、nfsclient安装
[[email protected] ~]# yum install rpcbind nfs-utils -y #nfs-utils可不安装
[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# systemctl enable rpcbind
3、测试连接
[[email protected] ~]# showmount -e 192.168.127.100 clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host) ##关闭server,client端防火墙和selinux
######nfsserver端
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[[email protected] ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
######nfsclient端同上
[[email protected] ~]# showmount -e 192.168.127.100
Export list for 192.168.127.100:
/Share 192.168.127.0/24
[[email protected] ~]# mount -t nfs 192.168.127.100:/Share /mnt
[[email protected] mnt]# echo ‘mount -t nfs 192.168.127.100:/Share /mnt‘ >>/etc/profile
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 1.2G 17G 7% /
devtmpfs 227M 0 227M 0% /dev
tmpfs 237M 0 237M 0% /dev/shm
tmpfs 237M 4.6M 232M 2% /run
tmpfs 237M 0 237M 0% /sys/fs/cgroup
/dev/sda1 97M 89M 8.6M 92% /boot
tmpfs 48M 0 48M 0% /run/user/0
192.168.127.100:/Share 18G 1.2G 17G 7% /mnt
[[email protected] mnt]# touch 1.test
touch: 无法创建"1.test": 权限不够
[[email protected] ~]# cat /var/lib/nfs/etab ######查看默认共享参数
/Share 192.168.127.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,secure,root_squash,no_all_squash)
[[email protected] ~]# ll /Share/ -d
drwxr-xr-x. 2 root root 6 8月 16 10:42 /Share/ ###共享文件属主为root,挂载的客户端root用户,被转换成nfsnobody用户,所以没有权限
[[email protected] ~]# chown nfsnobody.nfsnobody /Share
[[email protected] ~]# ll /Share/ -d
drwxr-xr-x. 2 nfsnobody nfsnobody 6 8月 16 10:42 /Share/
[[email protected] mnt]# touch 1.test
[[email protected] mnt]# ll /mnt/
总用量 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 8月 16 11:22 1.test
以上是关于NFS搭建的主要内容,如果未能解决你的问题,请参考以下文章