使用Shell脚本搭建NFS

#!/bin/bash

echo '1,checking network... '
ping -c1 192.168.1.51 &> /dev/null
if [ $? -eq 0 ];then
 echo 'network is ok!'
else 
 echo 'network is not ok! '
 exit 1
fi

echo '2.Configure selinux and firewalld... '
setenforce 0 &> /dev/null
echo 'Selinux set disable'
systemctl stop firewalled &> /dev/null
echo 'firewalld stopped'


echo '3.Check rpcbind...'
rpm -q rpcbind &> /dev/null
if [ $? -eq 0 ];then
 echo 'rpcbind has installed!'
else
 yum install -y rpcbind &> /dev/null && echo 'rpcbind install successfully' || echo 'rpcbind install failed!'; exit 1
fi

echo '4.Creat Share Dir and Share...'
read -p "Please input share dir:" dir
if [ -e $dir ];then
 echo "Share Directory $dir exists!"
else
 mkdir -p $dir
 echo "Share Directory $dir creat success!"
fi
chmod 1777 $dir
read -p "Please input share subnet:" sub
read -p "Please input share permission(ro/rw): " permission
echo 'Edit nfs configure file /etc/exports'
read -p "input 1 for clear config , default is add: " choice
if [ $choice -eq 1 ];then
 > /etc/exports
fi
cat >> /etc/exports <<EOF
$dir $sub($permission)
EOF

cho "5.Start and enable service..."
systemctl status nfs-server.service | grep active &>/dev/null
if [ $? -eq 0 ];then
 echo 'nfs-server.servise is active , restarting now ...'
 systemctl restart nfs-server.service
 echo 'nfs-server.service is restart successfully!'
else
 systemctl enable rpcbind --now
 systemctl encble nfs-server.service --now
fi
echo 'NFS buids completed!'

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值