Sponsored Content
Top Forums Shell Programming and Scripting Bash script to add multiple resources to NFS pacemaker cluster Post 303037210 by hburnswell on Thursday 25th of July 2019 08:07:04 PM
Old 07-25-2019
Bash script to add multiple resources to NFS pacemaker cluster

All,

I'm looking for some guidance on how to accomplish automating the addition of exports to an HA Pacemaker NFS cluster. I would like to do it in bash for logistics reasons.

The resource creation command looks like this:

Code:
pcs resource create nfs-b2b-hg-media-10.1 exportfs clientspec=10.1.0.0/255.255.0.0 options=rw,sync,no_root_squash directory=/nfs/exports/media fsid=1 --group nfsgroup

However, I would like the script to be able to add multiple exports at one time and am trying to figure out the best way to do it. I have been playing around with arrays and can gather 2 of the necessary variables in the command, but there are 4 needed variables:

Code:
resource_name --> nfs-b2b-hg-media-10.1
clientspec --> 10.1.0.0/255.255.0.0
directory --> /nfs/exports/media
fsid --> 1

The rest of the command is pretty static.

Here is a small test script that gathers resource name and clientspec (and puts in order):

Code:
#!/usr/bin/bash

cs10168="10.16.8.0/255.255.255.0"
cs101="10.1.0.0/255.255.0.0"
cs1091="10.91.0.0/255.255.0.0"
dirs=(media hotdrive images)
nfsenv="nfs-b2b-hg"
nfsoptions="rw,sync,no_root_squash"
lv=exports
mt="/nfs"
nfsgrp=nfsgroup

declare -A exports
exports[${nfsenv}-${dirs[0]}-10.1]=${cs101}
exports[${nfsenv}-${dirs[1]}-10.91]=${cs1091}
exports[${nfsenv}-${dirs[2]}-10.1]=${cs101}
exports[${nfsenv}-${dirs[2]}-10.91]=${cs1091}

declare -a orders
orders+=( ${nfsenv}-${dirs[0]}-10.1 )
orders+=( ${nfsenv}-${dirs[1]}-10.91 )
orders+=( ${nfsenv}-${dirs[2]}-10.1 )
orders+=( ${nfsenv}-${dirs[2]}-10.91 )

for i in ${orders[@]}

do

       pcs resource create $i exportfs clientspec=${exports[$i]} options=$nfsoptions directory=${mt}/${lv}/${dirs[0]} fsid=1 --group $nfsgrp

done

As you can see there is a problem with how to define 'directory' and 'fsid'.

Does anyone have any suggestions on how to accomplish this in bash? Any guidance is greatly appreciated.

Thanks,

HB

Last edited by hicksd8; 07-26-2019 at 07:00 AM..
 

8 More Discussions You Might Find Interesting

1. High Performance Computing

cluster setup and nfs

hello, During the cluster installation, we are required to enter a cluster name. When this name is used? I have a shared disk between those 2 nodes. To test NFS failover, what should I do? PS: I am using VCS 5 thanks (5 Replies)
Discussion started by: melanie_pfefer
5 Replies

2. Shell Programming and Scripting

bash script to rename multiple directories

Hello I have a directory structure with year in format 4 digits, e.g 2009, below which is month format 1 or 2 digits, e.g 1 or 12, blow which is day format 1 or 2 digits, e.g 1 or 31. I want to change the names of lots of directories to the be Year - 4 digits , e.g 2009 - No change here... (4 Replies)
Discussion started by: garethsays
4 Replies

3. Shell Programming and Scripting

Multiple Variables for BASH script

