linux——nfs
思路+命令
有思路则不死记,有命令因会忘记
思路
1.两台虚拟机
2.配置下载条件并下载安装
3.server机配置nfs配置文件并使其生效
4.启动服务并查看挂载点
5.关闭防火墙之后再在client机进行挂载
命令(默认使用并且已经配置完yum源)
1.安装nfs-utils和rpcbind
[root@nfs-server ~]# yum -y install nfs-utils rpcbind
2.修改server机上的nfs配置文件(/etc/exports)
[root@nfs-server share]# cat /etc/exports
/mnt/test 192.168.100.0/24(rw,no_root_squash,no_all_squash,sync,anonuid=501,anongid=501)
3.创建/mnt/test共享文件
[root@nfs-server ~]# mkdir /mnt/test
4.生效配置
[root@nfs-server ~]# exportfs -r
5.启动服务
[root@nfs-server ~]# systemctl start rpcbind
[root@nfs-server ~]# systemctl start nfs
6.关闭防火墙并且查看挂载点
[root@nfs-server ~]# systemctl stop firewalld
[root@nfs-server ~]# setenforce 0
[root@nfs-server ~]# showmount -e 192.168.100.100
Export list for 192.168.100.100:
/mnt/test 192.168.100.0/24
7.client机关闭防火墙并且挂载共享文件
[root@nfs-client ~]# systemctl stop firewalld
[root@nfs-client ~]# setenforce 0
[root@nfs-client ~]# mount -t nfs 192.168.100.100:/mnt/test /mnt
[root@nfs-client ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 36G 7.6G 28G 22% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.7M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 378M 0 378M 0% /run/user/0
/dev/loop0 4.1G 4.1G 0 100% /opt/cdrom
192.168.100.100:/mnt/test 36G 7.6G 28G 22% /mnt
8.验证NFS共享存储
[root@nfs-client ~]# cd /mnt/
[root@nfs-client mnt]# ll
total 0
[root@nfs-client mnt]# touch abc.txt
[root@nfs-client mnt]# md5sum abc.txt
d41d8cd98f00b204e9800998ecf8427e abc.txt
/mnt/test:为共享目录(若没有这个目录,请新建一个)。
192.168.23.0/24:可以为一个网段,一个IP,也可以是域名。域名支持通配符,例如,*.qq.com。
rw:read-write,可读写。
ro:read-only,只读。
sync:文件同时写入硬盘和内存。
async:文件暂存于内存,而不是直接写入内存。
no_root_squash:NFS客户端连接服务端时,如果使用的是root,那么对服务端共享的目录来说,也拥有root权限。显然开启这项是不安全的。
root_squash:NFS客户端连接服务端时,如果使用的是root,那么对服务端共享的目录来说,拥有匿名用户权限,通常它将使用nobody或nfsnobody身份。
all_squash:不论NFS客户端连接服务端时使用什么用户,对服务端共享的目录来说,都拥有匿名用户权限。
anonuid:匿名用户的UID(User Identification,用户身份证明)值,可以在此处自行设定。
anongid:匿名用户的GID(Group Identification,共享资源系统使用者的群体身份)值。