CentOS系统NIS服务器安装方法
NIS(网络信息服务)是一种轻量级的集中用户管理方案,常用于企业内部网络。配置过程并不复杂,关键在于准确设置服务端与客户端的几个要点。以下逐步说明,首先介绍服务端的搭建方法。 第一步 安装 NIS 服务器 安装软件包是常规操作,在 CentOS 6/7 下使用 yum 命令即可完成: [root@s
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. 设置 NIS 域名
编辑 /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. 初始化 NIS 数据库
执行 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$
出现该提示说明认证已通过,虽然 home 目录尚未自动创建(需单独处理),但 NIS 用户认证环节已成功运行。至此,整个配置流程结束,后续可结合 autofs 或手动创建 home 目录来完善体验。
