Example of shell script automatically building NFS service

Time:2020-8-13

This paper introduces an example of how shell scripts can build NFS services automatically. The details are as follows:

#vim /sh/zidong_dajian_nfs_fuwu.sh

#!/bin/bash

#name:zidong_dajian_nfs_fuwu.sh
#path:/sh/
#update:2017-9-17
#Test whether the network is smooth
Ping - C 1 172.16.13.254 > / dev / null**********
#Step 1: shut down SELinux and firewall
Setenforce 0 > / dev / null & echo**********
Systemctl stop firewall > / dev / null & echo**********

#Step 2: confirm whether the software is installed
rpm -aq rpcbind >/dev/null
if [ $? -eq 0 ];then
  Echo "rpcbind software installed"
else 
  Yum install rpcbind - Y > / dev / null & echo "installing software"
fi
Echo software installed**********

#Step 3: create and publish the shared directory
Please enter the directory you want to share: "dir
mkdir $dir -p >/dev/null
chmod 1777 $dir
Read - P "please enter the network segment to be shared" WD
Please enter the permission mode to share, enter ro or RW: "QX
cat >> /etc/exports << end
$dir $wd($qx)
end

#Step 4: start the service and start it automatically
systemctl restart rpcbind.service
systemctl restart nfs.service
Echo "NFS sharing service has been set up, welcome to use it next time"

Test: after the NFS server executes the script, first check whether the shared directory is successfully generated, and then touch a file in it for testing

The test side uses the showmount command to view the shared directory of the server, and then mounts it to a local directory of its own, and then goes in to see if there are corresponding files and check its contents

This article about shell script automatic build NFS service example article introduced here, more related shell automatic build NFS content, please search the previous articles of developeppaer or continue to browse the related articles below, I hope you can support developeppaer more in the future!

Recommended Today

How to share queues with hypertools 2.5

Share queue with swote To realize asynchronous IO between processes, the general idea is to use redis queue. Based on the development of swote, the queue can also be realized through high-performance shared memory table. Copy the code from the HTTP tutorial on swoole’s official website, and configure four worker processes to simulate multiple producers […]