在RHEL5中搭建NIS+autofs服务

1、主机名及IP地址

 角色名称
主机名
IP地址
OS 版本
NIS Server(master)
station100.example.com
192.168.0.100
 
 
RHEL5.8
NIS Server(slave)
station101.example.com
192.168.0.101
Client1
station200.example.com
192.168.0.200
Client2
station201.example.com
192.168.0.201

2、NIS Server主服务器master软件安装与配置

  • 软件安装
  1. yp-tools-2.9-2.el5  
  2. ypbind-1.19-12.el5_6.1  
  3. ypserv-2.19-9.el5  
  4. portmap-4.0-65.2.2.1 
  • portmap服务启动并设定为开机启动
  • NIS服务没有固定的端口号,依赖于portmap服务
  1. # /etc/init.d/portmap start  
  2. # netstat -tl |grep sunrpc  
  3. tcp   0   0   *:sunrpc     *:*          LISTEN     
  4. # chkconfig portmap on  
  5. # chkconfig --list|grep portmap  
  6. portmap  0:off  1:off  2:on  3:on  4:on  5:on 6:off  
  •  配置和启动time服务
    1. # cat /etc/xinetd.d/time-stream |grep disable  
    2.     disable     = no 
    3. # cat /etc/xinetd.d/time-dgram |grep disable  
    4.     disable     = no 
    5. # /etc/init.d/xinetd restart  
    6. # chkconfig xinetd on  
    7. # netstat -tul|grep time  
    8. tcp        0      0 *:time    *:*    LISTEN        
    9. udp        0      0 *:time    *:*   
  • 创建NISDOMAIN
  1. # nisdomainname example.com  
  2. # cat /etc/sysconfig/network  
  3. NETWORKING=yes 
  4. NETWORKING_IPV6=no 
  5. HOSTNAME=station100.example.com  
  6. GATEWAY=192.168.0.254  
  7. NISDOMAIN=example.com 
  • 主配置文件的配置
  1. # cat /etc/ypserv.conf |grep -vE '^#|^$'  
  2. dns: no  
  3. files: 30  
  4. slp: no  
  5. slp_timeout: 3600  
  6. xfr_check_port: yes  
  7. #允许本地任何域的成员访问nis共享的任意数据库
  8. 127.0.0.0/255.255.255.0   : * : * : port  
  9. #允许192.168.0.0/24网段的任意域的任意成员访问nis共享的任意数据库
  10. 192.168.0.0/255.255.255.0     : * : * : port  
  11. #拒绝其他所有网段访问任意数据库
  12. *             : * : * : deny     
  •  创建网络信任群组

由于前面主配置文件已经配置了访问的范围,所以不在此处继续配置,只需要创建文件即可

  1. # touch /etc/netgroup 
  • 配置共享的数据库

把不需要共享的给注释掉

  1. # cat /var/yp/Makefile |grep '^all'  
  2. all:  passwd group shadow hosts rpc services #netid protocols mail \ 
  • 启动ypserv服务
  1. # /etc/init.d/ypserv start  
  2. Starting YP server services:   
  3. service:                                [  OK  ]  
  4. # /etc/init.d/yppasswdd start  
  5. Starting YP passwd service:                                [  OK  ]  
  6. #rpcinfo -u localhost ypserv
    program 100004 version 1 ready and waiting
    program 100004 version 2 ready and waiting
    # rpcinfo -u localhost yppasswd
    program 100009 version 1 ready and waiting
  7. #chkconfig ypserv on  
  8. #chkconfig yppasswdd on 
  • 制作数据库发布数据
  1. #/usr/lib64/yp/ypinit -m  
  2.  
  3. At this point, we have to construct a list of the hosts which will run NIS  
  4. servers.  station100.example.com is in the list of NIS server hosts.  Please continue to add  
  5. the names for the other hosts, one per line.  When you are done with the  
  6. list, type a <control D>.  <=此处按control+d
  7.     next host to add:  station100.example.com  
  8.     next host to add:    
  9. The current list of NIS servers looks like this:  
  10.  
  11. station100.example.com  
  12.  
  13. Is this correct?  [y/n: y]    
  14. We need a few minutes to build the databases...  
  15. Building /var/yp/example.com/ypservers...  
  16. Running /var/yp/Makefile...  
  17. gmake[1]: Entering directory `/var/yp/example.com'  
  18. Updating passwd.byname...  
  19. Updating passwd.byuid...  
  20. Updating group.byname...  
  21. Updating group.bygid...  
  22. Updating shadow.byname... Ignored -> merged with passwd  
  23. Updating hosts.byname...  
  24. Updating hosts.byaddr...  
  25. Updating rpc.byname...  
  26. Updating rpc.bynumber...  
  27. Updating services.byname...  
  28. Updating services.byservicename...  
  29. gmake[1]: Leaving directory `/var/yp/example.com'  
  30.  
  31. station100.example.com has been set up as a NIS master server.  
  32.  
  33. Now you can run ypinit -s station100.example.com on all slave server. 

