Home > Linux > Setting up a NIS server over CentOS5 working under nfs

Setting up a NIS server over CentOS5 working under nfs

Server side: Preparing

The /etc/hosts has to be like this. (you can replace the domain to whatever you desire, but on this exercise it was defined as “queirozpacheco.com”.

[root@server ~]# cat /etc/hosts

192.168.1.13 server server.queirozpacheco.com yum.queirozpacheco.com
192.168.1.14 host host.queirozpacheco.com
[root@server ~]#

Connecting host via ssh – let’s make the things turning out much easier for us.

[root@server ~]# ssh host
root@host’s password: (press ctrl + C)

So, in this step, press Ctrl + c and send the key pub generated by the server to the host client.

[root@server ~]# cat /root/.ssh/id_rsa.pub | ssh host “cat – > /root/.ssh/authorized_keys”
root@host’s password:

The server doesn’t ask for any password to grant access to you.

[root@server ~]# ssh host
Last login: Mon Feb 22 21:24:17 2010
[root@host ~]#

Client Side: Preparing.

[root@host etc]# cat /etc/hosts

192.168.1.14 host host.queirozpacheco.com
192.168.1.13 server server.queirozpacheco.com yum.queirozpacheco.com
[root@host etc]#

Getting back to Server side. Setting NFS to be available.

———————

1- I created 3 users for using as a test. These one are called joao, maria and jose with their passwords associated.

[root@server ~]# adduser joao; passwd joao
[root@server ~]# adduser jose; passwd jose
[root@server ~]# adduser maria; passwd maria

2- Put an entry into /etc/exports like that below.

/home *(rw,sync)

3- Run “exportfs -a” command.

[root@server ~]# exportfs -a

4- Make sure that nfs is enabled during boot time.

[root@server ~]# chkconfig nfs on

[root@server ~]# chkconfig –list nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@server ~]#

By default I’m used to change init mode to level 3. As you can notice the level 3 is on.

5- Start nfs deamon.

[root@server ~]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@server ~]#

————————
Setting and installing NIS

1- Installing through yum. By default RHEL installs portmap, ypbind as well as yp-tools but unfortunately it cannot be installed. To make sure type:

[root@server ~]# yum install portmap ypserv ypbind yp-tools

2- Open /etc/yp.conf and add new friendly lines: Where queirozpacheco.com is the domain and server.queirozpacheco is the server.

Make sure if it hasn’t been defined in /etc/hosts yet.

[root@server ~]# vi /etc/yp.conf

domain queirozpacheco.com server server.queirozpacheco.com
server server.queirozpacheco.com

3- Type on shell these commands below.

[root@server ~]# domainname queirozpacheco.com
[root@server ~]# ypdomainname queirozpacheco.com

4- Start up ypserv service and put an entry in /etc/sysconfig/network file.

[root@server ~]# service ypserv start
Starting YP server services: [ OK ]
[root@server ~]#

————————

[root@server ~]# vi /etc/sysconfig/network
NISDOMAIN=queirozpacheco.com

5- Generate NIS init maps.

[root@server ~]# /usr/lib/yp/ypinit -m

At this point, we have to construct a list of the hosts which will run NIS
servers. server is in the list of NIS server hosts. Please continue to add
the names for the other hosts, one per line. When you are done with the
list, type a .
next host to add: server
next host to add: server.queirozpacheco.com
next host to add:
The current list of NIS servers looks like this:

server
server.queirozpacheco.com

Is this correct? [y/n: y] y
We need a few minutes to build the databases…
Building /var/yp/queirozpacheco.com/ypservers…
Running /var/yp/Makefile…
gmake[1]: Entering directory `/var/yp/queirozpacheco.com’
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…
gmake[1]: Leaving directory `/var/yp/queirozpacheco.com’

server has been set up as a NIS master server.

Now you can run ypinit -s server on all slave server.
[root@server ~]#

6- Start up ypbind service.

[root@server ~]# service ypbind start
Binding to the NIS domain: [ OK ]
Listening for an NIS domain server.
[root@server ~]#

7- Start up yppasswdd service.

[root@server ~]# service yppasswdd start
Starting YP passwd service: [ OK ]
[root@server ~]#

8- Start up ypxfrd and portmap services.

[root@server ~]# service portmap start
Starting portmap: [ OK ]
[root@server ~]# service ypxfrd start
Starting YP map server: [ OK ]
[root@server ~]#

9- Make sure that these one will startup during the boot process.

[root@server ~]# for i in ypserv ypbind yppasswdd portmap ypxfrd; do chkconfig $i on; done
[root@server ~]#

10- were you thinking to check if ypserv is working correctly? Try this one.

