安装NIS所需要的软件包:
ypserv-2.19-3
yp-tools-2.9-0.1
ypbind-1.19-8.el5
portmap-4.0-65.2.2.1
这里通过配置好的yum安装:yum -y install yp*
# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=server.example.com
NISDOMAIN=lanv_11
# vim /etc/yp.conf
domain lanv_11 service 192.168.137.254
---------添加一行
#service ypserv restart
-------------重启ypserv
# cd /var/yp/
[root@server yp]# /usr/lib64/yp/ypinit -m ----------32位系统是[root@server yp]# /usr/lib/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers.
server.example.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>.
---------按ctrl +D 完成配置
next host to add:
server.example.com
next host to add:
The current list of NIS servers looks like this:
server.example.com
Is this correct?
[y/n: y]
y
We need a few minutes to build the databases...
Building /var/yp/lanv_11/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/lanv_11'
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/lanv_11'
server.example.com has been set up as a NIS master server.
Now you can run ypinit -s server.example.com on all slave server.
[root@server yp]# make
gmake[1]: Entering directory `/var/yp/lanv_11'
Updating netid.byname...
gmake[1]: Leaving directory `/var/yp/lanv_11'
[root@server yp]# chkconfig portmap on
[root@server yp]# chkconfig nfs on
[root@server yp]# chkconfig ypserv on
[root@server yp]# chkconfig ypbind on
#mkdir /rhome
#useradd nisuser01 -d /rhome/nisuser01
#passwd nisuser01
#cd /var/yp
#make
每建立一个用户,要到/var/yp
更新即make
NIS的服务器设置好了
NFS服务配置:
nfs服务为linux内核级服务,默认是已经装好的
[root@server /]# vim /etc/exports
/rhome
192.168.137.0/255.255.255.0(rw,sync)
[root@server /]# service portmap restart
[root@server /]# service nfs restart
[root@server /]# showmount -e
Export list for server.example.com:
/rhome
192.168.137.0/255.255.255.0
即NIS+NFS服务器已经做好。
Client 端配置:
1:NIS client
要安装NIS的软件包有以下:
ypbind-1.19-8.el5
yp-tools-2.9-0.1
[root@station100 /]# vim /etc/resolv.conf
search example.com
nameserver 192.168.137.254
[root@station100 /]# system-config-authentication
[root@station100 /]# service ypbind restart
关闭 NIS 服务:
[确定]
关联到 NIS 域:
[确定]
监听 NIS 域服务器。.
[root@station100 /]# ypcat passwd
nisuser01:!!:502:503::/rhome/nisuser/nisuser01:/bin/bash
nagios:$1$QOpN2J5B$6m0JEPGcXGCb7KDGMy/UA/:500:500::/home/nagios:/bin/bash
test:!!:501:502::/home/nisuser/test:/bin/bash
nisuser03:!!:504:505::/rhome/nisuser03:/bin/bash
nisuser02:!!:503:504::/rhome/nisuser2:/bin/bash
2:autofs
#vim /etc/auto.master
/rhome
/etc/auto.nis
--timeout 60
----添加一行
#cp /etc/auto.misc /etc/auto.nisuser
#vim /etc/auto.nis
#cd XXXX
*
-rw,soft,intr
server.example.com:/rhome/&
#service autofs restart
#service portmap restart
[root@station100 /]# su - nisuser02
[nisuser02@station100 ~]$ pwd
/rhome/nisuser2
[nisuser02@station100 ~]$ id
uid=503(nisuser02) gid=504(nisuser02) groups=504(nisuser02)
[root@station100 /]# mount -l
/dev/sda1 on / type ext3 (rw) [/]
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
/dev/hdc on /media/RHEL_5.4 x86_64 DVD type iso9660 (ro,noexec,nosuid,nodev,uid=0) [RHEL/5.4 x86_64 DVD]
192.168.137.254:/rhome/nisuser2 on /rhome/nisuser2 type nfs (rw,soft,intr,addr=192.168.137.254)
[root@station100 /]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@station100 /]# cd /rhome/nisuser2/
bash: cd: /rhome/nisuser2/: 权限不够
[root@station100 /]# ----------客户端本地root无法访问nis用户目录
设定每个用户的home目录大小为500M,当用户使用空间达到400M时将提出警告,但能继续读写,当空间使用达到500M时,将不能继续写入数据。
为了方便测试,我将用户空间上线定为200K,超过200K不能继续写入,超过100K提出警告
[root@server /]# cat /etc/fstab
LABEL=/
/
ext3
defaults
1 1
tmpfs
/dev/shm
tmpfs
defaults
0 0
devpts
/dev/pts
devpts
gid=5,mode=620
0 0
sysfs
/sys
sysfs
defaults
0 0
proc
/proc
proc
defaults
0 0
LABEL=SWAP-sda2
swap
swap
defaults
0 0
/dev/sdb1
/rhome
ext3
defaults,usrquota,grpquota 0 0
配置quota:
[root@server ~]# umount /dev/sdb1
[root@server ~]# mount -a
[root@server ~]# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
/dev/hdc on /media/DPExps500 type iso9660 (ro,noexec,nosuid,nodev,uid=0)
/dev/sdb1 on /rhome type ext3 (rw,usrquota,grpquota)
[root@server ~]# quotacheck -mcugf /rhome/
[root@server ~]# quotaon /rhome/
[root@server ~]# edquota -u nisuser01
[root@server ~]# setquota -u nisuser01 100 200 0 0 /rhome/
[root@server ~]# repquota -a
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits
File limits
User
used
soft
hard
grace
used
soft
hard
grace
----------------------------------------------------------------------
root
--
5652
0
0
3
0
0
nisuser01 --
9
100
200
9
0
0
测试:
[root@server nisuser01]# su - nisuser01
[nisuser01@server ~]$ pwd
[nisuser01@server ~]$ dd if=/dev/zero of=/rhome/nisuser01/testfile bs=1024 count=100
sdb1: warning, user block quota exceeded.
-----空间使用超过100K提出警告,但能正常写入
100+0 records in
100+0 records out
102400 bytes (102 kB) copied, 0.001188 seconds, 86.2 MB/s
[root@server ~]# repquota -a
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits
File limits
User
used
soft
hard
grace
used
soft
hard
grace
----------------------------------------------------------------------
root
--
5652
0
0
3
0
0
nisuser01 +-
110
100
200
6days
10
0
0
[nisuser01@server ~]$ dd if=/dev/zero of=/rhome/nisuser01/testfile bs=1024 count=200
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: 写入 “/rhome/nisuser01/testfile”: ------超出磁盘限额
-----超出限制,写入失败
191+0 records in
190+0 records out
194560 bytes (195 kB) copied, 0.003576 seconds, 54.4 MB/s
[root@server ~]# repquota -a
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits
File limits
User
used
soft
hard
grace
used
soft
hard
grace
----------------------------------------------------------------------
root
--
5652
0
0
3
0
0
nisuser01 +-
200
100
200
6days
10
0
0
本文出自 “广园A班-林凡龙” 博客,谢绝转载!