存储服务:NFS
NFS 安装脚本
使用前需要前置脚本:01.setEnvironment.sh, 02.setYumLocalRepo.sh, 03.instEnv.sh, 并安装时间同步服务。
服务端脚本:
#!/bin/bash
# Maintainer: zhengmingyue
# Email: 348063831@qq.com
# The script is used to deploy nfs services.Run this script before running
# 01.setEnvironment.sh, 02.setYumLocalRepo.sh, 03.instEnv.sh, and deploy service chrony
# Install rpm: this module can merge to 03.instEnv.sh.
VERSION_ID=`cat /etc/os-release | grep "VERSION_ID" | awk -F"=|\"|=\"| " '{ print $2 }'`
echo "Install NFS rpms"
if [ $VERSION_ID == "7" ]
then
yum install -y nfs-utils
elif [ $VERSION_ID == "8" ]
then
dnf install -y nfs-utils
fi
systemctl enable rpcbind --now
systemctl enable nfs-server --now
## Parameter Description
# rw/ro : read-write/read-only permission
# root_squash/no_root_squash : sqush root privileges/not sqush root privileges
# all_squash/no_all_squash : sqush all user privileges/not sqush per user privileges
# subtree_check/ no_subtree_check : Enforce permission check of parent directory(Defaults).
# Do not check the permissions of the parent directory.
# secure/insecure : NFS is sent through a secure TCP/IP port below 1024.
# NFS is sent through more than 1024 ports.
# sync/async : Data is synchronously written to memory and hard disk/
# Data will be temporarily stored in memory rather than written directly to the hard disk
# wdelay : If multiple users want to write to the directory, group write(Defaults).
# no_wdelay : If multiple users want to write to the directory, write it immediately.
# This setting is not required when using async.
# hide/no_hide : Do not share subdirectories./Share subdirectories.
# anonuid : Map the user on the client to the user with the specified local user ID.
# anongid : Map the user on the client machine to belong to the specified local user group ID.
touch /etc/exports
echo "# This file was written by setNfs.sh" > /etc/exports
read -ep "Please enter the number of directories to be configured " countDir
echo -e "\033[31;1mWhen setting multiple directories, do not set the same directory, otherwise an error will occur. \033[0m"
for i in `seq $countDir`
do
read -ep "Please configure the No.$i shared directory: " shDirt
mkdir -pv $shDirt
# if the nfs service is used to ovirt storage domain, please change owner.
# chown -R 36:36 $shDirt
# if other service use nfs service, can change owner and group.
chmod 0755 $shDirt
echo -e "$shDirt *(insecure,rw,sync,no_root_squash,all_squash)" >> /etc/exports
done
exportfs -r
echo -e "\033[32;1mYou can use mount point below: \033[0m"
showmount -e localhost
exports括号中的参数说明:
## Parameter Description
# rw/ro : 读写/只读 权限
# root_squash/no_root_squash : root用户的文件权限改为nobody/不更改root用户的root权限
# all_squash/no_all_squash : 更改所有用户的权限为nobody/不更改任何用户的权限
# subtree_check/no_subtree_check : 强制检查父目录的权限(默认)./不检查父目录的权限.
# secure/insecure : NFS通过1024以下的安全TCP/IP端口发送./NFS通过1024以上的端口发送.
# sync/async : 向内存和硬盘同时写入数据./数据先向内存写入数据,硬盘空闲时在想硬盘写入数据(断电数据丢失风险大)。
# wdelay/no_wdelay : 如果多个用户要写入NFS目录时: 则归组写入(默认)/则立即写入,使用async时,无需此设置
# hide/no_hide : 在NFS共享目录中不共享其子目录./共享NFS目录的子目录.
# anonuid : 将客户机上的用户映射成指定的本地用户ID的用户.
# anongid : 将客户机上的用户映射成属于指定的本地用户组ID.
防火墙打开时:
firewall-cmd --zone=public --permanent --add-service=rpc-bind
firewall-cmd --zone=public --permanent --add-service=mountd
firewall-cmd --zone=public --permanent --add-service=nfs
firewall-cmd --reload