假设现在有2台Centos7的服务器,【服务器server:192.168.11.1】 和【客户机client:192.168.11.2】
一、服务部署
【服务器server】部署NFS服务
rpm -qa | grep nfs
yum -y install nfs-utils rpcbind
vim /etc/exports
/app/test *(rw,sync,no_root_squash) 配置说明: 1、/app/test:这个是本地要共享出去的目录; 2、*:指的是允许的ip地址指的是【客户机client】,*表示所有;可以是一个IP:192.168.227.4,也可以是一个IP段; 3、(rw,sync,no_root_squash): 1)rw表示可读写,ro只读; 2)sync :同步模式,时时写入磁盘;async :不同步,定期写入磁盘; 3)no_root_squash :加上这个选项后,root用户就会对共享的目录拥有至高的权限控制,就像是对本机的目录操作一样。 不安全,不建议使用; root_squash:和上面的选项对应,root用户对共享目录的权限不高,只有普通用户的权限,即限制了root; all_squash:不管使用NFS的用户是谁,他的身份都会被限定成为一个指定的普通用户身份; 4)anonuid/anongid :要和root_squash 以及all_squash一同使用,用于指定使用NFS的用户限定后的uid和gid ,前提是本机的/etc/passwd中存在这个uid和gid。 5)fsid=0表示将/app/eweb整个目录包装成根目录 比如这样配置:/app/test *(rw,sync,no_root_squash,fsid=0) 复杂配置示例:/app/test 192.168.1.8/24(rw,no_root_squash,no_all_squash,sync,anonuid=501,anongid=501)
exportfs -arv
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs.service
rpcinfo -p
mkdir /app/test
showmount -e 192.168.11.1
【客户机client】部署NFS服务
rpm -qa | grep nfs
yum -y install nfs-utils
systemctl enable rpcbind.service
systemctl start rpcbind.service
showmount -e 192.168.11.1
mkdir /app/test
mount -t nfs 192.168.11.1:/app/test/ /app/test
df -h
二、共享追加
vim /etc/exports
/app/test2 *(rw,sync,no_root_squash)
exportfs -arv
showmount -e 192.168.11.1
showmount -e 192.168.11.1
mkdir /app/test2
vim /etc/fstab
192.168.11.1:/app/test2 /app/test2 nfs rw
mount -t nfs 192.168.11.1:/app/test2/ /app/test2/
mount -a