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可以挂载该 ...
随机推荐
- ASP.NET MVC深入浅出(被替换)
一. 谈情怀-ASP.NET体系 从事.Net开发以来,最先接触的Web开发框架是Asp.Net WebForm,该框架高度封装,为了隐藏Http的无状态模式,ViewState功不可没,通过的控件的 ...
- MySQL - 日常操作一 增删改查
mysql 源码安装 创建 mysql 账户 组 groupadd mysql useradd mysql -g mysql -M -s /bin/false 解压缩源码安装 .tar.gz cd ...
- [C++]C++与C头文件辨析(比较)
C++/C头文件辨析 C++标准库 C标准库 C++标准模板库 ios vector iomanip deque sstream list fstream map set ...
- UE4的AI学习(1)——基本概念
AI学习当中,不学习行为树基本概念就不能明白具体实例中的操作意义,但是没有经过具体实例实验,又觉得基本概念抽象难以理解.建议先泛读(1)(2)后再对具体的细节进行死磕,能较深的理解行为树的具体概念.第 ...
- jQuery中【width(),innerWidth(),outerWidth()】
这个问题,已经别扭我多年了,今天终于彻底解决了,拿出来庆贺一下.jquery作为开源项目,无论从思路上,还是从严谨性上,让人崇敬. 随着时间的流逝,jquery的一些功能被逐渐挖掘出来.通过jQuer ...
- Getting started with machine learning in Python
Getting started with machine learning in Python Machine learning is a field that uses algorithms to ...
- Linux内核调试方法【转】
转自:http://www.cnblogs.com/shineshqw/articles/2359114.html kdb:只能在汇编代码级进行调试: 优点是不需要两台机器进行调试. gdb:在调试模 ...
- Linux命令学习总结:date命令【转】
本文转自:http://www.cnblogs.com/kerrycode/p/3427617.html 命令简介: date 根据给定格式显示日期或设置系统日期时间.print or set the ...
- 蓝牙Bluetooth技术手册规范下载【转】
蓝牙Bluetooth技术手册规范下载 http://www.crifan.com/summary_bluetooth_specification_download/ [背景] 之前就已经整理和转帖了 ...
- ES系列十二、ES的scroll Api及分页实例
1.官方api 1.Scroll概念 Version:6.1 英文原文地址:Scroll 当一个搜索请求返回单页结果时,可以使用 scroll API 检索体积大量(甚至全部)结果,这和在传统数据库中 ...