Sunday, April 23, 2017

RHEL7 - NFS server, client and autofs


1. On nfs server, perform the following
[root@bishal certs]# vi /etc/exports
/home *(rw,sync)

[root@bishal certs]# exportfs -r

[root@bishal certs]# exportfs
/opt/OS_Image   <world>
/home           <world>
[root@bishal certs]#

[root@bishal prema]# groupadd -g 1050 dba
[root@bishal prema]# useradd -u 1050 -g 1050 gagan
[root@bishal prema]# passwd gagan
Changing password for user gagan.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.



2. On Client system, perform the following tasks
[root@prema ~]# showmount -e 192.168.10.238
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
[root@prema ~]# showmount -e 192.168.10.238^C

[root@prema ~]# mount 192.168.10.238:/home /mnt

[root@prema ~]# df -h /mnt
Filesystem            Size  Used Avail Use% Mounted on
192.168.10.238:/home   18G   14G  4.6G  75% /mnt
[root@prema ~]#


3. Setting up auto-fs
Now, remove all the content from home directory on client system.

[root@prema home]# mkdir /var/tmp/all
[root@prema home]# ls
ahn  all  bau  bishal  dev  kamal  niv  pradip  prema  ram  sam

[root@prema home]# mv * /var/tmp/all

[root@prema home]# ls -l
total 0
[root@prema home]# pwd
/home


[root@prema home]# vi /etc/auto.master
/home   /etc/home.autofs

:wq


[root@prema home]# vi /etc/home.autofs
prema   192.168.10.238:/home/prema

[root@prema home]# groupadd -g 1050 dba

[root@prema home]#  useradd -u 1050 -g 1050 gagan
useradd: cannot create directory /home/gagan
[root@prema home]# ls
[root@prema home]# pwd
/home
[root@prema home]# passwd gagan
Changing password for user gagan.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.

Now, login to the system with respective users

[root@prema home]# vi /etc/auto.master
[root@prema home]# vi /etc/home.autofs
[root@prema home]# cat /etc/home.autofs
*       192.168.10.238:/home/&
[root@prema home]# systemctl restart autofs
[root@prema home]# echo $?
0
[root@prema home]# pwd
/home
[root@prema home]# ls
[root@prema home]# cd /
[root@prema /]# cd /home
[root@prema home]# ls
gagan  prema
[root@prema home]# pwd
/home
[root@prema home]# pwd
/home
[root@prema home]# ls
bishal  gagan  pradip  prema
[root@prema home]#

[root@prema /]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/sda3                     18G  4.0G   14G  23% /
devtmpfs                     898M     0  898M   0% /dev
tmpfs                        912M  156K  912M   1% /dev/shm
tmpfs                        912M  9.2M  903M   2% /run
tmpfs                        912M     0  912M   0% /sys/fs/cgroup
/dev/sda1                    297M  152M  146M  51% /boot
/dev/mapper/datavg-datavol   2.0G   33M  2.0G   2% /opt/oracle
tmpfs                        183M   20K  183M   1% /run/user/1000
tmpfs                        183M     0  183M   0% /run/user/0
192.168.10.238:/home          18G   14G  4.6G  75% /mnt
tmpfs                        183M     0  183M   0% /run/user/1050
192.168.10.238:/home/gagan    18G   14G  4.6G  75% /home/gagan
192.168.10.238:/home/prema    18G   14G  4.6G  75% /home/prema
192.168.10.238:/home/bishal   18G   14G  4.6G  75% /home/bishal
192.168.10.238:/home/pradip   18G   14G  4.6G  75% /home/pradip
192.168.10.238:/home/kamal    18G   14G  4.6G  75% /home/kamal
[root@prema /]#

4. Disable autofs
[root@prema /]# systemctl stop autofs
[root@prema /]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sda3                    18G  4.0G   14G  23% /
devtmpfs                    898M     0  898M   0% /dev
tmpfs                       912M  156K  912M   1% /dev/shm
tmpfs                       912M  9.2M  903M   2% /run
tmpfs                       912M     0  912M   0% /sys/fs/cgroup
/dev/sda1                   297M  152M  146M  51% /boot
/dev/mapper/datavg-datavol  2.0G   33M  2.0G   2% /opt/oracle
tmpfs                       183M   20K  183M   1% /run/user/1000
tmpfs                       183M     0  183M   0% /run/user/0
192.168.10.238:/home         18G   14G  4.6G  75% /mnt
tmpfs                       183M     0  183M   0% /run/user/1050
[root@prema /]#

5. Restore original home directory contents
# cd /home; mv /var/tmp/all/* .
or
[root@prema home]# pwd
/home
[root@prema home]# tar -xvzf /var/tmp/home-content.tar.gz

No comments:

Post a Comment