Hello, I am new to the whole "scripting" thing. Below is the script that I have so far and where i need the Variables to go (VAR#) #!/bin/bash #Sample Script VAR1= echo "Choose an option: 1) Create a file. 2) Delete a file. 3) Move a file." read VAR1 case $VAR1 in 1) echo "Pick... (4 Replies)
Discussion started by: eclerget
4 Replies

4. Shell Programming and Scripting

Bash script to copy timestamps of multiple files

Hi, I have a bunch of media files in a directory that have been converted (from MTS to MOV format), so my directory contains something like this: clip1.mts clip1.mov clip2.mts clip2.mov The problem is that the .mov files that have been created have the timestamps of the conversion task,... (2 Replies)
Discussion started by: Krakus
2 Replies

5. Homework & Coursework Questions

NFS service not started in Redhat Cluster

Hi All, Need your help to resolve below error in cluter. Sep 9 05:37:30 node2 rgmanager: Starting disabled service service:Prod_Service Sep 9 05:37:30 node2 rgmanager: HA LVM: Improper setup detected Sep 9 05:37:30 node2 rgmanager: * initrd image needs to be newer than lvm.conf... (3 Replies)
Discussion started by: nitinredekar
3 Replies

6. Shell Programming and Scripting

Mount NFS Share On NFS Client via bash script.

I need a help of good people with effective bash script to mount nfs shared, By the way I did the searches, since i haven't found that someone wrote a script like this in the past, I'm sure it will serve more people. The scenario as follow: An NFS Client with Daily CRON , running bash script... (4 Replies)
Discussion started by: Brian.t
4 Replies

7. Shell Programming and Scripting

Loop through multiple files in bash script

Hi Everybody, I'm a newbie to shell scripting, and I'd appreciate some help. I have a bunch of .txt files that have some unwanted content. I want to remove lines 1-3 and 1028-1098. #!/bin/bash for '*.txt' in <path to folder> do sed '1,3 d' "$f"; sed '1028,1098 d' "$f"; done I... (2 Replies)
Discussion started by: BabyNuke
2 Replies

8. Red Hat

PaceMaker Cluster Fence Device

I have 2 VM's setup with a shared VMware disk running RHEL 7.1 (just updated to 7.2 with yum update), and would like to know what is the easiest Fence device to implement for testing purposes. Apparently, I need a fence device before my IP resources will come online. I have the cluster... (1 Reply)
Discussion started by: mrmurdock
1 Replies
exportfs(8)						      System Manager's Manual						       exportfs(8)

NAME
exportfs - maintain list of NFS exported file systems SYNOPSIS
/usr/sbin/exportfs [-avi] [-o options,..] [client:/path ..] /usr/sbin/exportfs -r [-v] /usr/sbin/exportfs [-av] -u [client:/path ..] /usr/sbin/exportfs [-v] DESCRIPTION
The exportfs command is used to maintain the current table of exported file systems for NFS. This list is kept in a separate file named /var/lib/nfs/xtab which is read by mountd when a remote host requests access to mount a file tree, and parts of the list which are active are kept in the kernel's export table. Normally this xtab file is initialized with the list of all file systems named in /etc/exports by invoking exportfs -a. However, administrators can choose to add and delete individual file systems without modifying /etc/exports using exportfs. Any export requests which identify a specific host (rather than a subnet or netgroup etc) are entered directly into the kernel's export ta- ble as well as being written to /var/lib/nfs/xtab. Further, any mount points listed in /var/lib/nfs/rmtab which match a non host-specific export request will cause an appropriate export entry for the host given in rmtab to be entered into the kernel's export table. OPTIONS
-a Export or unexport all directories. -o options,... Specify a list of export options in the same manner as in exports(5). -i Ignore the /etc/exports file, so that only default options and options given on the command line are used. -r Reexport all directories. It synchronizes /var/lib/nfs/xtab with /etc/exports. It removes entries in /var/lib/nfs/xtab which are deleted from /etc/exports, and remove any entries from the kernel export table which are no longer valid. -u Unexport one or more directories. -v Be verbose. When exporting or unexporting, show what's going on. When displaying the current export list, also display the list of export options. DISCUSSION
Exporting Directories The first synopsis shows how to invoke the command when adding new entries to the export table. When using exportfs -a, all directories in exports(5) are added to xtab and the resulting list is pushed into the kernel. The host:/path argument specifies the directory to export along with the host or hosts to export it to. All formats described in exports(5) are supported; to export a directory to the world, simply specify :/path. The export options for a particular host/directory pair derive from several sources. There is a set of default options which can be over- ridden by entries in /etc/exports (unless the -i option is given). In addition, the administrator may overide any options from these sources using the -o argument which takes a comma-separated list of options in the same fashion as one would specify them in exports(5). Thus, exportfs can also be used to modify the export options of an already exported directory. Modifications of the kernel export table used by nfsd(8) take place immediately after parsing the command line and updating the xtab file. The default export options are sync,ro,root_squash,no_delay. Unexporting Directories The third synopsis shows how to unexported a currently exported directory. When using exportfs -ua, all entries listed in xtab are removed from the kernel export tables, and the file is cleared. This effectively shuts down all NFS activity. To remove individial export entries, one can specify a host:/path pair. This deletes the specified entry from xtab and removes the corre- sponding kernel entry (if any). Dumping the Export Table Invoking exportfs without further options shows the current list of exported file systems. When giving the -v option, the list of flags pertaining to each export are shown in addition. EXAMPLES
The following adds all directories listed in /etc/exports to /var/lib/nfs/xtab and pushes the resulting export entries into the kernel: # exportfs -a To export the /usr/tmp directory to host djando, allowing asynchronous writes, one would do this: # exportfs -o async django:/usr/tmp DEPENDENCIES
Exporting to IP networks, DNS and NIS domains does not enable clients from these groups to access NFS immediately; rather, these sorts of exports are hints to mountd(8) to grant any mount requests from these clients. This is usually not a big problem, because any existing mounts are preserved in rmtab across reboots. When unexporting a network or domain entry, any current exports to members of this group will be checked against the remaining valid exports and if they themselves are nolonger valid they will be removed. SEE ALSO
exports(5), mountd(8) AUTHORS
Olaf Kirch, <okir@monad.swb.de> Neil Brown, <neilb@cse.unsw.edu.au> 7 Sep 1999 exportfs(8)
All times are GMT -4. The time now is 06:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy