络信息服务(nis)

nis是一个客户机/服务器系统,ypbind是定义nis服务器的客户端进程。一旦确定了服务器位置,客户机绑定到了服务器上,所以客户端的查询都发往服务器,ypserv是回答客户端查询的进程(重要文件/etc/nsswitch.conf)

文件/etc/nsswitch.conf(name service switch configuration,名字服务切换配置)规定通过哪些途径以及按照什么顺序通过这些途径来查找特定类型的信息。还可以指定某个方法奏效或失效时系统将采取什么动作。

info: method`action` [method`action`...]
    其中,info指定该行所描述的信息的类型,method为用来查找该信息的方法,action是对前面的method返回状态的响应。action要放在方括号里。

automount

自动挂载(/etc/auto.master和/etc/auto.misc)

bootparams

无盘引导选项和其他引导选项(参见bootparam的手册页)

ethers

MAC地址

group

用户所在组(/etc/group),getgrent()函数使用该文件

hosts

主机名和主机号(/etc/hosts),gethostbyname()以及类似的函数使用该文件


passwd

用户口令(/etc/passwd),getpwent()函数使用该文件

protocols


网络协议(/etc/protocols),getprotoent()函数使用该文件

services

网络服务(/etc/services),getservent()函数使用该文件

下面列出了nsswich.conf文件控制搜索信息类型的方法,对于每一种信息类型,都可以指定下面的一种或多种方法

files搜索本地文件,如/etc/passwd和/etc/hostsnis搜索NIS数据库,nis还有一个别名,即ypdns查询DNS(只查询主机)compatpasswd、group和shadow文件中的±语法(参见本节后面的相关内容)

搜索顺序(/etc/nsswitch.conf     从左到右)

passwd files nis
host nis files dns
    第一行让系统在/etc/passwd文件中搜索口令信息,如果失败的话,就使用NIS来查找信息。如果正在查找的用户同时出现在这两个地方,就会使用本地文件中的信息,因此它就是权威信息。第二行先使用NIS搜索;如果失败的话,就搜索/etc/hosts文件;如果再次失败的话,核对DNS以找出主机信息。

nis  msater

1.指定database

2.提供slave更新

3.提供nis client查询

nis slave

1.取得master的database

2.提供nis client查询

 nis client

login_

     1./etc/passwd

          /etc/shadow

     2.nis 查询




nis安装

http://mirrors.163.com/centos/6/os/x86_64/Packages/yp-tools-2.9-12.el6.x86_64.rpm

http://mirrors.163.com/centos/6/os/x86_64/Packages/ypserv-2.19-26.el6_4.2.x86_64.rpm

http://mirrors.163.com/centos/6/os/x86_64/Packages/ypbind-1.20.4-30.el6.x86_64.rpm

搭建nis服务器

yum -y install   portmap

rpm -ivh   ypserv-2.19-26.el6_4.2.x86_64.rpm --nodeps



加入域环境

vi /etc/sysconfig/network

NISDOMAIN=rhce     加入域rhce

/usr/lib64/yp/ypinit -m 构建nis服务器数据库

          /var/yp会有rhce的nis库


service ypserv start

service yppasswdd start

chkconfig ypserv on

chkconfig yppasswdd on


测试账号

useradd user2

passwd user2

cd /var/yp 

make 


服务器新建用户

将用户数据导入到数据库

cd /var/yp

make


nis客户端

rpm -ivh yp-tools-2.9-12.el6.x86_64.rpm --nodeps

rpm -ivh ypbind-1.20.4-30.el6.x86_64.rpm --nodeps

yum -y install portmap

vi  /etc/yp.conf

domain rhce server 192.168.233.128

vi /etc/nsswitch.conf

passwd:     files nis
shadow:     files nis
group:      files nis

hosts:      files nis dns

netgroup:   nisplus nis

publickey:  nisplus

automount:  files nisplus nis
aliases:    files nisplus nis(在file后面加上nis)

service  ypbind restart            加入、绑定 rhce nis域

yptest           可以看到数据

使用测试账号user2登录




希望把服务器端的用户家目录自动挂载到客户端机器上

nis服务器端

yum -y install nfs*

vim /etc/exports

/nishome *(ro)

exportfs -rv

mkdir /nishome

useradd -d /nishome/user3 user3

passwd user3

service nfs restart


客户端配置

vi /etc/auto.master

     /misc  /etc/auto.misc

     /nishome  /etc/auto.nfs --timeout=60 (两个文件属性一样)

vi /etc/auto.nfs

* -ro,soft.intr 192.168.233.128:/nishome/&

service autofs restart