NIS(Network Information Service)用来共享网络主机上的信息,我们最常见是的共享用户信息,我们可以将用户信息统一配置在NIS服务器上,客户机只需要通过NIS服务器上获取username、passwd信息。
NIS server(Master/Slave)
1、NIS Master:首先NIS Master将用户信息生成数据库文件。
2、NIS Master:master可以主动Push用户信息到Slave数据库中。
3、NIS Slave:Slave也可以主动Request Master上的用户信息并更新到自己的数据库中。
NIS Client:
1、Client用户登录时首先查询本地的passwd、shadow中的数据;如果在本地中没有查询到该用户信息,Client开始向整个NIS域中广播查询;NIS master和Slave都可以响应Client端的请求,响应没有先后顺序,先响应者优先。
![这里写图片描述](https://img-blog.csdn.net/20161222143137441?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTmlhbl9DdHJs/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
整个环境的实例:
1、NIS域名:zlnian
2、NIS Master:IP:192.168.56.101 hostname:pnode2
3、NIS Slave:IP:192.168.56.102 hostname:pnode3
4、NIS Client:IP:192.168.56.103 hostname:pnode4
1、配置本地yum源:
vim /etc/yum.repos.d/local_yum.repo
[Centos6]
name=Centos6X
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
2、挂在本地yum源:
mount -oloop /root/rhel-server-6.5-x86_64-dvd.iso /mnt/
3、安装软件包:
yum install ypserv yp-tool ypbind -y
1、配置NIS Master:
运行:authconfig-tui (或authconfig-gtk)
在图形界面中选择”NIS”,在下一步的设置中填写”zlnian”, “<127.0.0.1>”
2、启动ypserv服务并设置自启动方式:
service ypserv restart
chkconfig ypserv on
3、配置NIS Master的数据库文件:
[root@pnode2 ~]# /usr/lib64/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers. pnode2 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: pnode2
next host to add: pnode3
next host to add:
The current list of NIS servers looks like this:
pnode2
pnode3
Is this correct? [y/n: y] y
We need a few minutes to build the databases...
Building /var/yp/zlnian/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/zlnian'
Updating passwd.byname...
Updating passwd.byuid...
Updating group.byname...
Updating group.bygid...
4、重新启动NIS Master服务:
service ypserv restart
service ypbind restart
chkconfig ypbind on
5、设置Master 和Slave数据库同步
NIS可以通过pypush可以直接将master上的数据库同步到Slave节点上。
vim /var/yp/Makefile
NOPUSH=true 改为false
然后在执行命令:
yppush -h pnode3 passwd.byname
yppush -h pnode3 passwd.byuid
1、NIS Slave其他配置和NIS master配置一样,同样按照NIS master的安装步骤配置Slave。唯一不同是Slave 和 Master数据库配置不一样。
2、在Slave上执行/usr/lib64/yp/ypinit -s pnode2命令
[root@pnode3 ~]# /usr/lib64/yp/ypinit -s pnode2
We will need a few minutes to copy the data from pnode2.
Transferring netid.byname...
Trying ypxfrd ... success
Transferring passwd.byuid...
Trying ypxfrd ... success
Transferring services.byservicename...
Trying ypxfrd ... success
Transferring mail.aliases...
Trying ypxfrd ... success
Transferring hosts.byaddr...
Trying ypxfrd ... success
Transferring rpc.byname...
Trying ypxfrd ... success
Transferring protocols.bynumber...
Trying ypxfrd ... success
Transferring group.bygid...
Trying ypxfrd ... success
Transferring hosts.byname...
Trying ypxfrd ... success
Transferring group.byname...
Trying ypxfrd ... success
Transferring ypservers...
Trying ypxfrd ... success
Transferring services.byname...
Trying ypxfrd ... success
Transferring protocols.byname...
Trying ypxfrd ... success
Transferring rpc.bynumber...
Trying ypxfrd ... success
Transferring passwd.byname...
Trying ypxfrd ... success
pnode3's NIS data base has been set up.
If there were warnings, please figure out what went wrong, and fix it.
At this point, make sure that /etc/passwd and /etc/group have
been edited so that when the NIS is activated, the data bases you
have just created will be used, instead of the /etc ASCII files.
3、通过ypcat验证配置的正确性
[root@pnode3 ~]# ypcat -h localhost passwd.byname
jhadmin:$6$qeu52nop$AtdS.6r.KZq33hlkurF5g7.71KMf4newqZ7dG43M5oR9ScfooatRipomjnoDikSDSHUPcJ1sx9ejQ8YNERgBG/:501:501::/home/jhadmin:/bin/bash
lsfadmin:$6$UPRFXdO0$ZXsS8WNMdGGGcjJX5qad3sPAYlrblrGJTkaUOC4/WQ4mkKi/jheMXUQj.RDHpDCueFUrAN8pqDfGrpndovv9d/:500:500::/home/lsfadmin:/bin/bash
执行完之后重启ypserv、ypbind服务。
1、首先配置本地yum源
2、安装ypbind软件包
3、配置NIS 服务器:
运行:authconfig-tui (或authconfig-gtk)
在图形界面中选择”NIS”,在下一步的设置中填写“zlnian”, “”
4、重启ypbind服务。
service ypbind restart
chkconfig ypbind on
1、在NIS Master上启用ypxfrd服务:
service ypxfrd restart
chkcofnig ypxfrd on
2、在Slave上可以使用crontab同步Master数据
[root@pnode3 ~]# cat /etc/crontab
10 * * * * root /usr/lib64/yp/ypxfr -h pnode2 passwd.byname
10 * * * * root /usr/lib64/yp/ypxfr -h pnode2 passwd.byuid
即每小时10min时Slave会从Master同步passwd.byname和passwd.byuid到Slave上,保证数据库统一。
1、关闭Master服务
service ypserv stop
2、在客户机上执行ypwhich可以查看当前NIS server主机名:
[root@pnode4 ~]# ypwhich
pnode3