一、写脚本的动机

由于最近老是搭建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. SpringMVC学习笔记_01

    1.JAVAEE体系结构 JAVAEE体系结构图如下所示: 2.什么是springmvc? 什么是mvc? Model1 Model2 SpringMVC是什么? SpringMVC是一个web层mv ...

  2. STM32建立基本项目

    1.下载固件库解压 2.Keil建立项目,项目下建立三个文件夹3.各目录下从固件库中拷贝对应的目录 4.修改main.c文件 5.修改C++ 6.修改Include 7,编译.

  3. luogu 1064 金明的预算方案

    01背包 变形,有主附件的背包内则更改决策 original: 1) 不选   2)选,f[j-w[i]]+v[i] now :     1)不选   2)选主   3)主 附1  4)主 附2   ...

  4. SpringBootTest单元测试实战、SpringBoot测试进阶高级篇之MockMvc讲解

    1.@SpringBootTest单元测试实战 简介:讲解SpringBoot的单元测试 1.引入相关依赖 <!--springboot程序测试依赖,如果是自动创建项目默认添加--> &l ...

  5. cell下载图片的思路 --无沙盒(内存)缓冲

    // // ViewController.m // 06-表格图片下载 // // Created by jerry on 15/9/7. // Copyright (c) 2015年 jerry. ...

  6. SpringAOP+注解实现简单的日志管理

    今天在再次深入学习SpringAOP之后想着基于注解的AOP实现日志功能,在面试过程中我们也经常会被问到:假如项目已经上线,如何增加一套日志功能?我们会说使用AOP,AOP也符合开闭原则:对代码的修改 ...

  7. 【vim】缩写 :ab [缩写] [要替换的文字]

    一个很可能是最令人印象深刻的窍门是你可以在 Vim 中定义缩写,它可以实时地把你输入的东西替换为另外的东西.语法格式如下: :ab [缩写] [要替换的文字] 一个通用的例子是: :ab asap a ...

  8. Ajax jsonp 跨域请求实例

    跨域请求 JSONP的缺点则是:它只支持GET请求而不支持POST等其它类型的HTTP请求:它只支持跨域HTTP请求这种情况,不能解决不同域的两个页面之间如何进行JavaScript调用的问题. $. ...

  9. WebsphereMQ搭建集群

    #https://www.ibm.com/developerworks/cn/websphere/library/techarticles/1202_gaoly_mq/1202_gaoly_mq.ht ...

  10. 如何解决OpenStack创建虚拟机或删除虚拟机时一直处于deleting或者creating状态的问题(转载)

    原文地址:http://www.cnblogs.com/robertoji/p/4968280.html 在OpenStack使用时,有时候会遇到创建虚拟机或者删除虚拟机无法成功创建或者删除的时候,一 ...