NFS(Network File System)是一种分布式文件系统协议,它允许计算机系统通过网络共享文件

nfs feature

  • 跨平台性

install nfs-server

1.安装nfs相关包

yum -q install -y nfs-utils rpcbind

2.创建共享目录及权限调整

mkdir -p /opt/share
useradd share && chown -R share: /opt/share
chmod a+w /opt/share

3.配置共享策略

tee <<EOF >/etc/exports
/opt/share 10.* (rw,sync,no_root_squash)
EOF

nfs-client ip访问控制,默认不做控制 10.10.10. 172.*

4.启动nfs服务

systemctl enable rpcbind --now && systemctl enable nfs --now

5.刷新nfs

exportfs -rv  && showmount -e localhost

6.客户端挂载测试

1.nfs-client使用需要安装nfs-utils
yum install -y nfs-utils

2.mount
mount -t nfs 172.24.20.20:/opt/nfs_root /mnt   //remote mount
touch /mnt/sb && rm -rf /mnt/* 

3.umount
umount /mnt

nfs-server 一键安装脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
set -e

## support centos6/7

#define vars
share_dir=${1:-/xx/nfs_root}
ip_limit=${2:-*}

#judge centos6/7
if ! (uname -r |egrep "el6|el7" >/dev/null); then
    echo "current system not support!"
    exit 9
fi

#judge run user
if [ $UID -ne 0 ]; then
    echo "please execute script by root!"
    exit 9
fi

if ! (getent passwd weblogic >/dev/null); then
    echo "please add weblogic user!"
    exit 9
fi

#nfs-server install
yum -q install -y nfs-utils rpcbind

#create share_dir && configure
if [ ! -e ${share_dir} ]; then
    mkdir -p $share_dir  && echo "create share_root success!"
    chown -R weblogic: $share_dir
    chmod a+w $share_dir
fi

tee <<EOF >/etc/exports
${share_dir} ${ip_limit}(rw,sync,no_root_squash)
EOF

#start nfserver
if (uname -r |grep -q el7); then
    systemctl enable rpcbind --now && systemctl enable nfs --now
else
    service rpcbind restart
    service nfs restart
    chkconfig rpcbind on && chkconfig nfs on 
fi 

#testing
exportfs -rv  && showmount -e localhost

#使用说明

使用环境:
centos6/7及基于此的发型系列
yum在线

使用限制:
weblogic作为挂在使用用户,cliet/server uid/gid 一致
执行账户root初始化nfs_server

脚本解读:
./install_nfs_server.sh  //default
./install_nfs_server.sh  nfs_root  ip_limit

参数说明
nfs_root:
nfs共享目录,权限weblogic,默认/xx/nfs_root
ip_limit:
nfs-client ip访问控制,默认*不做控制  10.10.10.*   172.*

nfs-client使用需要安装nfs-utils
yum install -y nfs-utils

mount -t nfs 172.24.20.20:/opt/nfs_root /mnt   //remote mount
touch /mnt/sb && rm -rf /mnt/* 
umount /mnt

注意:centos6/7默认添加weblogic的uid/gid不同会导致权限映射不出用户名weblogic uid/gid 要一致才可以显示为用户名

reference