一、写脚本的动机

由于最近老是搭建NFS,虽然不复杂,但是很繁琐。安装服务、修改配置文件、手动挂载、写入开机自动挂载等于是就写了一个脚本

二、脚本说明及审明

作用:该脚本主要实现NFS自动安装,客户端的自动挂载、写入开机自动挂载
使用环境:centos6、nfs客户端的个数为2个
参数:nfs服务端ip、第1个客户端IP、第2个客户端IP、第1个客户端密码、第2个客户端密码、NFS目录
申明:该脚本在本人的服务器上跑是正常的,如果你要用于自己的环境需先测试,该脚本完全处于作者自己爱好,使用脚本请三思。脚本中的参数请根据实际的情况填写,脚本内容如下:

#!/bin/bash

#######################################################################################################################################
## ##
##Function: this script mainly realizes NFS automatic installation and automatic mounting of client. ##
##Usage environment: the number of centos6 and NFS clients is . ##
##Parameters: NFS server side IP, first client IP, second client IP, first client password, second client password, NFS directory ##
##Author: heruiguo ##
####################################################################################################################################### #Check whether the IP address is legitimate
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/rc.d/init.d/functions
function check_ip()
{
IP=$
VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $IP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >/dev/null; then
if [ $VALID_CHECK == "yes" ]; then
echo "IP $IP Correct!"
return
else
echo "IP $IP no Correct!"
return
fi
else
echo "IP error!"
return
fi
} #mkdir nfs dir
mkdir_nfs_dir()
{
mkdir -p $nfs_dir
} #start nfs server
nfs_start()
{
service rpcbind restart
service nfs restart
} #Determine whether the server and client are installing NFS services. If there is no installation service, install and start it first.
pd_nfs_install()
{
rpm -aq |grep nfs-utils >/dev/null
if [ $? -eq ];then
echo "NFS service has been installed"
else
echo "############################The NFS service is being installed############################"
yum install nfs-utils -y >/dev/null
echo "############################The NFS service is being started############################"
nfs_start
fi
} #NFS directory permissions definition
qx="(rw,no_root_squash)" #Verify that NFS server side IP is legitimate
while true; do
read -p "Please enter the IP address of the NFS server: " NFS_SERVER_IP
check_ip $NFS_SERVER_IP
[ $? -eq ] && break
done #Verify whether the NFS client IP is legitimate
while true; do
read -p "Please enter the IP of the first NFS client: " nfs_client1
check_ip $nfs_client1
[ $? -eq ] && break
done #Verify whether the NFS client IP is legitimate
while true; do
read -p "Please enter the IP of second NFS clients: " nfs_client2
check_ip $nfs_client2
[ $? -eq ] && break
done read -p "Please enter the password for the first NFS client: " nfs_passwd_1
read -p "Please enter the second NFS client's password: " nfs_passwd_2
read -p "Please enter the NFS directory: " nfs_dir echo "###########################Server execution###################################"
#、Close the firewall
service iptables stop
#、Create the NFS directory
mkdir_nfs_dir #、Increase the access rights of the client
cat >/etc/exports<<EOF
$nfs_dir $nfs_client1$qx
$nfs_dir $nfs_client2$qx
EOF
#、Start the NFS service
nfs_start echo "###########################NFS customer 1 terminal execution###################################"
sshpass -p $nfs_passwd_1 ssh root@$nfs_client1 -o StrictHostKeyChecking=no <<EOF
server iptabes stop
yum install nfs-utils -y
service rpcbind start
service nfs start
mkdir -p $nfs_dir
umount $nfs_dir
mount -t nfs $NFS_SERVER_IP:$nfs_dir $nfs_dir
sed -i '/nfs/d' /etc/fstab
echo "$NFS_SERVER_IP:$nfs_dir $nfs_dir nfs defaults 0 0 " >>/etc/fstab
EOF echo "###########################NFS customer 2 terminal execution###################################"
sshpass -p $nfs_passwd_2 ssh root@$nfs_client2 -o StrictHostKeyChecking=no <<EOF
server iptabes stop
yum install nfs-utils -y
service rpcbind start
service nfs start
mkdir -p $nfs_dir
umount $nfs_dir
mount -t nfs $NFS_SERVER_IP:$nfs_dir $nfs_dir
sed -i '/nfs/d' /etc/fstab
echo "$NFS_SERVER_IP:$nfs_dir $nfs_dir nfs defaults 0 0 " >>/etc/fstab
EOF

