一、写脚本的动机

由于最近老是搭建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. 用Python中的re做信息筛选

    背景 平时工作中,我们经常会处理大量的元数据(Raw Data),而一般的文件编辑器只能一次查询一个关键字,这就难以连续的分析元数据,比如分析产品日志文件(log),日志可能包括很多informati ...

  2. JavaScript之能力与硬件检测[小结]

    //检查浏览器种类及其版本号 function checkBrowserVersion(){ var Sys = {}; var ua = navigator.userAgent.toLowerCas ...

  3. CSS进阶之SASS入门指南

    CSS进阶之SASS入门指南         随着跟着公司学习项目的前端的推进,越来越对好奇了许久的SASS垂涎欲滴,哈哈,可能这个词使用不当,没有关系,就是对SASS有一股神秘的爱!好了,闲话不多说 ...

  4. POJ1236 Network of Schools【强连通】

    题意: N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输,问题1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件 ...

  5. 8、判断三角形ABC中是否有点D

    思路: 首先连接AD,BD,CD,SABC为三角形的面积,SABD为三角形ABD的面积,SACD....,SBCD....... 因此,若D在三角形则SABC = SABD + SACD + SBCD ...

  6. 解决jdk1.7,1.8共存问题小思

    一 起因 随着jdk1.9呼之欲出之势,准备花点时间把jdk1.8搞掉,于是准备下一个项目的依赖改为jdk1.8,先去下载安装,安装好之后电脑上就存在两个版本的jdk.然后将两个版本的jdk路径都配置 ...

  7. C# List分页

    假设你每页10条数据当前是第3页 跳到第4页则:List.Skip((4-1)*10).Take(10) 本文来自SunShine,转载请标明出处: http://do.jhost.cn/sunshi ...

  8. 【Python】批量爬取网站URL测试Struts2-045漏洞

    1.概述都懒得写了.... 就是批量测试用的,什么工具里扣出来的POC,然后根据自己的理解写了个爬网站首页URL的代码... #!/usr/bin/env python # -*- coding: u ...

  9. mysql系列五、mysql中having的用法

    HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 和 SELECT 的交互方式类似.WHERE 搜索条件在进行分组操作之前应用:而HAVING 搜索条件在进行分组操作之后应用. ...

  10. redhat换用centos源

    解除原有源rpm -aq|grep yum|xargs rpm -e --nodepsrpm -aq|grep python-iniparse|xargs rpm -e --nodeps rpm -q ...