3、客户端软件安装与配置

  • 客户端软件安装
  1. yp-tools-2.9-2.el5  
  2. ypbind-1.19-12.el5_6.1  
  3. portmap-4.0-65.2.2.1  
  • portmap服务启动并设定为开机启动
  1. # /etc/init.d/portmap start  
  2. # netstat -tl |grep sunrpc  
  3. tcp   0   0   *:sunrpc     *:*          LISTEN     
  4. # chkconfig portmap on  
  5. # chkconfig --list|grep portmap  
  6. portmap  0:off  1:off  2:on  3:on  4:on  5:on 6:off  
  • 创建NISDOMAIN
  1. # nisdomainname example.com  
  2. # cat /etc/sysconfig/network  
  3. NETWORKING=yes 
  4. NETWORKING_IPV6=no 
  5. HOSTNAME=station100.example.com  
  6. GATEWAY=192.168.0.254  
  7. NISDOMAIN=example.com 
  • 配置/etc/hosts文件,将NIS Server的对应关系加进去
  1. # cat /etc/hosts  
  2. # Do not remove the following line, or various programs  
  3. # that require network functionality will fail.  
  4. 127.0.0.1   localhost.localdomain localhost  
  5. ::1     localhost6.localdomain6 localhost6  
  6. 192.168.0.100   station100.example.com station100  
  7. 192.168.0.101   station101.example.com station101 
  • 客户端配置
  1. [root@station200 ~]# cat /etc/yp.conf |grep -v '^#'
    domain example.com
    ypserver station100.example.com
  2. [root@station200 ~]# /etc/init.d/ypbind start  
  3. Binding to the NIS domain:   
  4. Listening for an NIS domain server.  
  5. [root@station200 ~]# chkconfig ypbind on  
  6. [root@station200 ~]# rpcinfo -p localhost|grep ypbind  
  7.     100007    2   udp    619  ypbind  
  8.     100007    1   udp    619  ypbind  
  9.     100007    2   tcp    622  ypbind  
  10.     100007    1   tcp    622  ypbind 
  •  修改密码验证方式
  1. 在passwd文件最后一行添加如下信息  
  2. [root@station200 ~]# tail -n 1 -f /etc/passwd  
  3. +:::::: 
  • nsswitch文件配置更改
  1. [root@station200 ~]# setup  

在RHEL5中搭建NIS+autofs服务_RHEL 在RHEL5中搭建NIS+autofs服务_RHEL_02 在RHEL5中搭建NIS+autofs服务_RHEL_03

  •  重启ypbind进程
  1. # service ypbind restart  
  2. Shutting down NIS services:                                [  OK  ]  
  3. Binding to the NIS domain:                                 [  OK  ]  
  4. Listening for an NIS domain server.. 
  • 客户端测试及查询
  1. [root@station200 ~]# yptest  
  2. Test 1: domainname  
  3. Configured domainname is "example.com"  
  4.  
  5. Test 2: ypbind  
  6. Used NIS server: station100.example.com  
  7.   
  8. Test 3: yp_match  
  9. WARNING: No such key in map (Map passwd.byname, key nobody)
  10.  
  11. ......   
  12.  
  13. Test 9: yp_all  
  14. 1 tests failed  
  15. #只有一个nobody用户测试失败,其它都正确是测试通过 
  • ypwhich命令
  1. #ypwhich显示nis server名称  
  2. # ypwhich  
  3. station100.example.com  
  4. #-x查询服务端共享了那些数据库  
  5. # ypwhich -x  
  6. Use "ethers"    for map "ethers.byname"  
  7. Use "aliases"   for map "mail.aliases"  
  8. Use "services"  for map "services.byname"  
  9. Use "protocols" for map "protocols.bynumber"  
  10. Use "hosts" for map "hosts.byname"  
  11. Use "networks"  for map "networks.byaddr"  
  12. Use "group" for map "group.byname"  
  13. Use "passwd"    for map "passwd.byname" 
  • ypcat命令
  1. ypcat后跟数据库名称显示该数据库信息  
  2. [root@station200 ~]# ypcat hosts  
  3. 192.168.0.100   station100.example.com station100  
  4. 192.168.0.202   station202.example.com station202  
  5. 192.168.0.201   station201.example.com station201  
  6. 192.168.0.101   station101.example.com station101  
  7. 192.168.0.100   station100.example.com station100  
  8. 192.168.0.203   station203.example.com station203  
  9. 127.0.0.1   localhost.localdomain localhost 

 4、Autofs配置

以上就完成了nis的配置,此时在客户端切换用户时会发现主目录无法挂载,最好使用autofs来实现自动挂载。

  • autofs服务端的配置
    1. [root@station100 ~]# cat /etc/exports  
    2. /home   192.168.0.0/255.255.255.0(rw,sync) 
    3. [root@station100 ~]# exportfs -rv 
    4. exporting 192.168.0.0/255.255.255.0:/home 
    5. [root@station100 ~]# /etc/init.d/nfs start 
    6. [root@station100 ~]# chkconfig nfs on 
  • autofs客户端的配置
  1. [root@station201 ~]# cat  /etc/auto.master |grep home 
  2. /home   /etc/auto.home 
  3. [root@station200 ~]# cat /etc/auto.home  
  4. *   -rw,soft,intr   192.168.0.100:/home/& 
  5. [root@station201 ~]# chkconfig autofs on 
  6. [root@station201 ~]# service autofs restart 
  7. Stopping automount:                                        [  OK  ] 
  8. Starting automount:                                        [  OK  ]