###nfs
nfs:network file system
RPC:远程过程调用
1.nfs安装
centos5.x中,portmap就是指centos6.x中的rpcbind
[root@s01 tech]# yum install rpcbind.x86_64 nfs-utils.x86_64
2.检查RPC的注册状况
rpcinfo -p [ip|hostname]
rpcinfo -t|-u ip|hostname 程序名称
-p:针对某个IP或者主机名显示出全部的端口和程序信息。
-t/-u:针[root@Cent64 raid]# rpcinfo -t 10.10.54.64 mountd
program 100005 version 1 ready and waiting
program 100005 version 2 ready and waiting
program 100005 version 3 ready and waiting
对某主机的某个程序检查其tcp/udp数据包所在的软件版本。服务器端vim
#例子
1.共享/stu1目录,容许全部的客户端访问该目录,但只具备只读权限。
2.共享/stu2目录,容许10.10.54.0/24网段客户端访问,而且对该目录具备只读权限。
3.共享/stu3目录,10.10.54.0/24网段的客户端具备只读权限,而且将root用户映射成匿名用户。
4.共享/stu4目录,全部人具备读写权限,但当用户使用该共享目录的时候将账号映射为匿名用户,指定匿名用户的uid/gid为600。
客户端
1.使用showmount命令查看nfs服务器发布的共享目录
2.挂载服务器端的/stu1目录到本地的/mnt/stu1目录
3.卸载/mnt/stu1目录
4.自动挂载nfs服务器上/stu4到本地的/mnt/stu4目录
环境:
服务器:10.10.54.64
客户端:10.10.54.63
服务器和客户端:
yum install rpcbind.x86_64 nfs-utils.x86_64
1.服务器端
[root@Cent64 /]# mkdir /stu1
[root@Cent64 /]# chmod 755 /stu1
[root@Cent64 /]# mkdir /stu2
[root@Cent64 /]# chmod 755 /stu2
[root@Cent64 /]# mkdir /stu3
[root@Cent64 /]# chmod 755 /stu3
[root@Cent64 /]# mkdir /stu4
[root@Cent64 /]# groupadd -g 600 nfs-stu4
[root@Cent64 /]# useradd -u 600 -g nfs-stu4 nfs-stu4
[root@Cent64 /]# chown -R nfs-stu4:nfs-stu4 /stu4
2.配置服务器文件
[root@Cent64 share]# vim /etc/exports
/stu1 *(ro)
/stu2 10.10.54.0/24(ro)
/stu3 10.10.54.0/24(ro,root_squash)
/stu4 *(rw,all_squash,anonuid=600,anongid=600)
3.重启服务
[root@Cent64 /]# /etc/init.d/rpcbind restart
[root@Cent64 /]# /etc/init.d/nfs restart
4.客户端查看nfs服务器发布的共享目录centos
[root@Cent63 ~]# /etc/init.d/rpcbind stop
[root@Cent63 ~]# /etc/init.d/rpcbind start[root@CentOS63 usr]# showmount -e 10.10.54.64
clnt_create: RPC: Program not registered
解决方法服务器端
[root@Cent64 ~]# /etc/init.d/rpcbind stop
[root@Cent64 ~]# /etc/init.d/rpcbind start
[root@CentOS63 usr]# showmount -e 10.10.54.64
Export list for 10.10.54.64:
/stu4 *
/stu1 *
/stu3 10.10.54.0/24
/stu2 10.10.54.0/24
5.挂载服务器端的/stu1目录到本地的/mnt/stu1目录
客户端
[root@CentOS63 usr]# mkdir /mnt/stu1
[root@CentOS63 usr]# mount -t nfs 10.10.54.64:/stu1 /mnt/stu1/
[root@CentOS63 usr]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 6192704 3951784 1926348 68% /
tmpfs 510268 0 510268 0% /dev/shm
/dev/sda1 198337 25836 162261 14% /boot
/dev/sda5 516040 16780 473048 4% /swap
/dev/sda3 5160576 4862248 36184 100% /usr
10.10.54.64:/stu1 6192768 1597184 4281088 28% /mnt/stu1
6.卸载/mnt/stu1目录
[root@CentOS63 mnt]# umount /mnt/stu1
[root@CentOS63 mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 6192704 3787340 2090792 65% /
tmpfs 510268 0 510268 0% /dev/shm
/dev/sda1 198337 25836 162261 14% /boot
/dev/sda5 516040 16780 473048 4% /swap
/dev/sda3 5160576 4862248 36184 100% /usr
7.自动挂载nfs服务器上/stu4到本地的/mnt/stu4目录
客户端服务器
[root@CentOS63 mnt]# yum install autofs.x86_64
###开机自动挂载
[root@CentOS63 mnt]# vim /etc/rc.d/rc.local
[root@CentOS63 usr]# mount -t nfs 10.10.54.64:/stu4 /mnt/stu4/
###使用/mnt/stu4/数据时自动挂载,5分钟不使用自动卸载,/mnt和stu4都是自动创建
//建立/etc/auto.master,自动检测特定目录
[root@CentOS63 mnt]# vim /etc/auto.master
/mnt /etc/auto.nfs
..../mnt是子目录stu1所在的文件夹
..../etc/auto.nfs文件设置挂载状况
//建立/etc/auto.nfs
[root@CentOS63 mnt]# vim /etc/auto.nfs
stu4 -rw,bg,soft,rsize=32768,wsize=32768 10.10.54.64:/stu4
[root@CentOS63 ~]# rm -rf /mnt
//启动autofs服务
[root@CentOS63 ~]# /etc/init.d/autofs restart
Starting automount:
#自动创建/mnt文件夹 [ OK ]
[root@CentOS63 ~]# ls -dl /mnt
drwxr-xr-x 2 root root 0 3月 5 19:39 /mnt
[root@CentOS63 ~]# cd /mnt/stu4/ ....使用时df才能看到挂载
[root@CentOS63 ~]#mount |grep stu4
10.10.54.64:/stu4 on /mnt/stu4 type nfs (rw,soft,rsize=32768,wsize=32768,sloppy,vers=4,addr=10.10.54.183,clientaddr=10.10.54.184)
[root@CentOS63 ~]# df /mnt/stu4
Filesystem 1K-blocks Used Available Use% Mounted on
10.10.54.64:/stu4 6192704 1553952 4324192 27% /mnt/stu4tcp
nfs固定端口配置有助于防火墙编写
vim /etc/sysconfig/nfs
# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=32769
# Port rpc.mountd should listen on.
MOUNTD_PORT=892
# Port rquotad should listen on.
RQUOTAD_PORT=875
# Port rpc.statd should listen on.
STATD_PORT=662测试
测试:
ui
[root@Cent64 raid]# rpcinfo -p|grep mount
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 mountd
rest