Wednesday, June 22, 2011

Linux NIS Service Configuration


Linux NIS Service Configuration
Scenario
To understand the benefits of NFS, consider an example. A school wants to set up a small computer lab for students.
Downloading and installing RPMs. When searching for the RPMs, remember that the filename usually starts with the software package name followed by a version number, as in yp-tools-2.8-3.i386.rpm.

The lab instructor did some research and created an implementation plan:
1. Configure Gsntek as an NFS server to make its /home directory available to the Linux workstations.
2. Configure smallfry as an NFS client that can access Gsntek's /home directory.
3. Configure Gsntek as an NIS server.
4. Create a user account (nisuser) on Gsntek that doesn't exist on smallfry. Convert the account to a
NIS user account.
5. Configure smallfry as an NIS client.
6. Test a remote login from Gsntek to smallfry using the username and password of the account nisuser.
Configuring The NFS Server
Here are the steps to configure the NFS server in this scenario:
1. Edit the /etc/exports file to allow NFS mounts of the /home directory with read/write access.
/home *(rw,sync)
2. Let NFS read the /etc/exports file for the new entry, and make /home available to the network with the exportfs command.
[root@gsntek tmp]# exportfs -a
3. Make sure the required nfs, nfslock, and portmap daemons are both running and configured to start after the next reboot.
chkconfig nfslock on
chkconfig nfs on
chkconfig portmap on
service portmap start
Starting portmapper: [ OK ]
service nfslock
start Starting NFS statd: [ OK ]
service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
After configuring the NFS server configure its clients
Configuring The NFS Client
You also need to configure the NFS clients to mount their /home directories on the NFS server. These steps archive the /home directory. In a production environment in which the /home directory
would be actively used, you'd have to force the users to log off, backup the data, restore it to the NFS server, and then follow the steps below. As this is a lab environment, these prerequisites aren't necessary.
1. Make sure the required netfs, nfslock, and portmap daemons are running and configured to start after the next reboot.
chkconfig nfslock on
chkconfig netfs on
chkconfig portmap on
service portmap start
Starting portmapper: [ OK ]
service netfs start Mounting other filesystems: [ OK ]
service nfslock start Starting NFS statd: [ OK ]
2. Keep a copy of the old /home directory, and create a new directory /home on which you'll mount the
NFS server's directory.
mv /home /home.save
mkdir /home
3. Make sure you can mount gsntek's /home directory on the new /home directory you just created. Unmount it once everything looks correct.
# mount 192.168.1.100:/home /home/
# ls /home
# umount /home
4. Start configuring autofs automounting. Edit your /etc/auto.master file to refer to file /etc/auto.home for mounting information whenever the /home directory is accessed. After five minutes, autofs unmounts the directory.
#/etc/auto.master
/home /etc/auto.home --timeout 600
5. Edit file /etc/auto.home to do the NFS mount whenever the /home directory is accessed. If the line is too long to view on your screen, you can add a \ character at the end to continue on the next line.
#/etc/auto.home
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp \
192.168.1.100:/home/&
6. Start autofs and make sure it starts after the next reboot with the chkconfig command.
# chkconfig autofs on
# service autofs restart
After doing this, you won't be able to see the contents of the /home directory on gsntek as user root. This is because by default NFS activates the root squash feature, which disables this user from having privileged access to directories on remote NFS servers. You'll be able to test this later after NIS is configured.
Configuring The NIS Server
NFS only covers file sharing over the network. You now have to configure NIS login authentication for the lab students before the job is done. The configuration of the NIS server is not difficult, but requires many steps that you may overlook. Don't worry, we'll review each one in detail.
Note: In the early days, NIS was called Yellow Pages. The developers had to change the name after a copyright infringement lawsuit, yet many of the key programs associated with NIS have kept their original names beginning with yp.
Install the NIS Server Packages
All the packages required for NIS clients are a standard part of most Fedora installations. The ypserv package for servers is not. Install the package according to the steps outlined
Edit Your /etc/sysconfig/network File
You need to add the NIS domain you wish to use in the /etc/sysconfig/network file. For the school, call the domain NIS-SCHOOL-NETWORK.
#/etc/sysconfig/netwwork
NISDOMAIN="NIS-SCHOOL-NETWORK"
Edit
/etc/yp.conf File
NIS servers also have to be NIS clients themselves, so you'll have to edit the NIS client configuration file /etc/yp.conf to list the domain's NIS server as being the server itself or localhost.
# /etc/yp.conf - ypbind configuration file ypserver 127.0.0.1
Start The  NIS Server Related Daemons
Start the necessary NIS daemons in the /etc/init.d directory and use the chkconfig command to ensure they start after the next reboot.
# service portmap start
# service yppasswdd start
# service ypserv start
Setting NIS domain name NIS-SCHOOL-NETWORK: [ OK ] Starting YP server services: [ OK ]
# chkconfig portmap on
# chkconfig yppasswdd on
# chkconfig ypserv on
The ypbind and ypxfrd daemons won't start properly until after you initialize the NIS domain. You'll start these daemons after initialization is completed.
Initialize NIS Domain
# /usr/lib/yp/ypinit -m
gsntek
Is this correct? [y/n: y] y
Leaving directory `/var/yp/NIS-SCHOOL-NETWORK' gsntek has been set up as a NIS master server.
Now you can run ypinit -s gsntek on all slave server.
Start The ypbind and ypxfrd Daemons
You can now start the ypbind and the ypxfrd daemons because the NIS domain files have been created.
# service ypbind start
Binding to the NIS domain: [ OK ]
# service ypxfrd start
# chkconfig ypbind on
# chkconfig ypxfrd on
Adding New NIS Users
New NIS users can be created by logging into the NIS server and creating the new user account. In this case, you'll create a user account called nisuser and give it a new password.
Once this is complete, you then have to update the NIS domain's authentication files by executing the make command in the /var/yp directory.
# useradd -g users nisuser
# passwd nisuser
# cd /var/yp
# make
Configuring The NIS Client
NIS server is configured, it's time to configure the NIS clients. There are a number of related configuration files that you need to edit to get it to work. Take a look at the procedure.
Run authconfig
The authconfig or the authconfig-tui program automatically configures your NIS files after prompting you for the IP address and domain of the NIS server.
# authconfig-tui
Once finished, it should create an /etc/yp.conf file that defines, amongst other things, the IP address of the NIS server for a particular domain. It also edits the /etc/sysconfig/network file to define the NIS domain to which the NIS client belongs.
# /etc/yp.conf - ypbind configuration file domain NIS-SCHOOL-NETWORK server 192.168.1.100
#/etc/sysconfig/network
NISDOMAIN=NIS-SCHOOL-NETWORK
In addition, the authconfig program updates the /etc/nsswitch.conf file that lists the order in which certain data sources should be searched for name lookups, such as those in DNS, LDAP, and NIS. Here you can see where NIS entries were added for the important login files.
#/etc/nsswitch.conf passwd: files nis shadow: files nis group: files nis
Start The NIS Client Related Daemons
# service portmap start
# service ypbind start
# chkconfig ypbind on
# chkconfig portmap on
Remember to use the rpcinfo -p localhost command to make sure they all started correctly.
Test NIS Access To The NIS Server
You can run the ypcat, ypmatch, and getent commands to make sure communication to the server is correct.
# ypcat passwd nisuser
# ypmatch nisuser passwd nisuser
# getent passwd nisuser nisuser
The End......................

1 comment: