centos6/7安装nfs-server脚本
#!/bin/sh
set -e
#define vars
share_dir=${1:-/servyou/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
使用说明
2021年9月13日 18:45:04
使用环境:
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,默认/servyou/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 要一致才可以显示为用户名