3. 修改yppasswdd文件:
```
# vi /etc/sysconfig/yppasswdd
17 YPPASSWDD_ARGS="--port 1012"
```
4. 启动服务,设定开机启动:
```
# service ypserv start
# chkconfig ypserv on
# service yppasswdd start
# chkconfig yppasswdd on
```
5. 查看服务:
```
# rpcinfo -u localhost ypserv
program 100004 version 1 ready and waiting
program 100004 version 2 ready and waiting
```
>说明:出现这个就算成功了。
6. 创建账户:
```
# useradd -u 1001 test001
# useradd -u 1002 test002
# echo 123456 | passwd --stdin test001
# echo 123456 | passwd --stdin test002
```
>这样就创建好了test001和test002,密码一致,-u代表uid。
7. 将创建的账户与密码转换成数据库:
```
# /usr/lib64/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers. server.nis.com 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>.
next host to add: server.nis.com
next host to add: #按ctrl+D
The current list of NIS servers looks like this:
server.nis.com
Is this correct? [y/n: y] y #输入y
We need a few minutes to build the databases...
Building /var/yp/nis.com/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/nis.com'
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]: Leaving directory `/var/yp/nis.com'
server.nis.com has been set up as a NIS master server.
Now you can run ypinit -s server.nis.com on all slave server.
```
>注意:如果用户密码发生过变化,就需要重新制作数据库,重新启动ypserv 以及yppasswdd。
8. 到此NIS服务端设置完毕。
# 四、NIS客户端安装配置
1. 安装NIS客户端软件:
```
# yum install -y ypbind yp-tools setuptool
```
>说明:setuptool是命令行图形化配置工具
2. 设置yp.conf主配置文件:
```
# vi /etc/yp.conf
domain nis.com server server.nis.com
```
>格式为:domain 你的NIS Server和Client所在的域名 server 你的NIS服务器的IP地址,添加在最后就可以了。
完成后会自动重启rpbind服务,正常如下:
关闭 NIS 服务: [确定]
启动 NIS 服务: [确定]
绑定 NIS 服务:. [确定]
4. 启动服务,并加入开机启动:
```
# service ypbind start
# chkconfig ypbind on
```
5. 测试客户端的连接:
```
# yptest
Test 1: domainname
Configured domainname is "nis.com"
Test 2: ypbind
Used NIS server: server.nis.com
Test 3: yp_match
WARNING: No such key in map (Map passwd.byname, key nobody)
Test 4: yp_first
test001 test001:$6$T8cLZP10$yrLCwB9Yn2rStNVP.YS.v7kgKcNowfJvIFq0PianblosSej9mmw0l7Y24WTQQNZsOFS0ZEmZB1tbaSHJqa4q21:1001:1001::/home/test001:/bin/bash
Test 5: yp_next
test002 test002:$6$Z/pvpzPa$PKpxiMOBSh3zkDlQjabsB4jaxHXI1H4yDMua4aBF5ERGa5blK0FMTL0mQU0tk1qtevjHmKuRLsPRepd/is0hh1:1002:1002::/home/test002:/bin/bash
Test 9: yp_all
test001 test001:$6$T8cLZP10$yrLCwB9Yn2rStNVP.YS.v7kgKcNowfJvIFq0PianblosSej9mmw0l7Y24WTQQNZsOFS0ZEmZB1tbaSHJqa4q21:1001:1001::/home/test001:/bin/bash
test002 test002:$6$Z/pvpzPa$PKpxiMOBSh3zkDlQjabsB4jaxHXI1H4yDMua4aBF5ERGa5blK0FMTL0mQU0tk1qtevjHmKuRLsPRepd/is0hh1:1002:1002::/home/test002:/bin/bash
1 tests failed
```
>会看到测试信息,分辨出是否出了问题 Test 3 Wraing : No such key in map(Map passwd.byname , key nobody)
6. 检查数据库:
```
# ypwhich -x
Use "ethers" for map "ethers.byname"
Use "aliases" for map "mail.aliases"
Use "services" for map "services.byname"
Use "protocols" for map "protocols.bynumber"
Use "hosts" for map "hosts.byname"
Use "networks" for map "networks.byaddr"
Use "group" for map "group.byname"
Use "passwd" for map "passwd.byname"
```
>说明正常
7. 测试客户端登录,如图:
![]()
出现:Could not chdir to home directory /home/test001: No such file or directory这个是正常的,因为我们知道所有用户的信息都是保存在NIS服务器端的,因此找不到用户的目录,这里的解决方法是要用到NFS , 即将/home目录共享,在NIS客户端只需要挂载即可,所以我们将NFS安装放在后面,主要就是说明这个问题的。
8. 到此NIS服务端和客户端安装配置测试完成,接下来安装nfs解决上面出现扎不到用户家目录的问题。