NFS服务自动搭建及挂载脚本
一、写脚本的动机
由于最近老是搭建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服务自动搭建及挂载脚本的更多相关文章
- ubuntu 16.04 nfs服务的搭建
nfs服务是实现Linux和Linux之间的文件共享,nfs服务的搭建比较简单. 现在介绍如何在ubuntu16.04系统中搭建nfs服务,ubuntu的搭建比红帽的还要简单. 1.安装nfs服务 s ...
- Red Hat 6.5 nfs服务的搭建
nfs服务是实现Linux和Linux之间的文件共享,nfs服务的搭建比较简单. 现在介绍如何在红帽6.5系统中搭建nfs服务. 1.关闭selinux服务 如果已经关闭该服务的可以直接跳过该步骤. ...
- NFS服务的搭建
NFS服务的作用:提供网络文件系统给客户机 nfs服务器的安装配置和使用: 1.将已经制作好的文件系统rootfs_fs210_audio.tgz 拷贝到 /opt,并解压(这里的/opt目录是通过s ...
- NFS服务搭建与配置
启动NFS SERVER之前,首先要启动RPC服务(CentOS5.8下为portmap服务,CentOS6.6下为rpcbind服务,下同),否则NFS SERVER就无法向RPC服务注册了.另外, ...
- Linux搭建NFS服务
一.NFS服务简单介绍 NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中, ...
- nfs服务的讲解
第4章 nfs存储服务的搭建 4.1 nfs服务的介绍 4.1.1 nfs的作用 nfs服务器是一种远程网络传输的共享文件系统 节省web服务器的本地存储空间 用户存储在web服务器上面的资源,会通过 ...
- linux服务之NFS服务篇
一.概念 NFS(Network File Server) 网络文件系统(映射).网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS: NFS允许一个系统在网络上与他人共享目录和文件. ...
- 第四章 NFS服务相关介绍
一.NFS服务介绍 1.什么是NFS?是一个共享存储,文件服务器 2.NFS基本概述NFS是Network File System的缩写及网络文件系统.NFS主要功能是通过局域网络让不同的主机系统之间 ...
- ubuntu14.04 部署nfs服务
安装nfs服务 apt-get install nfs-kernel-server 修改配置文件,共享目录为/var/www,*号可替换为客户端IP地址,*默认为任何部署了nfs客户端的IP可以挂载该 ...
随机推荐
- VS2015(Xamarin)开发安卓WebApp笔记
有关WebApp的开发,大多数人都用了第三方框架,如Cordova等.我这里没有用到这类框架,而是新建了一个WebView嵌入Assets(本地资源)来完成这个App,由于第一个练习App希望对初学者 ...
- 用贪心算法近似求解 Loading Balance 问题(作业调度的负载均衡)
一,Loading Balance 问题描述:有 m 台相同的机器及 n 个作业,其中 m={M(1),M(2),……M(m)}.n = {J(1),J(2),……J(n)}.每个作业都有一个处理时间 ...
- 组合框QGroupBox
样式: 注意:内部必须使用布局控件 import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QPixmap from PyQt5. ...
- cetus系列~安装和基本配置
cetus系列一 安装 1 安装软件环境 yum install cmake gcc glib2-devel flex mysql-devel gperftools-libs bison f ...
- IMU 预积分推导
给 StereoDSO 加 IMU,想直接用 OKVIS 的代码,但是有点看不懂.知乎上郑帆写的文章<四元数矩阵与 so(3) 左右雅可比>提到 OKVIS 的预积分是使用四元数,而预积分 ...
- springboot项目发布到独立的tomcat中运行&打成jar包运行
springboot的打包方式依赖于插件:(下面插件打出的包与普通的包目录结构有区别) <plugin> <groupId>org.springframework.boot&l ...
- CXF2.7整合spring发布webservice,返回值类型是Map和List<Map>类型
在昨天研究了发布CXF发布webservice之后想着将以前的项目发布webservice接口,可是怎么也发布不起来,服务启动失败,原来是自己的接口有返回值类型是Map. 研究了一番之后,发现: we ...
- 深层揭密extern "C"
一. extern "C" 包含双重含义,从字面上即可得到:首先,被它修饰的目标是“extern”的:其次,被它修饰的目标是“C”的.让我们来详细解读这两重含义. (1) 被ext ...
- Cpp读文件、CString转String、String转CString
场景 C++读取文件 技术点 读取文件 fstream提供了三个类,用来实现c++对文件的操作.(文件的创建.读.写). ifstream -- 从已有的文件读入 ofstream -- 向文件写内容 ...
- 【逆向知识】动态调试技巧-C++代码逆向
1.C++类代码的特点 寄存器ECX传参时一般用作this指针(对象地址)或是计数器. 有ecx传参的call,是成员函数,构造函数,析构函数 能访问成员变量的函数都会有ecx传参 静态函数.全局函数 ...