一、简介
NIS(Network Information Service,亦即一般简称之“黄页”YP(Yellow Pages))是
Sun Microsystem于1985年发布的一项目录服务技术(DiretoryService),用来集中控制
几个系统管理数据库的网络用品。NIS简化了UNIX和LINUX桌面客户的管理工作,
客户端利用它可以使用中心服务器的管理文件。桌面系统的用户无需建立他们自己
的/etc/passwd,他们只简单的使用维护在NIS服务器的文件即可。NIS是一个客户机/
服务器系统,YPbind是定义NIS服务器的客户端进程。一旦确定了服务器位置,客户
机绑定到了服务器上,所以客户端的住处查询都发往服务器。YPserv是回答客户端
查询的服务器进程。
NIS 相关指令
- ypcat
- ypmatch
- ypwhich
- ypclnt
- yppasswd
- ypset
- ypmake
- ypinit
- yppush
- ypserve
二、案例
1.服务器端
安装软件包
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
[root@localhost ~]# cd /mnt/cdrom/Server
[root@localhost Server]# rpm -ivh ypserv-2.19-5.el5.i386.rpm
启动服务
[root@localhost Server]# service ypserv start
[root@localhost Server]# chkconfig ypserv on
[root@localhost Server]# service yppasswdd start
启动 YP 口令服务: [确定]
[root@localhost Server]# chkconfig yppasswdd on
[root@localhost Server]# cd /var/yp
修改能够导入的信息:
[root@localhost yp]# vim Makefile
编辑结果:
117 all: passwd group hosts \
编辑域环境
[root@localhost yp]# vim /etc/sysconfig/network
编辑结果:
4 NISDOMAIN=rhce
重启
[root@localhost yp]# init 6
[root@localhost Server]# cd /var/yp
产生域
[root@localhost yp]# /usr/lib/yp/ypinit –m
At this point, we have to construct a list of the hosts which will run NIS
servers. localhost.localdomain 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: localhost.localdomain
next host to add:
The current list of NIS servers looks like this:
localhost.localdomain
Is this correct? [y/n: y] y
We need a few minutes to build the databases...
Building /var/yp/(none)/ypservers...
Running /var/yp/Makefile...
Domain name cannot be (none)
localhost.localdomain has been set up as a NIS master server.
Now you can run ypinit -s localhost.localdomain on all slave server.
[root@localhost yp]# ll
总计 44
drwxr-xr-x 2 root root 4096 2009-04-15 binding
-rw-r--r-- 1 root root 16635 08-19 19:55 Makefile
-rw-r--r-- 1 root root 185 2006-07-13 nicknames
drwxr-xr-x 2 root root 4096 08-19 20:04 rhce
-rw-r--r-- 1 root root 22 08-19 20:04 ypservers
建立帐号,导入账号库
[root@localhost ~]# useradd user3
[root@localhost ~]# passwd user3
Changing password for user user3.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# cd /var/yp/
[root@localhost yp]# make
gmake[1]: Entering directory `/var/yp/rhce'
Updating passwd.byname...
Updating passwd.byuid...
Updating group.byname...
Updating group.bygid...
Updating hosts.byname...
Updating hosts.byaddr...
gmake[1]: Leaving directory `/var/yp/rhce'
客户端配置
安装软件
[root@localhost Server]# rpm -ivh ypbind-1.19-12.el5.i386.rpm
客户端配置
2.设置手动挂载, 共享服务器端用户家目录
[root@localhost ~]# vim /etc/exports
/home 192.168.20.0/24(rw,sync)
[root@localhost yp]# service nfs restart
关闭 NFS mountd: [确定]
关闭 NFS 守护进程: [确定]
关闭 NFS quotas: [确定]
关闭 NFS 服务: [确定]
启动 NFS 服务: [确定]
关掉 NFS 配额: [确定]
启动 NFS 守护进程: [确定]
启动 NFS mountd: [确定]
[root@localhost yp]# chkconfig nfs on
导入共享清单
[root@localhost yp]# exportfs -rv
exporting 192.168.20.0/24:/home
客户端导入查看共享清单
3.为提高服务器可用性设置自动挂载
删除手动挂载
服务器端配置
[root@localhost yp]# vim /etc/exports
/nishome 192.168.20.0/24(rw,sync)
导出共享清单
[root@localhost yp]# exportfs -rv
exporting 192.168.20.0/24:/nishome
[root@localhost yp]# mkdir /nishome
[root@localhost yp]# useradd -d /nishome/user10 user10
[root@localhost yp]# passwd user10
Changing password for user user10.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
刷新账号库
cd /var/yp
[root@localhost yp]# make
重启服务
[root@localhost yp]# service nfs restart
关闭 NFS mountd: [确定]
关闭 NFS 守护进程: [确定]
关闭 NFS quotas: [确定]
关闭 NFS 服务: [确定]
启动 NFS 服务: [确定]
关掉 NFS 配额: [确定]
启动 NFS 守护进程: [确定]
启动 NFS mountd: [确定]
客户端配置
[root@localhost ~]# vim /etc/auto.master
10 /nishome /etc/auto.qq --timeout=60
[root@localhost ~]# cp /etc/auto.misc /etc/auto.qq
[root@localhost ~]# vim /etc/auto.qq
* -ro,soft,intr 192.168.20.10:/nishome/&
[root@localhost ~]# mkdir /nishome
[root@localhost ~]# chmod o+wt /nishome/
[root@localhost ~]# service autofs restart
停止 automount: [确定]
启动 automount: [确定]