[root@server ~]# rpcinfo -u localhost ypserv
program 100004 version 1 ready and waiting
program 100004 version 2 ready and waiting
[root@server ~]#

11- Finally, run make command in /var/yp directory.

[root@server ~]# cd /var/yp/
[root@server yp]# make
gmake[1]: Entering directory `/var/yp/queirozpacheco.com’
Updating netid.byname…
gmake[1]: Leaving directory `/var/yp/queirozpacheco.com’
[root@server yp]#

Getting back to Client Side. Let’s put making up.

Configuring AutoFS to mount /home directories.

It allows the system mounting home’s directories at the moment when they log in and past some time (timeout time) it will be unmounted automatically.

1- Setting /etc/auto.master.

[root@host etc]# mv auto.master auto.master.backup

[root@host etc]# vi auto.master

/home /etc/auto.home –timeout 300

2- Create /etc/auto.home and make it out like this.

[root@host etc]# vi auto.home

* -fstype=nfs,soft,rsize=8192,wsize=8192,intr,tcp server:/home/&

3- Make sure if the nfs service works.

[root@host etc]# mount server:/home /home
[root@host etc]# mount |grep server
server:/home on /home type nfs (rw,addr=192.168.1.13)

Unmount at once.

[root@host etc]# umount /home

4- Install ypbind and portmap.

[root@host etc]# yum install ypbind portmap

5- Set through system-config-authentication tool as NIS client configuring:

Domain: queirozpacheco.com
Server: server.queirozpacheco.com

or Edit yp.conf in /etc like this. Edit also /etc/nsswitch.conf

domain queirozpacheco.com server server.queirozpacheco.com

——————————–

and Edit nssswitch.conf and put these lines into that.

passwd: files nis

shadow: files nis

group: files nis

6- start up ypbind, autofs and portmap. Make sure that they will be startup during the boot.

[root@host ~]# service portmap start
[root@host ~]# service ypbind start
[root@host ~]# service autofs start

————————————-

[root@host ~]# for i in portmap autofs ypbind; do chkconfig $i on; done

7- You can try this to check if is working or not.

[root@host ~]# ypcat passwd
jose:$1$CSjl0r3p$BkSouhc2ENyZwsGAdO.58.:502:502::/home/jose:/bin/bash
joao:$1$kDne475.$1/XLOERyzye9uG4stE8Kc.:500:500::/home/joao:/bin/bash
maria:$1$xB8Livy9$jS7lpQubNdQxCIISEjln71:501:501::/home/maria:/bin/bash
[root@host ~]#

———————–

[root@host ~]# rpcinfo -u localhost ypbind
program 100007 version 1 ready and waiting
program 100007 version 2 ready and waiting
[root@host ~]#

Okay… Now, let’s get started to trying.

Log in as jose, maria and joao.

[root@server ~]# ssh jose@host
jose@host’s password:
Last login: Mon Feb 22 23:00:58 2010 from server

[jose@host ~]$ pwd
/home/jose

[jose@host ~]$ mount |grep nfs

server:/home/jose on /home/jose type nfs (rw,soft,rsize=8192,wsize=8192,intr,tcp
,addr=192.168.1.13)

[jose@host ~]$

———-

[root@server ~]# ssh joao@host
joao@host’s password:
[joao@host ~]$ pwd
/home/joao
[joao@host ~]$ mount |grep nfs
server:/home/jose on /home/jose type nfs (rw,soft,rsize=8192,wsize=8192,intr,tcp
,addr=192.168.1.13)
server:/home/joao on /home/joao type nfs (rw,soft,rsize=8192,wsize=8192,intr,tcp
,addr=192.168.1.13)
[joao@host ~]$

————–

[root@server ~]# ssh maria@host
maria@host’s password:
Last login: Mon Feb 22 22:58:57 2010
[maria@host ~]$ pwd
/home/maria
[maria@host ~]$ mount |grep nfs

server:/home/jose on /home/jose type nfs (rw,soft,rsize=8192,wsize=8192,intr,tcp
,addr=192.168.1.13)
server:/home/joao on /home/joao type nfs (rw,soft,rsize=8192,wsize=8192,intr,tcp
,addr=192.168.1.13)
server:/home/maria on /home/maria type nfs (rw,soft,rsize=8192,wsize=8192,intr,t
cp,addr=192.168.1.13)
[maria@host ~]$

Wait for 5 min without using the session user. Actually, all these mount points must be unmounted after this while.

[root@host ~]# mount |grep nfs
[root@host ~]#

So, that’s all. See ya folks.

If you wanna work behind a firewall, to set a fixed port to NIS service, edit /etc/sysconfig/network and put this entries
YPSERV_ARGS=”-p 834″
YPXFRD_ARGS=”-p 835″

Cheers!

Carlos.

Categories: Linux
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment