NIS(网络信息服务)在企业内部网络中,是一种轻量级的集中用户管理方案。整个配置过程并不复杂,关键在于正确设置服务端和客户端的几个要点。下面我们将逐步进行,首先来看服务端的搭建方法。
第一步 安装 NIS 服务器
安装软件包是常规操作,在 CentOS 6/7 下直接使用 yum 即可完成:
[root@s ~]# yum install ypserv yp-tools rpcbind
安装完成后,操作非常简单。以下是本次实验的环境信息:
- NIS 服务器 IP:
192.168.100.254,主机名:www.e2fsck.org - NIS 客户端 IP:
192.168.100.240,主机名:site.e2fsck.org
第二步 配置 NIS 服务器
1. 设置 NISDOMAIN
编辑 /etc/sysconfig/network 文件,添加 NIS 域名。需要注意的是,这里的域名建议与主机名保持一致:
[root@s ~]# vi /etc/sysconfig/network
NISDOMAIN=e2fsck # 这里的名字要和 HOSTNAME 一样
2. 启动 NIS 服务
先启动 RPC 绑定服务(CentOS 5 为 portmap),再启动 ypserv:
[root@s ~]# service rpcbind start # CentOS 5 请使用 service portmap start
[root@s ~]# service ypserv start
3. 限制 IP 访问范围
出于安全考虑,需要限定哪些客户端能够访问 NIS 服务。编辑 /var/yp/securenets 文件:
[root@s ~]# vi /var/yp/securenets
255.255.255.255 127.0.0.1
255.255.255.0 192.168.100.0
4. 创建测试用户
先创建一个用于验证的账户:
[root@s ~]# useradd e2fsck
[root@s ~]# passwd e2fsck
5. 初始化数据库
运行 ypinit -m 命令初始化 NIS 数据库。过程中会提示添加其他 NIS 服务器(如果存在多台),这里我们只使用一台主服务器,因此直接按 Ctrl+D 结束即可:
[root@s ~]# /usr/lib/yp/ypinit -m
At this point, we ha ve to construct a list of the hosts which will run NIS
servers. www.e2fsck.org 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: www.e2fsck.org
next host to add: # 此处 Ctrl + D,从服务器的地址我们不需要
The current list of NIS servers looks like this:
www.e2fsck.org
Is this correct? [y/n: y] y
We need a few minutes to build the databases...
Building /var/yp/e2fsck/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/e2fsck'
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]: Lea ving directory `/var/yp/e2fsck'
www.e2fsck.org has been set up as a NIS master server.
Now you can run ypinit -s www.e2fsck.org on all sla ve server.
6. 启动 yppasswdd 服务
该服务允许客户端修改自己的密码:
[root@s ~]# service yppasswdd start
第三步 客户端配置
1. 安装客户端软件包
客户端需要安装 ypbind 和 rpcbind:
[root@c2 ~]# yum install ypbind rpcbind
2. 图形化认证配置
借助 authconfig-tui 工具进行设置,勾选 Use NIS,下一步后填写 Domain 为 e2fsck,Server 为 192.168.100.254:
[root@c2 ~]# authconfig-tui
┌───────┤ Authentication Configuration ├───────|
│ User Information Authentication │
│ [ ] Cache Information [*] Use MD5 Passwords │
│ [ ] Use Hesiod [*] Use Shadow Passwords │
│ [ ] Use LDAP [ ] Use LDAP Authentication │
│ [*] Use NIS [ ] Use Kerberos │
│ [ ] Use Winbind [ ] Use SMB Authentication │
│ [ ] Use Winbind Authentication │
│ [ ] Local authorization is sufficient │
│ │
│ │ Cancel │ │ Next │ │
│ │
└─────────────────────────────────
3. SSH 登录测试
使用之前创建的 e2fsck 账户通过 SSH 登录客户端(192.168.100.240),验证认证是否成功:
login as: e2fsck
e2fsck@www.e2fsck.org's password:
Could not chdir to home directory /home/e2fsck: No such file or directory
-bash-3.2$
出现该提示说明认证已经通过,虽然家目录尚未自动创建(需要额外处理),但 NIS 用户认证这一步已经成功运行。整个配置流程到此结束,后续可以结合 autofs 或手动创建家目录来进一步完善使用体验。
