[root@nfs01 ~]# chkconfig rpcbind on
[root@nfs01 ~]# chkconfig nfs on
[root@nfs01 ~]# ls /etc/rc.d/rc3.d/* | grep -E 'rpc|nfs'
/etc/rc.d/rc3.d/K61nfs-rdma
/etc/rc.d/rc3.d/K69rpcsvcgssd
/etc/rc.d/rc3.d/S13rpcbind
/etc/rc.d/rc3.d/S14nfslock
/etc/rc.d/rc3.d/S19rpcgssd
/etc/rc.d/rc3.d/S30nfs
查看rpc服务和NFS服务的开机启动顺序
[root@nfs01 ~]# head /etc/init.d/rpcbind
#! /bin/sh
#
# rpcbind Start/Stop RPCbind
#
# chkconfig: 2345 13 87 #运行级别 开机顺序 关机顺序【其中 2345 指的是 运行级别】
# description: The rpcbind utility is a server that converts RPC program \
# numbers into universal addresses. It must be running on the \
# host to be able to make RPC calls on a server on that machine.
#
# processname: rpcbind
[root@nfs01 ~]# head /etc/init.d/nfs
#!/bin/sh
#
# nfs This shell script takes care of starting and stopping
# the NFS services.
#
# chkconfig: - 30 60
# description: NFS is a popular protocol for file sharing across networks.
# This service provides NFS server functionality, which is \
# configured via the /etc/exports file.
# probe: true
1.7. 查看有哪些参数生效
[root@nfs01 ~]# cat /var/lib/nfs/etab
/data 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
1.8. 检查是否成功
[root@nfs01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
2. NFS客户端配置
2.1. 开始rpcbind服务
[root@web01 ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
2.2. 检查共享信息
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
2.3. NFS挂载
[root@web01 ~]# mount -t nfs 172.16.1.31:/data /mnt
2.4. 查看挂载信息
[root@web01 ~]# df -h #有时可能会被卡主
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.5G 6.9G 18% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 190M 40M 141M 23% /boot
172.16.1.31:/data 8.8G 1.5G 6.9G 18% /mnt
或者
[root@web01 ~]# cat /proc/mounts # 优先使用,监控时使用该命令
rootfs / rootfs rw 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
devtmpfs /dev devtmpfs rw,relatime,size=490920k,nr_inodes=122730,mode=755 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /dev/shm tmpfs rw,relatime 0 0
/dev/sda3 / ext4 rw,relatime,barrier=1,data=ordered 0 0
/proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
/dev/sda1 /boot ext4 rw,relatime,barrier=1,data=ordered 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
172.16.1.31:/data/ /mnt nfs4 rw,relatime,vers=4,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=172.16.1.8,minorversion=0,local_lock=none,addr=172.16.1.31 0 0
2.5. 测试
在客户端和服务端之间测试
1、客户端创建文件并且输入数据,在服务端是否可以查看
2、服务端创建文件并且输入数据,在客户端是否可以查看
3、在服务端删除客户端创建的文件
4、在客户端删除服务端创建的文件
2.6. 加入开机自启动
[root@web01 mnt]# tail -3 /etc/rc.local
# mount nfs
mount -t nfs 172.16.1.31:/data /mnt