(5). 为服务器配置NFS服务,在/share中创建并共享soft目录,要求只有技术部的测试机对soft有读写的权限,其它所有主机都只有读取权限。配置技术部的测试机的自动挂载器,每次访问/mnt/soft目录时能自动看到服务器soft目录的内容。
服务器端1.安装所需软件包
[root@localhost ~]# yum install rpcbind nfs-utils -y
2.修改nfs主配置文件
[root@localhost share]# vim /etc/exports[root@localhost share]# cat /etc/exports/share/soft 192.168.30.0/24(rw) *(ro)
3.重启服务
[root@localhost share]# service rpcbind restart[root@localhost share]# service nfs restart
#设置开机自启动
[root@localhost share]# chkconfig nfs on[root@localhost share]# chkconfig rpcbind on
4.创建共享目录
[root@localhost /]# cd /share/[root@localhost share]# mkdir soft
#新建标志性文件,并给共享目录的其他用户加上w(写)权限
[root@localhost share]# touch soft/abc[root@localhost share]# chmod o+w soft/[root@localhost share]# lldrwxr-xrwx 2 root root 4096 Aug 3 15:40 soft客户机1.安装所需软件包
[root@localhost /]# yum install rpcbind nfs-utils autofs -y
2.启动rpcbind服务,常看服务器共享目录信息
[root@localhost /]# service rpcbind restart[root@localhost /]# showmount -e 192.168.0.8Export list for 192.168.0.8:/share/soft (everyone)
3.修改autofs主配置文件
[root@localhost /]# vim /etc/auto.master[root@localhost /]# grep "soft" /etc/auto.master/mnt /etc/auto.soft #定义神奇目录
#配置自动挂载点
[root@localhost /]# cp -a /etc/auto.misc /etc/auto.soft[root@localhost /]# vim /etc/auto.soft[root@localhost /]# grep share /etc/auto.softsoft -rw,soft,intr 192.168.0.8:/share/soft
4.重启服务
[root@localhost /]# service rpcbind restartStopping rpcbind: [ OK ]Starting rpcbind: [ OK ]
[root@localhost /]# service autofs restartStopping automount: [ OK ]Starting automount: [ OK ]
#设置开机启动
[root@localhost /]# chkconfig rpcbind on[root@localhost /]# chkconfig autofs on
5.测试nfs共享目录的自动挂载
[root@localhost /]# ls /mnt[root@localhost /]# ls /mnt/softabc
#挂载成功,看能否写入
[root@localhost /]# touch /mnt/soft/123[root@localhost /]# ls /mnt/soft/123 abc #写入成功
6. 配置文件服务器的/share中,市场部和财务部每位员工可存50M文件,技术部每位员工可存100M文件
1.重新挂载/share目录使其支持磁盘配额
[root@localhost /]# mount -o remount,usrquota,grpquota /share/
2.通过quotacheck命令生成配置文件
[root@localhost /]# quotacheck -ugv /dev/sdb1[root@localhost /]# ll /share/total 36-rw------- 1 root root 8192 Aug 3 16:23 aquota.group-rw------- 1 root root 8192 Aug 3 16:23 aquota.user
3.开启quota(磁盘配额)
[root@localhost /]# quotaon -ugv /share//dev/sdb1 [/share]: group quotas turned on/dev/sdb1 [/share]: user quotas turned on
4.配置每个用户的磁盘配额
[root@localhost /]# edquota -u sc1Disk quotas for user sc1 (uid 501):Filesystem blocks soft hard inodes soft hard/dev/sdb1 4 40000 50000 1 0 0
#通过-p选项复制
[root@localhost /]# edquota -p sc1 sc2[root@localhost /]# edquota -p sc1 scjl[root@localhost /]# edquota -p sc1 cwjl[root@localhost /]# edquota -p sc1 cw1[root@localhost /]# edquota -p sc1 cw2
[root@localhost /]# edquota -u jsjlDisk quotas for user jsjl (uid 506):Filesystem blocks soft hard inodes soft hard/dev/sdb1 4 90000 100000 1 0 0[root@localhost /]# edquota -p jsjl js1[root@localhost /]# edquota -p jsjl js2
5.查看每个用户的配额情况
[root@localhost /]# repquota -savu
Block limits File limits
User used soft hard grace used soft hard grace----------------------------------------------------------------------root -- 24 0 0 17 0 0 nfsnobody -- 0 0 0 1 0 0 scjl -- 4 40000 50000 1 0 0 sc1 -- 4 40000 50000 1 0 0 sc2 -- 4 40000 50000 1 0 0 cwjl -- 4 40000 50000 1 0 0 cw1 -- 4 40000 50000 1 0 0 cw2 -- 4 40000 50000 1 0 0 jsjl -- 4 90000 100000 1 0 0 js1 -- 4 90000 100000 1 0 0 js2 -- 4 90000 100000 1 0 0 6.开机启动quota[root@localhost share]# vim /etc/rc.local[root@localhost share]# tail -2 /etc/rc.localquotaoff -avugquotaon -avug
7.测试#使用su命令切换到其他用户,进入到/share目录的任意位置使用dd命令写入指定大小的文件
[root@localhost ~]# su - cwjl[cwjl@localhost ~]$ cd /share/soft/[cwjl@localhost soft]$ dd if=/dev/zero of=cwjl bs=1M count=200
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.dd: writing `cwjl': Disk quota exceeded49+0 records in48+0 records out51191808 bytes (51 MB) copied, 0.0931238 s, 550 MB/s[cwjl@localhost soft]$ ll -h cwjl-rw-rw-r-- 1 cwjl cwjl 49M Aug 4 22:05 cwjl通过上面的结果可知,用户cwjl想写入200的空文件却只能写入50M,因为磁盘配额限制系统报错而不能继续写入。