Friday, October 2, 2009

Update NIS maps, share automount files (linux)

If you need to share mounts coming from your NIS server automatically on multiple linux clients you will update the local auto.master with something like :
/net yp:auto.net

Usually auto. folder refers to a /folder. All NFS shares automounted through auto.folder, will be mounted in /folder.

For instance you create a /etc/auto.netShare on your NIS server including :
home -rw server1:/mnt/sdb2
data -rw server2:/mnt/sdc1
public -rw server3:/mnt/sdb1


In order to make available this file to clients, you need to edit the /var/yp/Makefile first.

  1. Search for "AUTO_MASTER = $(YPSRCDIR)/auto.master"

  2. Add a new line just below :
    AUTO_NETSHARE = $(YPSRCDIR)/auto.netShare

  3. Search for "all:"
    Add auto.netShare to the list (passwd group hosts rpc...). By default all auto.xxx are commented out.

  4. Search for :
    auto.master: $(AUTO_MASTER) $(YPDIR)/Makefile
    @echo "Updating $@..."
    -@sed -e "/^#/d" -e s/#.*$$// $(AUTO_MASTER) | $(DBLOAD) \
    -i $(AUTO_MASTER) -o $(YPMAPDIR)/$@ - $@
    -@$(NOPUSH) || $(YPPUSH) -d $(DOMAIN) $@

  5. Add below the auto.master block :
    auto.netShare: $(AUTO_NETSHARE) $(YPDIR)/Makefile
    @echo "Updating $@..."
    -@sed -e "/^#/d" -e s/#.*$$// $(AUTO_NETSHARE) | $(DBLOAD) \
    -i $(AUTO_NETSHARE) -o $(YPMAPDIR)/$@ - $@
    -@$(NOPUSH) || $(YPPUSH) -d $(DOMAIN) $@

  6. Then better do a clean up in /var/yp :
    > cd /var/yp
    > rm -rf ./group* ./binding/* ./hosts* mail* netid* pass* proto* rpc* services* mydomain*

  7. Build the maps containing the new auto.netShare file
    > make all
    Running /var/yp/Makefile...
    gmake[1]: Entering directory `/var/yp/mydomain.intra'
    Updating passwd.byname...
    Updating passwd.byuid...
    Updating group.byname...
    Updating group.bygid...
    Updating hosts.byname...
    Updating hosts.byaddr...
    Updating rpc.byname...
    Updating rpc.bynumber...
    Updating services.byname...
    Updating services.byservicename...
    Updating netid.byname...
    Updating protocols.bynumber...
    Updating protocols.byname...
    Updating mail.aliases...
    Updating auto.netShare...

    gmake[1]: Leaving directory `/var/yp/mydomain.intra'

  8. Check your auto.netShare is part of the NIS maps :
    > ypcat auto.netShare
    -rw server1:/mnt/sdb2
    -rw server2:/mnt/sdc1
    -rw server3:/mnt/sdb1

  9. Now you can update /etc/auto.master on all clients with :
    /netShare yp:auto.netShare

  10. And restart automount on the clients :
    > /etc/init.d/autofs restart

Then you can use /netShare/home, /netShare/data, netShare/public on all clients. These folders are mounted when accessed and released after a while.

No comments:

Post a Comment