Saturday, May 21, 2016

RHEL7 - How to configure nfs server/autofs

 how to configure nfs server/autofs on RHEL7

1. add entry to /etc/exports
vi /etc/exports

/opt/myshare    *(rw,sync)

wq!

2. Start network service
# systemctl start nfs.server

3. Verify your export
# exportfs

# showmount -e localhost
Export list for localhost:
/opt/myshare *

# showmount -e 192.168.10.120
Export list for 192.168.10.120:
/opt/myshare *



Go to client
1. Verify you can access nfs server share

# showmount -e 192.168.10.120
Export list for 192.168.10.120:
/opt/myshare *


2. Mount the share
# mount -t nfs 192.168.10.120:/opt/myshare /mnt


3. Verify you mounted nfs share successfully

[root@localhost ~]# cd /mnt
[root@localhost mnt]# df -h .
Filesystem                   Size  Used Avail Use% Mounted on
192.168.10.120:/opt/myshare   20G   16G  4.7G  77% /mnt
[root@localhost mnt]#



autofs set up

nfs server

[root@sudhir ravi]# ls -ld /opt/sudhir/
drwxr-xr-x. 2 root root 6 May 14 11:00 /opt/sudhir/
[root@sudhir ravi]# pwd
/opt/ravi
[root@sudhir ravi]# exportfs
[root@sudhir ravi]# cat /etc/exports
/opt/sudhir     *(rw,sync)
[root@sudhir ravi]# systemctl start nfs-server
[root@sudhir ravi]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2016-05-21 08:40:27 EDT; 1h 16min ago
 Main PID: 663 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─663 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

May 21 08:40:19 sudhir.expanor.local systemd[1]: Starting firewalld - dynamic firewall dae.....
May 21 08:40:27 sudhir.expanor.local systemd[1]: Started firewalld - dynamic firewall daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@sudhir ravi]# systemctl stop  firewalld
[root@sudhir ravi]# exportfs
/opt/sudhir     <world>
[root@sudhir ravi]#


autofs client


[root@localhost ravi]# cat /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc   /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
/net    -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/export/home    /etc/auto.sudhir

[root@localhost ravi]# cat /etc/auto.sudhir
sudhir  -rw     192.168.10.9:/opt/sudhir

[root@localhost ravi]# cd /export/home/sudhir
-bash: cd: /export/home/sudhir: No such file or directory

[root@localhost ravi]# systemctl status autofs
autofs.service - Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; disabled)
   Active: inactive (dead)

[root@localhost ravi]# systemctl start autofs
[root@localhost ravi]# systemctl status autofs
autofs.service - Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; disabled)
   Active: active (running) since Sat 2016-05-21 07:04:17 PDT; 2s ago
  Process: 6944 ExecStart=/usr/sbin/automount $OPTIONS --pid-file /run/autofs.pid (code=exited,                                                                         status=0/SUCCESS)
 Main PID: 6946 (automount)
   CGroup: /system.slice/autofs.service
           └─6946 /usr/sbin/automount --pid-file /run/autofs.pid

May 21 07:04:16 localhost.localdomain automount[6946]: setautomntent: lookup(sss): setautom...ry
May 21 07:04:17 localhost.localdomain systemd[1]: Started Automounts filesystems on demand.
Hint: Some lines were ellipsized, use -l to show in full.

[root@localhost ravi]# cd /export/home/sudhir
[root@localhost sudhir]# pwd
/export/home/sudhir
[root@localhost sudhir]# df -h .
Filesystem                Size  Used Avail Use% Mounted on
192.168.10.9:/opt/sudhir   13G  6.5G  5.7G  54% /export/home/sudhir
[root@localhost sudhir]#

No comments:

Post a Comment