NFS服务自动搭建及挂载脚本的更多相关文章

  1. ubuntu 16.04 nfs服务的搭建

    nfs服务是实现Linux和Linux之间的文件共享,nfs服务的搭建比较简单. 现在介绍如何在ubuntu16.04系统中搭建nfs服务,ubuntu的搭建比红帽的还要简单. 1.安装nfs服务 s ...

  2. Red Hat 6.5 nfs服务的搭建

    nfs服务是实现Linux和Linux之间的文件共享,nfs服务的搭建比较简单. 现在介绍如何在红帽6.5系统中搭建nfs服务. 1.关闭selinux服务 如果已经关闭该服务的可以直接跳过该步骤. ...

  3. NFS服务的搭建

    NFS服务的作用:提供网络文件系统给客户机 nfs服务器的安装配置和使用: 1.将已经制作好的文件系统rootfs_fs210_audio.tgz 拷贝到 /opt,并解压(这里的/opt目录是通过s ...

  4. NFS服务搭建与配置

    启动NFS SERVER之前,首先要启动RPC服务(CentOS5.8下为portmap服务,CentOS6.6下为rpcbind服务,下同),否则NFS SERVER就无法向RPC服务注册了.另外, ...

  5. Linux搭建NFS服务

    一.NFS服务简单介绍 NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中, ...

  6. nfs服务的讲解

    第4章 nfs存储服务的搭建 4.1 nfs服务的介绍 4.1.1 nfs的作用 nfs服务器是一种远程网络传输的共享文件系统 节省web服务器的本地存储空间 用户存储在web服务器上面的资源,会通过 ...

  7. linux服务之NFS服务篇

    一.概念 NFS(Network File Server) 网络文件系统(映射).网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS: NFS允许一个系统在网络上与他人共享目录和文件. ...

  8. 第四章 NFS服务相关介绍

    一.NFS服务介绍 1.什么是NFS?是一个共享存储,文件服务器 2.NFS基本概述NFS是Network File System的缩写及网络文件系统.NFS主要功能是通过局域网络让不同的主机系统之间 ...

  9. ubuntu14.04 部署nfs服务

    安装nfs服务 apt-get install nfs-kernel-server 修改配置文件,共享目录为/var/www,*号可替换为客户端IP地址,*默认为任何部署了nfs客户端的IP可以挂载该 ...

随机推荐

  1. 让富文本编辑器支持复制doc中多张图片直接粘贴上传

    Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧? 我希望打开文档doc直接复制粘贴到富文本编辑器,直接发布 感觉这个似乎很困难 ...

  2. .Net进阶系列(11)-异步多线程(委托BeginInvoke)(被替换)

    一. BeginInvoke最后两个参数的含义 倒数第二个参数:指该线程执行完毕后的回调函数:倒数第一个参数:可以向回调函数中传递参数. 下面以一段代码说明: /// <summary> ...

  3. 用ajax传递json,返回前台的中文乱码问题

    java项目中用ajax传递json,返回前台时中文出现问号(乱码问题)的解决办法 首先看一下没有解决前的状态: 我用的框架是ssm,在springMVC中我配置了编码格式为utf-8,每个jsp页面 ...

  4. ECharts(中国地图)的使用 及 非空 tooltip formatter 验证

    中国地图使用频率很高下载文件:        echarts.min.js网址:               http://echarts.baidu.com/download.html点击:     ...

  5. C - 数字配对 (网络流 最大费用最大流)

    题目链接:https://cn.vjudge.net/contest/281959#problem/C 题目大意:中文题目 具体思路:用网络流的思想,我们求得是最大的匹配数,那么我们按照二分图的形式去 ...

  6. python - 计算器 程序练习

    v1.0 计算器(数据内不含括号方式:) import re def jisuan(a,b,c): sun_count = 0 if c =="+": sun_count = st ...

  7. 简单透彻理解JSONP原理及使用

    首先提一下JSON这个概念,JSON是一种轻量级的数据传输格式,被广泛应用于当前Web应用中.JSON格式数据的编码和解析基本在所有主流语言中都被实现,所以现在大部分前后端分离的架构都以JSON格式进 ...

  8. 反汇编调试内核驱动 Oops提示【转】

    以下部分内容转自:https://blog.csdn.net/jiatingqiang/article/details/7481497 反汇编调试内核驱动 arm-none-linux-gnueabi ...

  9. Bootstrap3.0学习第一轮(入门)

    详情请查看 http://aehyok.com/Blog/Detail/7.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...

  10. 安装cactiez v11对windows和linux系统进行监控

    日常运维中我们需要对服务器的流量.CPU占用.硬盘使用及内存.磁盘IP等进行监控和了解,cactiez是一款基于centos6.4定制安装了常用监控软件的系统,安装简单,功能强大很适合快速部署监控系统 ...