一键安装NFS文件存储服务器脚本,服务端安装

#/bin/bash
#editor by yhzong
#date 2020-07-27
#操作版本系统号检测
OS=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`

#创建共享目录
share_dir=/home/share
mkdir -p ${share_dir}

#检测服务器是否可以上网,如果不能上网就退出
check_net=`curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com`
if [ ${check_net} -ne 200 ];then
	echo "请检查网络是否正常,能否访问外网"
	exit 1
fi

#安装替换yum源的wget软件
yum install wget -y > /dev/null 2>&1

#替换镜像源为阿里镜像源
echo "更换为阿里云yum源"
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
if [ $OS == '7' ];then
	wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo > /dev/null 2>&1
	wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo >/dev/null 2>&1
	sed -i '/aliyuncs.com/d' /etc/yum.repos.d/*.repo
elif [ $OS == '6' ];then
	wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
	sed -i '/aliyuncs.com/d' /etc/yum.repos.d/*.repo
else 
	exit 0
fi

#进行nfs的安装配置
yum -y install nfs-utils rpcbind

#赋予权限给共享目录,一般给777的权限
chmod -R 777 ${share_dir}

echo "nfs服端安装已经完成,请配置/etc/exports 中加入相应的客户端"
#启动nfs服务
if [ $OS == '7' ];then
	systemctl start rpcbind
        systemctl start nfs
elif [ $OS == '6' ];then
        systemctl start rpcbind
	service nfs  start
else
	exit 0
fi
#检测nfs是否安装成功
nfs_status=`ps -ef |grep nfs`
if [ -z "${nfs_status}" ];then
	echo "请检查相应的服务和配置文件,installed failure!!!"
else
	echo "congratulation you are successful installed nfs"
fi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值