您的位置:首页 > 其它

NIS+NFS+Authconfig+Autofs实现自动挂载NIS用户宿主目录!

2014-04-08 15:05 513 查看
NIS服务配置请参考:NIS+NFS+Authconfig+Autofs实现自动挂载NIS用户宿主目录!
NFS及Autofs配置参考:RHCE课程--NFS服务 网络文件系统搭建攻略!

NFS和NIS的配置问题请参考上面的Blog,现在直接切入正题!
我们搭建完NIS服务器后可以为客户端提供统一的帐号和其它网络配置信息,但是如果我们使用NIS帐号登录客户端,系统会提示bash提示符,而没有其它环境信息提示:

Could not chdir to home directory /home/nisuser1: No such file or directory
-bash-3.2$
这是因为NIS帐号的主目录存放在NIS服务器上,而客户端虽然通过NIS服务器进行验证成功,但是客户端本地没有存放该用户的主目录信息,当根据NIS数据库提供的信息寻找用户主目录时将会提示错误哈~
一、在NIS服务器上共享NIS用户主目录

1.创建用户及NIS用户主目录

建议在NIS服务器上建立独立的目录存放NIS帐号信息,如果保持默认设置则客户端挂载NIS主目录到/home目录时会覆盖原有用户主目录而导致其他异常错误;我们现在建立/nishome存放NIS用户的主目录并使用useradd -d将NIS帐号的主目录指向/nishome,如果己有帐号可以使用usermod -d变更主目录。
[root@master /]# mkdir nishome
[root@master /]# mkdir nishome/nisuser1
[root@master /]# usermod -d /nishome/nisuser1/ nisuser1
[root@master /]# useradd -d /nishome/nisuser2 nisuser2
[root@master /]# ls nishome/
nisuser1 nisuser2
2.重新生成NIS数据库并重启ypserv和yppasswd服务

# /usr/lib/yp/ypinit -m# service ypserv restart# service yppasswdd restart

3.共享用户主目录
# vim /etc/exports
/nishome/nisuser1 *(rw)
/nishome/nisuser2 *(rw)
4.重启NFS服务

[root@master /]# service nfs restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
Stopping RPC idmapd: [ OK ]
Starting RPC idmapd: [ OK ]
二、客户端配置NIS验证及Autofs

1.检测主/从NIS服务器相应服务是否正常开启
[root@client01 ~]# rpcinfo -p master.abcnis
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 952 status
100024 1 tcp 955 status
100004 2 udp 682 ypserv
100004 1 udp 682 ypserv
100004 2 tcp 685 ypserv
100004 1 tcp 685 ypserv
100009 1 udp 699 yppasswdd
100011 1 udp 781 rquotad
100011 2 udp 781 rquotad
100011 1 tcp 784 rquotad
100011 2 tcp 784 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 49642 nlockmgr
100021 3 udp 49642 nlockmgr
100021 4 udp 49642 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 tcp 57392 nlockmgr
100021 3 tcp 57392 nlockmgr
100021 4 tcp 57392 nlockmgr
100005 1 udp 796 mountd
100005 1 tcp 799 mountd
100005 2 udp 796 mountd
100005 2 tcp 799 mountd
100005 3 udp 796 mountd
100005 3 tcp 799 mountd
2.Authconfig启用NIS验证
执行setup(或者authconfig-tui命令)










3.修改Autofs主配置文件

vim /etc/auto.master
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#/misc   /etc/auto.misc
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
/net    -hosts
/nishome        /etc/auto.nishome
#nishome是客户端要挂载的目录;auto.nishome是Autofs客户端配置文件;
# Include central master map if it can be found using
# nsswitch sources.
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are th
# same will not be seen as the first read key seen takes
# precedence.
+auto.master
4.创建NIS自动挂载配置文件

[root@client01 ~]# touch /etc/auto.nishome
[root@client01 ~]# vim /etc/auto.nishome
* -fstype=nfs master.abcnis:/nishome/&
# Autofs挂载目录支持通配符 * ;
# 网络路径中的用户名使用 & 表示;
5.重启Autofs服务
# service autofs restart
可以看到重启Autofs服务后客户端自动创建了/nishome目录!

三、客户端测试
注意如果使用su命令在NIS客户端切换到NIS用户时,在第一次可能会报无法定位到用户家目录的错误,没有关系,退出第二次再使用时就会正常。
[root@client01 ~]# su nisuser1
[nisuser1@client01 root]$ pwd
/root
[nisuser1@client01 root]$ cd
[nisuser1@client01 nisuser1]$ pwd
/nishome/nisuser1
[nisuser1@client01 nisuser1]$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息