NFS服务端安装配置
#以下为服务端操作
[root@iZbp1e0xboek6oow616aoiZ ~]# yum install -y nfs-utils rpcbind
[root@wsl-001 ~]# vim /etc/exports
#写入下面一行
/home/nfstestdir 172.16.79.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
[root@wsl-001 ~]# mkdir /home/nfstestdir
[root@wsl-001 ~]# chmod 777 /home/nfstestdir
[root@wsl-001 ~]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd (这就是rpcbind)
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 874/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1093/master
tcp 0 0 172.16.79.140:8730 0.0.0.0:* LISTEN 1655/rsync
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::80 :::* LISTEN 62840/httpd
tcp6 0 0 :::22 :::* LISTEN 874/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1093/master
tcp6 0 0 :::90 :::* LISTEN 62840/httpd
[root@wsl-001 ~]# systemctl start rpcbind
[root@wsl-001 ~]# systemctl start nfs
[root@wsl-001 ~]# ps aux|grep nfs
root 77732 0.0 0.0 0 0 ? S< 22:25 0:00 [nfsd4_callbacks]
root 77738 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77739 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77740 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77741 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77742 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77743 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77744 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77745 0.0 0.0 0 0 ? S 22:25 0:00 [nfsd]
root 77751 0.0 0.0 112676 984 pts/0 S+ 22:26 0:00 grep --color=auto nfs
[root@wsl-001 ~]# ps aux|grep rpc
rpc 77684 0.0 0.0 64956 1420 ? Ss 22:25 0:00 /sbin/rpcbind -w
rpcuser 77702 0.0 0.0 42376 1748 ? Ss 22:25 0:00 /usr/sbin/rpc.statd
root 77709 0.0 0.0 0 0 ? S< 22:25 0:00 [rpciod]
root 77721 0.0 0.0 42564 948 ? Ss 22:25 0:00 /usr/sbin/rpc.mountd
root 77722 0.0 0.0 43816 548 ? Ss 22:25 0:00 /usr/sbin/rpc.idmapd
root 77792 0.0 0.0 112676 980 pts/0 S+ 22:26 0:00 grep --color=auto rpc
#允许开机启动
[root@wsl-001 ~]# systemctl enable rpcbind
[root@wsl-001 ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
NFS配置选项
#以下为客户端操作
[root@wsl-001 ~]# yum install -y nfs-utils
[root@wsl-001 ~]# showmount -e 172.16.79.140
Export list for 172.16.79.140:
/home/nfstestdir 172.16.79.0/24
[root@wsl-001 ~]# mount -t nfs 172.16.79.140:/home/nfstestdir /mnt
[root@wsl-001 mnt]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 16G 1.6G 15G 10% /
devtmpfs 902M 0 902M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 17M 895M 2% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 297M 160M 137M 54% /boot
tmpfs 183M 0 183M 0% /run/user/0
172.16.79.140:/home/nfstestdir 16G 7.0G 8.8G 45% /mnt
[root@wsl-001 mnt]# touch /mnt/test.txt
[root@wsl-001 mnt]# ls -l /mnt/test.txt
-rw-r--r-- 1 wsl wsl 0 5月 8 22:34 /mnt/test.txt
[root@wsl-001 mnt]# id wsl
uid=1000(wsl) gid=1000(wsl) 组=1000(wsl) (限定了用户)
#以下为服务端操作
[root@wsl-001 nfstestdir]# ls -l /home/nfstestdir/test.txt
-rw-r--r-- 1 wsl wsl 0 5月 8 22:34 /home/nfstestdir/test.txt
[root@wsl-001 nfstestdir]# id wsl
uid=1000(wsl) gid=1000(wsl) 组=1000(wsl) (限定了用户)