NIS搭建

日志内容:前几篇工作日志实现了NIS的基本功能,本工作日志对用户目录进行优化,使得NIS用户的增加和删除只在server端操作即可,实现的关键点在于server上用户目录级数的设置技巧;

NIS设置只在server端维护用户数据

NIS用户设置方法:

服务器上是三级目录:

/跟下第一级目录/ocean-peak/用户家目录

客户机:

auto.master设置:

/ocean-peak-rhome                /etc/auto.nfs

auto.nfs设置:

ocean-peak        192.168.0.106:/ocean-peak-rhome/ocean-peak

一、NIS server设置

1、建立用户目录

[root@nis-server1 桌面]# cd /
[root@nis-server1 /]# ls
bin     data  home   lost+found  mnt  proc   sbin     sys  var
boot    dev   lib    media       net  rhome  selinux  tmp
cgroup  etc   lib64  misc        opt  root   srv      usr
[root@nis-server1 /]# mkdir ocean-peak-rhome
[root@nis-server1 /]# cd ocean-peak-rhome/
[root@nis-server1 ocean-peak-rhome]# ls
[root@nis-server1 ocean-peak-rhome]# mkdir ocean-peak
[root@nis-server1 ocean-peak-rhome]# ls
ocean-peak
[root@nis-server1 ocean-peak-rhome]# cd ..

2、建立用户
[root@nis-server1 /]# useradd -u 3001 -d /ocean-peak-rhome/ocean-peak/ocean-peak-user1 ocean-peak-user1
[root@nis-server1 /]# echo root123 |passwd --stdin ocean-peak-user1
更改用户 ocean-peak-user1 的密码 。
passwd: 所有的身份验证令牌已经成功更新。

3、更新数据库
[root@nis-server1 /]# /usr/lib64/yp/ypinit -m

At this point, we have to construct a list of the hosts which will run NIS
servers.  nis-server1 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:  nis-server1
next host to add:  
The current list of NIS servers looks like this:

nis-server1

Is this correct?  [y/n: y]  
We need a few minutes to build the databases...
Building /var/yp/ocean-peak/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/ocean-peak'
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/ocean-peak'

nis-server1 has been set up as a NIS master server.

Now you can run ypinit -s nis-server1 on all slave server.
[root@nis-server1 /]# 


4、建立测试第二个用户(该步骤原本是在完成第一个用户的测试后才开始做的)

[root@nis-server1 /]# useradd -u 3002 -d /ocean-peak-rhome/ocean-peak/ocean-peak-user2 ocean-peak-user2
[root@nis-server1 /]# /usr/lib64/yp/ypinit -m

At this point, we have to construct a list of the hosts which will run NIS
servers.  nis-server1 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:  nis-server1
next host to add:  
The current list of NIS servers looks like this:

nis-server1

Is this correct?  [y/n: y]  
We need a few minutes to build the databases...
Building /var/yp/ocean-peak/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/ocean-peak'
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/ocean-peak'

nis-server1 has been set up as a NIS master server.

Now you can run ypinit -s nis-server1 on all slave server.
[root@nis-server1 /]# 

5、NFS共享用户目录设置

[root@nis-server1 /]# vim /etc/exports 

/rhome 192.168.0.0/24(rw,no_root_squash)

/rhome/nisuser-nfs-1            192.168.0.0/24(rw,no_root_squash)

/rhome/nisuser-nfs-2       192.168.0.0/24(rw,no_root_squash)

/ocean-peak-rhome/ocean-peak 192.168.0.0/24(rw,no_root_squash)

[root@nis-server1 /]# service nfs restart
关闭 NFS 守护进程:                                        [确定]
关闭 NFS mountd:                                          [确定]
关闭 NFS quotas:                                          [确定]
关闭 NFS 服务:                                            [确定]
Shutting down RPC idmapd:                                  [确定]
启动 NFS 服务:                                            [确定]
关掉 NFS 配额:                                            [确定]
启动 NFS mountd:                                          [确定]
启动 NFS 守护进程:                                        [确定]
正在启动 RPC idmapd:                                      [确定]
[root@nis-server1 /]# showmount -e localhost
Export list for localhost:
/ocean-peak-rhome/ocean-peak 192.168.0.0/24
/rhome/nisuser-nfs-2         192.168.0.0/24
/rhome/nisuser-nfs-1         192.168.0.0/24
/rhome                       192.168.0.0/24
[root@nis-server1 /]# 

二、NIS Client设置

1、auto.nfs设置

[root@nis-client1 桌面]# vim /etc/auto.nfs

#server1-nisuser                192.168.0.106:/rhome

nisuser-nfs-1           192.168.0.106:/rhome/nisuser-nfs-1

nisuser-nfs-2           192.168.0.106:/rhome/nisuser-nfs-2

ocean-peak              192.168.0.106:/ocean-peak-rhome/ocean-peak

2、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

#

# 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 the

# same will not be seen as the first read key seen takes

# precedence.

#

#automount 192.168.0.106(nis users)

/rhome /etc/auto.nfs

/ocean-peak-rhome /etc/auto.nfs

#

#

+auto.master

3、重启autofs服务

[root@nis-client1 桌面]# service autofs restart
停止 automount:                                           [确定]
正在启动 automount:                                       [确定]

4、测试autofs是否触发挂载成功
[root@nis-client1 /]# ls
bin     data  home   lost+found  mnt               opt    root     srv  usr
boot    dev   lib    media       net               proc   sbin     sys  var
cgroup  etc   lib64  misc        ocean-peak-rhome  rhome  selinux  tmp
[root@nis-client1 /]# cd ocean-peak-rhome/
[root@nis-client1 ocean-peak-rhome]# ls
[root@nis-client1 ocean-peak-rhome]# cd ocean-peak
[root@nis-client1 ocean-peak]# ls
ocean-peak-user1
[root@nis-client1 ocean-peak]# df -h
Filesystem                                  Size  Used Avail Use% Mounted on
/dev/sda2                                    40G  9.9G   28G  27% /
tmpfs                                       932M  224K  932M   1% /dev/shm
/dev/sda1                                    52G  180M   49G   1% /data
192.168.0.106:/ocean-peak-rhome/ocean-peak   40G  9.9G   28G  27% /ocean-peak-rhome/ocean-peak
[root@nis-client1 ocean-peak]# 

5、ocean-peak-user1用户登陆测试

[ocean-peak-user1@nis-client1 桌面]$ df -h
Filesystem                                  Size  Used Avail Use% Mounted on
/dev/sda2                                    40G  9.9G   28G  27% /
tmpfs                                       932M  236K  932M   1% /dev/shm
/dev/sda1                                    52G  180M   49G   1% /data
192.168.0.106:/ocean-peak-rhome/ocean-peak   40G  9.9G   28G  27% /ocean-peak-rhome/ocean-peak
[ocean-peak-user1@nis-client1 桌面]$ 

6、ocean-peak-user2登陆测试

[ocean-peak-user2@nis-client1 桌面]$ df -h
Filesystem                                  Size  Used Avail Use% Mounted on
/dev/sda2                                    40G  9.9G   28G  27% /
tmpfs                                       932M  460K  931M   1% /dev/shm
/dev/sda1                                    52G  180M   49G   1% /data
192.168.0.106:/ocean-peak-rhome/ocean-peak   40G  9.9G   28G  27% /ocean-peak-rhome/ocean-peak
[ocean-peak-user2@nis-client1 桌面]$ 


你可能感兴趣的:(linux,NIS)