安裝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