nfs文件系统

##nfs文件系统
1.适用于linux系统
下载服务
yum install nfs-utils
打开防火墙
[[email protected] ~]# firewall-cmd --permanent --add-service=nfs ##开启服务
success
[[email protected] ~]# firewall-cmd --permanent --add-service=rpc-bind ##让客户端分配端口
success
[[email protected] ~]# firewall-cmd --permanent --add-service=mountd ##让客户端可以挂载
success
[[email protected] ~]# firewall-cmd --reload ##重新加载防火墙服务
success
nfs文件系统
[[email protected] ~]# vim /etc/exports
1 /westoslinux *(ro,sync)
[[email protected] ~]# exportfs -rv
exporting *:/westoslinux

nfs文件系统

在客户端:
[[email protected] ~]# showmount -e 172.25.254.115 ##查看服务端能够开启的端口
Export list for 172.25.254.115:
/westoslinux *
[[email protected] ~]# mount 172.25.254.115:/westoslinux /mnt/ ##只能用挂载的方式
[[email protected] ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 121041160 37944688 83096472 32% /
devtmpfs 1948356 0 1948356 0% /dev
tmpfs 1963368 480 1962888 1% /dev/shm
tmpfs 1963368 9004 1954364 1% /run
tmpfs 1963368 0 1963368 0% /sys/fs/cgroup
/dev/loop0 3704296 3704296 0 100% /var/www/html/westos
tmpfs 392676 20 392656 1% /run/user/1000
172.25.254.115:/westoslinux 10473984 3222528 7251456 31% /mnt
nfs文件系统

2.执行自动挂载
在客户端:
[[email protected] ~]# yum install autofs
[[email protected] ~]# vim /etc/auto.master
8 /opt ##挂载地址的上层目录 /etc/auto.westos

nfs文件系统
[[email protected] ~]# vim /etc/auto.westos
1 westos 172.25.254.115:/westoslinux ##服务端的地址
nfs文件系统
[[email protected] ~]# vim /etc/sysconfig/autofs ##autofs的主配置文件
13 TIMEOUT=5 ##挂载后不执行操作,等待5s后自动卸载
nfs文件系统
7.0的配置文件在 /etc/sysconfig/autofs里
7.0以上的配置文件在 /etc/autofs.conf里
[[email protected] ~]# cd /opt/
[[email protected] opt]# ls
[[email protected] westos]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3252136 7221764 32% /
devtmpfs 469332 0 469332 0% /dev
tmpfs 484920 80 484840 1% /dev/shm
tmpfs 484920 12784 472136 3% /run
tmpfs 484920 0 484920 0% /sys/fs/cgroup
172.25.254.115:/westoslinux 10473984 3226880 7247104 31% /opt/westos ##自动挂载执行成功
[[email protected] westos]# cd
等待5s,自动卸载
[[email protected] ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3252136 7221764 32% /
devtmpfs 469332 0 469332 0% /dev
tmpfs 484920 80 484840 1% /dev/shm
tmpfs 484920 12784 472136 3% /run
tmpfs 484920 0 484920 0% /sys/fs/cgroup
nfs文件系统

3.客户端挂载选项
rw 挂载可读写的文件系统
ro 挂载只读文件系统
ver=4 尝试只使用指定的NFS的版本进行挂载,如果服务器不支持改版本,则挂载请求失败
soft:如果NFS请求超时,三次尝试后返回错误,权衡数据完整性于提高客户端相应性
测试
更改文件所有人和所有组
1 /westoslinux *(ro,sync) 172.25.254.215(rw,sync,anonuid=1002,anongid=1001 )
[[email protected] ~]# exportfs -rv
exporting 172.25.254.215:/westoslinux
exporting *:/westoslinux
nfs文件系统
[[email protected] mnt]# touch file6
[[email protected] mnt]# ll
total 0
-rw-r–r-- 1 student student 0 Feb 22 01:37 file1
-rw-r–r-- 1 student student 0 Feb 22 01:38 file2
-rw-r–r-- 1 nfsnobody nfsnobody 0 Feb 22 04:02 file3
-rw-r–r-- 1 1002 1001 0 Feb 22 04:14 file4
-rw-r–r-- 1 1002 1001 0 Feb 22 04:15 file5
-rw-r–r-- 1 1002 1001 0 Feb 22 04:16 file6
nfs文件系统
nfs文件系统
更改soft
1 /westoslinux *(ro,sync) 172.25.254.215(ro,sync,anonuid=1002,anongid=1001 )
nfs文件系统
[[email protected] ~]# mount 172.25.254.115:/westoslinux /mnt -o soft
[[email protected] mnt]# touch file7
touch: cannot touch ‘file7’: Read-only file system ##会报错证明成功

nfs文件系统
nfs文件系统
用mount查看显示soft
nfs文件系统
测试:在服务端:
[[email protected] ~]# vim /etc/exports

1 /westoslinux *(ro,sync) 172.25.254.215(rw,sync,no_root_squash)
[[email protected] ~]# exportfs -rv
exporting 172.25.254.215:/westoslinux
exporting *:/westoslinux
nfs文件系统
在客户端
[[email protected] ~]# mount 172.25.254.115:/westoslinux /mnt -o soft
[[email protected] ~]# cd /mnt
[[email protected] mnt]# ll
total 0
-rw-r–r-- 1 student student 0 Feb 22 01:37 file1
-rw-r–r-- 1 student student 0 Feb 22 01:38 file2
-rw-r–r-- 1 nfsnobody nfsnobody 0 Feb 22 04:02 file3
-rw-r–r-- 1 1002 1001 0 Feb 22 04:14 file4
-rw-r–r-- 1 1002 1001 0 Feb 22 04:15 file5
-rw-r–r-- 1 1002 1001 0 Feb 22 04:16 file6
[[email protected] mnt]# touch file7
[[email protected] mnt]# ll
total 0
-rw-r–r-- 1 student student 0 Feb 22 01:37 file1
-rw-r–r-- 1 student student 0 Feb 22 01:38 file2
-rw-r–r-- 1 nfsnobody nfsnobody 0 Feb 22 04:02 file3
-rw-r–r-- 1 1002 1001 0 Feb 22 04:14 file4
-rw-r–r-- 1 1002 1001 0 Feb 22 04:15 file5
-rw-r–r-- 1 1002 1001 0 Feb 22 04:16 file6
-rw-r–r-- 1 root root 0 Feb 22 04:26 file7

nfs文件系统