- 2010-85日
NIS服务简介
NIS的前身是SUN公司开发的一款叫Yellow Page的信息共享的软件,后来由于注册商标的原因改名为NIS。NIS可以用来在LINUX之间进行资源的集中管理和帐户信息共享。
提到NIS不得不先说明一下WINDOWS的域控制器,在局域网内有一台WINOWS域控制器,下面有一些机器加入到这个域中,在机器登录时,有一个选项是选择登入到本机还时登入到域内,登入本地的密码有本机控制,但是如果登入域内,密码由域控制器负责管理。
LINUX也是操作系统,跟WINOWS没有本质的区别,所以仔细读上段话,就能理解NIS是原理是什么样了,这时出现了一个重要的配置文件/etc/nsswitch.conf
NIS是一个客户机/服务器系统,ypbind是定义NIS服务器的客户端进程。一旦确定了服务器位置,客户机绑定到了服务器上,所以客户端的住处查询都发往服务器。ypserv是回答客户端查询的服务器进程。
NIS服务软件安装
第一步:安装ypserv服务程序,这个需要手动安装的,加载光盘,执行安装程序
[root@a ~]# mount /dev/cdrom /media/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@a ~]# rpm -ivh /media/Server/ypserv-2.19-5.el5.i386.rpm
warning: /media/Server/ypserv-2.19-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:ypserv ########################################### [100%]
[root@a ~]#
另外portmap、yptools和ypbind都是必须的程序,Redhat系统是默认安装的,这里不需要另外安装。
其中ypserv是NIS的服务器端程序,yp-tools和ypbind是客户端程序,portmap是端口分配程序。在NIS服务器上一般只需要安装ypserv和portmap,但是由于服务器本身也是其自己的客户端,所以在服务器上,我们将这四个软件包都装上。
[root@a ~]# rpm -qa|grep yp
xorg-x11-fonts-truetype-7.1-2.1.el5
freetype-2.2.1-21.el5_3
libgcrypt-1.4.4-5.el5
m2crypto-0.16-6.el5.6
cryptsetup-luks-1.0.3-5.el5
ypbind-1.19-12.el5
yp-tools-2.9-1.el5
xorg-x11-drv-hyperpen-1.1.0-2
ypserv-2.19-5.el5
xorg-x11-fonts-Type1-7.1-2.1.el5
[root@a ~]# rpm -qa|grep portmap
portmap-4.0-65.2.2.1
[root@a ~]#
第二步:配置服务器端
设置NIS域名为liusuping.com,通过以下命令:
[root@a ~]# nisdomainname liusuping.com
[root@a ~]# nisdomainname
liusuping.com
为了系统启动后自动执行此操作,可以将命令"/bin/nisdomainname liusuping.com"添加到文件/etc/rc.local中。
[root@a ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
/bin/nisdomainname liusuping.com
touch /var/lock/subsys/local
配置服务器端主配置文件编辑文件/etc/ypserv.conf,在文件的最后添加控制参数,允许部分客户端可以访问nis服务器。
# Host : Domain : Map : Security
# * : * : passwd.byname : port
192.168.0.0/255.255.255.0 : * : * : none
127.0.0.0/255.255.255.0 : * : * : none
all : * : * : deny
其它参数保持默认值即可!securenets的安全配置(此文件在系统中没有,需要手动建立,保存在/var/yp目录中)
Host 127.0.0.1
255.255.255.0 192.168.0.0启动服务启动服务器端的相关服务包括portmap和ypserv,yppasswdd,命令如下:
[root@a ~]# service portmap start
启动 portmap:[确定]
[root@a ~]# service ypserv start
启动 YP 服务器的服务:[确定]
[root@a ~]# service yppasswdd start
启动 YP 口令服务:[确定]
[root@a ~]#
初始化NIS数据库运行命令:/usr/lib/yp/ypinit -m ,(其中-m是master,相当于将当前主机设置为主域控),然后设置主数据库存储主机的名称,然后按CTRL+D键,最后按Y确认,最后程序将创建初始化的NIS数据库。
[root@a ~]# /usr/lib/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers. a.liusuping.com 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 <control D>.
next host to add: a.liusuping.com
next host to add:
The current list of NIS servers looks like this:a.liusuping.com
Is this correct? [y/n: y]
We need a few minutes to build the databases...
Building /var/yp/liusuping.com/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/liusuping.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/liusuping.com'a.liusuping.com has been set up as a NIS master server.
Now you can run ypinit -s a.liusuping.com on all slave server.
创建完成后,在目录/var/yp下会生成一个liusuping.com的目录,目录下还有很多数据库文件。
[root@a ~]# ls /var/yp/
binding liusuping.com Makefile nicknames ypservers
[root@a ~]# ls /var/yp/liusuping.com/
group.bygid hosts.byname passwd.byname protocols.bynumber services.byname
group.byname mail.aliases passwd.byuid rpc.byname services.byservicename
hosts.byaddr netid.byname protocols.byname rpc.bynumber ypservers
NIS客户端配置
默认情况下NIS客户端程序portmap,ypbind和yp-tools是默认安装的,不需要另外安装。
设置NIS域名为liusuping.com
[root@b ~]# nisdomainname liusuping.com
[root@b ~]# nisdomainname
liusuping.com
设置网卡所在的NIS域,通过以下命令:#echo "NISDOMAIN=liusuping.com" >> /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=b.liusuping.com
NISDOMAIN=liusuping.com
配置nis客户端配置文件编辑文件/etc/yp.conf,在文件末尾添加以下参数:domain liusuping.com server a.liusuping.com
[root@b ~]# vim /etc/yp.conf
# /etc/yp.conf - ypbind configuration file
# domain NISDOMAIN server HOSTNAME
domain liusuping.com server a.liusuping.com
修改 /etc/hosts文件
[root@b ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.0.200 a.liusuping.com
编辑文件/etc/nsswitch.conf,更改密码查询顺序。
[root@b ~]# vim /etc/nsswitch.conf
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis
passwd: files nis
shadow: files nis
group: files nis
#hosts: db files nisplus nis dns
hosts: files nis dns
启动服务portmap,ypbind
测试nis客户端通过以下命令:ypcat passwd,如果能够输出服务器上普通用户的帐户信息,则说明NIS配置成功。其它测试命令还有yptest,ypwhich -x等。
[root@linux-b ~]# ypcat passwd
frank:$1$ECsPpKqW$1m.sXZSFcMqBpglkx0SrG0:501:501::/home/frank:/bin/bash
frankliu:$1$3sH.vpiy$BaexAOuIBebtNWs98P9cb0:500:500:frank liu:/home/frankliu:/bin/bash其他配置
NIS客户端通过 NIS服务器进行帐户认证的时候,需要两者系统时间一致,所以在配置NIS的同时,一般还要配置NTPD服务,即网络时间协议,然后通过cron定时同步时钟,进而达到系统时间一致的目的。除以上外,NIS还可以结合NFS达到漫游用户配置文件的目的。我们可以通过NFS共享服务器上的/home目录,然后在NIS客户端系统启动时,自动挂载/home目录到客户端上,命令是:mount -t nfs 192.168.20.200:/home /home
可以把此命令加入到文件/etc/rc.local中,也可以配置文件/etc/fstab,使系统自动挂载,当用户在nis客户端登陆时,将自动使用其在服务器上的宿主目录。
转载请注明:
本文转自:http://www.liusuping.com/ubuntu-linux/Redhat-Linux-NIS-setting.html
- 评论:(0)
- 引用通告
发表评论点击这里获取该日志的TrackBack引用地址