Sunday, February 11, 2018

Configure NFS Client


This example is based on the environment below.

+----------------------+          |          +----------------------+
| [    NFS Server    ] |10.0.0.30 | 10.0.0.31| [    NFS Client    ] |
| localhost.manish.world     +----------+----------+ www.manish.world    |
|                      |                     |                      |
+----------------------+                     +----------------------+



Configure NFS Client.


[root@www ~]# 
yum -y install nfs-utils
[root@www ~]# 
vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name

Domain = 
srv.world
[root@www ~]# 
systemctl start rpcbind 

[root@www ~]# 
systemctl enable rpcbind 

[root@www ~]# 
mount -t nfs dlp.srv.world:/home /home 

[root@www ~]# 
df -hT 

Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        46G  1.4G   45G   4% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  8.3M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1               xfs       497M  219M  278M  45% /boot
dlp.srv.world:/home  nfs4       46G  1.4G   45G   4% /home
# /home from NFS server is mounted



Configure NFS mounting on fstab to 
mount it when the system boots.




[root@www ~]# 
vi /etc/fstab
/dev/mapper/centos-root /                       xfs     defaults        1 1
UUID=a18716b4-cd67-4aec-af91-51be7bce2a0b /boot xfs     defaults        1 2
/dev/mapper/centos-swap swap                    swap    defaults        0 0
# add like follows to the end

dlp.srv.world:/home  /home                   nfs     defaults        0 0



Configure auto-mounting. 
For example, set NFS directory on /mntdir. 


[root@www ~]# 
yum -y install autofs
[root@www ~]# 
vi /etc/auto.master
# add follows to the end

/-    /etc/auto.mount

[root@www ~]# 
vi /etc/auto.mount
# create new : [mount point] [option] [location]

/mntdir -fstype=nfs,rw  dlp.srv.world:/home

[root@www ~]# 
mkdir /mntdir 

[root@www ~]# 
systemctl start autofs 

[root@www ~]# 
systemctl enable autofs 

# move to the mount point to make sure it normally mounted

[root@www ~]# 
cd /mntdir 

[root@www mntdir]# 
ll 

total 0
drwx------ 2 cent cent 59 Jul  9  2014 cent
[root@www mntdir]# 
cat /proc/mounts | grep mntdir 

/etc/auto.mount /mntdir autofs rw,relatime,fd=18,pgrp=2093,timeout=300,minproto=5,maxproto=5,direct 0 0
dlp.srv.world:/home /mntdir nfs4 rw,relatime,vers=4.0,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,
port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.31,local_lock=none,addr=10.0.0.30 0 0


Configure NFS Server

Configure NFS Server to share directories on your Network.

This example is based on the environment below.


NFS (Network File System) is basically developed for sharing of files and folders 
between Linux/Unix systems by Sun Microsystems in 1980
It allows you to mount your local file systems over a network and remote hosts 
to interact with them as they are mounted locally on the same system. 
With the help of NFS, we can set up file sharing between Unix to Linux 
system and Linux to Unix system.



+----------------------+          |          +----------------------+
| [    NFS Server    ] |10.0.0.30 | 10.0.0.31| [    NFS Client    ] |
| localhost.manish.world +----------+----------+ www.manish.world    |
|                      |                     |                      |
+----------------------+                     +----------------------+


[1]

Configure NFS Server.



[root@localhost ~]# 
yum -y install nfs-utils
[root@localhost ~]# 
vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name

Domain = 
manish.world
[root@localhost ~]# 
vi /etc/exports
# write settings for NFS exports

/home 10.0.0.0/24(rw,no_root_squash)
[root@localhost ~]# 
systemctl start rpcbind nfs-server 

[root@localhost ~]# 
systemctl enable rpcbind nfs-server 



[2] If Firewalld is running, allow NFS 
service.


[root@localhost ~]# 
firewall-cmd --add-service=nfs --permanent 

success
[root@localhost ~]# 
firewall-cmd --reload 

success



For basic options of exports:

Option
Description
rw
Allow both read and write requests on a NFS volume.
ro
Allow only read requests on a NFS volume.
sync
Reply to requests only after the changes have been committed to stable storage. (Default)
async
This option allows the NFS server to violate the NFS protocol and reply to requests before any changes made by that request have been committed to stable storage.
secure
This option requires that requests originate on an Internet port less than IPPORT_RESERVED (1024). (Default)
insecure
This option accepts all ports.
wdelay
Delay committing a write request to disc slightly if it suspects that another related write request may be in progress or may arrive soon. (Default)
no_wdelay
This option has no effect if async is also set. The NFS server will normally delay committing a write request to disc slightly if it suspects that another related write request may be in progress or may arrive soon. This allows multiple write requests to be committed to disc with the one operation which can improve performance. If an NFS server received mainly small unrelated requests, this behaviour could actually reduce performance, so no_wdelay is available to turn it off.
subtree_check
This option enables subtree checking. (Default)
no_subtree_check
This option disables subtree checking, which has mild security implications, but can improve reliability in some circumstances.
root_squash
Map requests from uid/gid 0 to the anonymous uid/gid. Note that this does not apply to any other uids or gids that might be equally sensitive, such as user bin or group staff.
no_root_squash
Turn off root squashing. This option is mainly useful for disk-less clients.
all_squash
Map all uids and gids to the anonymous user. Useful for NFS exported public FTP directories, news spool directories, etc.
no_all_squash
Turn off all squashing. (Default)
anonuid=UID
These options explicitly set the uid and gid of the anonymous account. This option is primarily useful for PC/NFS clients, where you might want all requests appear to be from one user. As an example, consider the export entry for /home/joe in the example section below, which maps all requests to uid 150.
anongid=GID
Read above (anonuid=UID)


Friday, February 2, 2018

Calculating Mathematical Expressions in Shell Scripting Language – Part V


You People would be feeling comfortable, understanding Shell Scripts and writing them fluently, as per your need. This is the last post of this tutorial series, where we will be carrying out a bit complex Mathematical Operations using scripting language. The last four articles of Shell Scripting series which are chronologically.

Lets start with Fibonacci Series

A pattern of numbers where each number is the sum of two preceding numbers. The series is 0, 112358…… By definition, the first two numbers in the Fibonccai sequence are 0 and 1.

Script 1: Fibonacci.sh
#!/bin/bash
echo "How many numbers do you want of Fibonacci series ?" 
read total 
x=0 
y=1 
i=2 
echo "Fibonacci Series up to $total terms :: " 
echo "$x" 
echo "$y" 
while [ $i -lt $total ] 
do 
i=`expr $i + 1 ` 
z=`expr $x + $y ` 
echo "$z" 
x=$y 
y=$z 
done

Sample Output
[root@localhost ~]# chmod 755 Fibonacci.sh
[root@localhost ~]# ./Fibonacci.sh
How many numbers do you want of Fibonacci series ? 
10 
Fibonacci Series up to 10 terms :: 
0 
1 
1 
2 
3 
5 
8 
13 
21 
34

You are Familiar with the fact that computer understand only in the Binary Format, i.e., ‘0‘ and ‘1‘ and most of us have enjoyed learning the conversion of Decimal to Binary. How about writing a simple script for this complex operation.

Script 2: Decimal2Binary.sh
#!/bin/bash 
for ((i=32;i>=0;i--)); do 
r=$(( 2**$i)) 
Probablity+=( $r  ) 
done 
[[ $# -eq 0 ]] &echo -en "Decimal\t\tBinary\n" 
for input_int in $@; do 
s=0 
test ${#input_int} -gt 11 &printf "%-10s\t" "$input_int" 
for n in ${Probablity[@]}; do 
if [[ $input_int -lt ${n} ]]; then 
[[ $s = 1 ]] && printf "%d" 0 
else 
printf "%d" 1 ; s=1 
input_int=$(( $input_int - ${n} )) 
fi 
done 
echo -e 
done

Sample Output
[root@localhost ~]# chmod 755 Decimal2Binary.sh
[root@localhost ~]# ./Decimal2Binary.sh 1121
Decimal        Binary 
1121           10001100001

Note: The above script accept Input at run time, which obviously is an aid.

Well the inbuilt ‘bc‘ command can convert a decimal to binary in a script of single line. Run, at your terminal.

[root@localhost ~]# echo "obase=2; NUM" | bc

Replace ‘NUM‘ with the number, which you want to convert from Decimal to Binary. For example,

[root@localhost ~]# echo "obase=2; 121" | bc 
1111001

Next we will be writing a script which function just opposite of the above script, Converting Binary Values to Decimal.

Script 3: Binary2Decimal.sh
#!/bin/bash 
echo "Enter a number :" 
read Binary 
if [ $Binary -eq 0 ] 
then 
echo "Enter a valid number " 
else 
while [ $Binary -ne 0 ] 
do 
Bnumber=$Binary 
Decimal=0 
power=1 
while [ $Binary -ne 0 ] 
do 
rem=$(expr $Binary % 10 ) 
Decimal=$((Decimal+(rem*power))) 
power=$((power*2)) 
Binary=$(expr $Binary / 10) 
done 
echo  " $Decimal" 
done 
fi

Sample Output
[root@localhost ~]# chmod 755 Binary2Decimal.sh
[root@localhost ~]# ./Binary2Decimal.sh
Enter a number : 
11 
3

Note: The above function can be performed in terminal using ‘bc‘ command as.

[root@localhost ~]# echo "ibase=2; BINARY" | bc

Replace ‘BINARY‘ with the Binary number, viz.,

[root@localhost ~]# echo "ibase=2; 11010101" | bc 
213

Similarly you can write conversion from octalhexadecimal to decimal and vice-versa yourself. Accomplishing the above result in terminal using ‘bc‘ command is.

Decimal to Octal
[root@localhost ~]# echo "obase=8; Decimal" | bc

Decimal to Hexadecimal
[root@localhost ~]# echo "obase=16; Decimal" | bc

Octal to Decimal
[root@localhost ~]# echo "ibase=8; Octal" | bc

Hexadecimal to Decimal
[root@localhost ~]# echo "ibase=16; Hexadecimal" | bc

Binary to Octal
[root@localhost ~]# echo "ibase=2;obase=8 Binary" | bc

Some of the Common Numeric tests used in shell scripting language with description is.

Test : INTEGER1 -eq INTEGER2
Meaning: INTEGER1 is equal to INTEGER2
Test : INTEGER1 -ge INTEGER2
Meaning: INTEGER1 is greater than or equal to INTEGER2
Test: INTEGER1 -gt INTEGER2
Meaning: INTEGER1 is greater than INTEGER2
Test:INTEGER1 -le INTEGER2
Meaning: INTEGER1 is less than or equal to INTEGER2
Test: INTEGER1 -lt INTEGER2
Meaning: INTEGER1 is less than INTEGER2
Test: INTEGER1 -ne INTEGER2
Meaning: INTEGER1 is not equal to INTEGER2

That’s all for this article, and the article series. This is the last article of Shell Script Series and it does not means that no article on Scripting language will be here again, it only means the shell scripting tutorial is over and whenever we find an interesting topic worth knowing or a query from you people, we will be happy to continue the series from here.


Configure NFS Client

This example is based on the environment below. +----------------------+           |           +----------------------+ | [...