实验环境
 NIS域名为crazylinux
NIS主服务器IP100.0.0.1,主机名master.crazylinux 该服务器下面有user01账号
NIS从服务器IP100.0.0.2,主机名 slave.crazylinux
NIS客户机IP100.0.0.3, 主机名 client.crazylinux
二、实验的配置
在配置服务器之前,我们首先确保ip,主机名信息。(过程略。。。)
首先配置NIS主服务器:
1.检查服务器是否安装了下列包:portmapypservypbindyp-tools
2.建立NIS的域名
nis服务自动设置nis
3.设置ypserv服务的配置文件
[root@crazylinux /]# vi /etc/ypserv.conf
dns : no
# nis服务器在使用时不需要dns系统,如需要在/etc/hosts中设置即可
files: 30
#
这说的是有多少数据库档案(database file)会被先读进高速缓存当中的意思,不需跟改
trusted_master: your.master.servers.name
xfr_check_port: yes
#
上面这两个都仅与 Master + Slave 架构有关的设定值,一般来说,
#
只有一部主要 NIS Server 的系统中是用不到这两个设定值的!
#
如果你的 NIS slave 的架构,那么需要指定一部 master 做为数据库内容的
#
同步时候的主机,那就是 trusted_master 的设定内容啰!
#
如果没有 master/slave 架构时,那就不需要 trusted_master 这个设定了!
#
至于 xfr_check_port 则是指定 master slave 是否都要以 < 1024 
#
以下的 port 来进行沟通的讯息!通常预设就是 yes ,不需要更动他!
# &lt;
主机名称/IP>:<网域名称>:<数据库类别>:<安全性>
#
这个是这个档案里面最重要的部分了!主要在设定安全性的方面,
#
可以设定多行,而是否能够通过的规则是『一行一行检查』的方式!
#
所以这里的设定应该是:先开放要开放的网域,然后全部都关闭!
#
先谈一谈各个相关的项目:
# 1.
主机名称/IP:这里可以这样设定:192.168.1.0/255.255.255.0
# 2.
网域名称:通常都设定成为 * 即可!
# 3.
数据库类别:可以使用 * 来表示所有的数据库!
# 4.
安全性:主要有三种参数:
# none
:无论如何就是可以无条件进入本机;
# port
:仅允许 < 1024 以下的 port 进入;
# deny
:无论如何就是关闭不让人家登入主机!
#
由于我是允许 127.0.0.0/255.0.0.0 以及 100.0.0.0/255.0.0.0 进入,
#
其它的都关闭!所以我可以这样设定:
127.0.0.0/255.0.0.0   :  *  :  *  :  none
100.0.0.0/255.0.0.0 :  *  :  *  :  none
*                          :  *  :  *  :  deny
[root@localhost ~]# cat /var/yp/securenets 需要自己建立
host 127.0.0.1
255.0.0.0 100.0.0.0
4.设置/etc/hosts与建立可信任群组/etc/netgroup
[root@localhost ~]# touch /etc/netgroup
[root@localhost ~]# vi /etc/hosts
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
100.0.0.1 master.crazylinux
100.0.0.2 slave.crazylinux
100.0.0.3 client.crazylinux
这个/etc/netgroup 文件可以记录在我们网络里面被信任的群,这个档案的内容当中,每一行都有三个字段,分别以逗号『,』隔开,意义为:
&lt;host>,<user>,<domain>
主机,使用者账号,领域名称
事实上,如果这个文件是空的的话,那么代表着全部的主机、账号与域名称都接受的意思,因为我们已经在/etc/ypserv.conf 里头设定好了关于安全的项目了,所以这个文件只要建立即可(本来是不存在的!)
5.初始化NIS数据库:
[root@localhost ~]# useradd user01
[root@localhost ~]# passwd user01
Changing password for user user01.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# /usr/lib/yp/ypinit –m
At this point, we have to construct a list of the hosts which will run NIS
servers. master.crazylinux 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>. #ctrl+D回车
next host to add: master.crazylinux
next host to add:
The current list of NIS servers looks like this:
master.crazylinux
Is this correct? [y/n: y] y
6.启动相关服务:
[root@localhost ~]# service portmap restart
停止 portmap[确定]
启动 portmap[确定]
[root@localhost ~]# service ypserv restart
停止 YP 服务器的服务:[失败]
启动 YP 服务器的服务:[确定]
[root@localhost ~]# service yppasswd restart
yppasswd: 未被识别的服务
[root@localhost ~]# service yppasswdd restart
停止 YP 口令服务:[失败]
启动 YP 口令服务:[确定]
[root@localhost ~]# chkconfig --level 35 portmap on
[root@localhost ~]# chkconfig --level 35 ypserv on
[root@localhost ~]# chkconfig --level 35 yppasswdd on
同时检查进程是否正常运行以及信息是否正确:ps –aux | grep yp
[root@localhost ~]# tail /var/log/message
7.与slave server相关设置
[root@crazylinux /]# vi /var/yp/Makefile
NOPUSH=true 大约在23行附近 修改成
NOPUSH=false 使主服务器给辅助服务器提供同步
[root@localhost ~]# cat /var/yp/ypservers 该成下面2行,可以将所有的nis slave都添加到这里
master.crazylinux
slave.crazylinux
[root@localhost ~]# service ypxfrd restart 这个服务是让slave主动连接上ypxfrd来更新数据库
停止 YP 映射图服务器:[失败]
启动 YP 映射图服务器:[确定]
注:如直接想将master的数据库直接传给slave的话可以用下面的命令
[root@crazylinux]# yppush -h slave.crazylinux passwd.*
 
(接2)