NFS服务的配置与应用
NFS通常在局域网中使用,主要用于多台主机共享同一台主机上的文件资源。一台NFS服务器就像一台文件服务器,只要将其文件系统共享出来,NFS客户端将它挂载到本地系统中,从而可以像使用本地系统中的文件一样使用那些远程文件系统中的文件,而不必在本地系统中维护该文件的副本。
1.NFS服务安装使用
yum install nfs-utils ##nfs 主程序
systemctl start nfs
firewall-cmd --permanent --add-service=nfs ##防火墙开放服务端口
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload ##加载防火墙
mkdir /westos/nfs -p ##建立一个共享文件
vim /etc/exports ##
/westos/nfs *(sync,rw) ##共享对所有人开放,sync表示同步更新
exportfs -rv ##刷新
25 history
[[email protected] ~]# mount 172.25.254.118:/westos/nfs /mnt ##测试可挂载
【示例】

自动挂载
yum install autofs.x86_64 -y ##插件安装自动挂载
109 systemctl restart autofs ##开启挂载软件
110 ls -ld /net/ ##此目录是自动生成
【示例】

指定目录挂载
[[email protected] ~]# vim /etc/auto.master ##编辑挂载的配置文件
/westos/linux /etc/auto.nfs ##前面是挂载的目录,后面是挂载时读取的系统文件此文件名任意
[[email protected] ~]# vim /etc/auto.nfs
nfs -rw 172.25.254.118:/westos/nfs
[[email protected] ~]# systemctl restart autofs.service
[[email protected] linux]# cd /westos/linux/nfs #不需要建立,切换到此目录就可以
[[email protected] nfs]# df



客户端可写
NFS通常在局域网中使用,主要用于多台主机共享同一台主机上的文件资源。一台NFS服务器就像一台文件服务器,只要将其文件系统共享出来,NFS客户端将它挂载到本地系统中,从而可以像使用本地系统中的文件一样使用那些远程文件系统中的文件,而不必在本地系统中维护该文件的副本。
1.NFS服务安装使用
yum install nfs-utils ##nfs 主程序
systemctl start nfs
firewall-cmd --permanent --add-service=nfs ##防火墙开放服务端口
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload ##加载防火墙
mkdir /westos/nfs -p ##建立一个共享文件
vim /etc/exports ##
/westos/nfs *(sync,rw) ##共享对所有人开放,sync表示同步更新
exportfs -rv ##刷新
25 history
[[email protected] ~]# mount 172.25.254.118:/westos/nfs /mnt ##测试可挂载
【示例】
【/etc/exports文件的编写内容】


2.客户端使用
2.客户端使用
自动挂载
yum install autofs.x86_64 -y ##插件安装自动挂载
109 systemctl restart autofs ##开启挂载软件
110 ls -ld /net/ ##此目录是自动生成
cd /net/172.25.254.118/westos/nfs ##切换到此目录切换到服务端服务文件就可以把服务端的文件挂载上
【示例】
挂载插件的主配置文件
[[email protected] ~]# vim /etc/sysconfig/autofs ##7.0版本配置文件
[[email protected] ~]# systemctl restart autofs.service ##更改后重启服务
[[email protected] ~]# systemctl restart autofs.service ##更改后重启服务
【比如可以更改断开挂载的默认时间,就是不再使用n秒后自动卸载】
指定目录挂载
[[email protected] ~]# vim /etc/auto.master ##编辑挂载的配置文件
/westos/linux /etc/auto.nfs ##前面是挂载的目录,后面是挂载时读取的系统文件此文件名任意
[[email protected] ~]# vim /etc/auto.nfs
nfs -rw 172.25.254.118:/westos/nfs
[[email protected] ~]# systemctl restart autofs.service
[[email protected] linux]# cd /westos/linux/nfs #不需要建立,切换到此目录就可以
[[email protected] nfs]# df
客户端可写
[[email protected] ~]# vim /etc/exports
/westos/nfs *(sync,rw,no_root_squash) ##所有用户超户动作
[[email protected] ~]# chmod 777 /westos/nfs/
[[email protected] ~]# exportfs -rv ##刷新
[[email protected] ~]# vim /etc/auto.nfs
nfs -rw 172.25.254.118:/westos/nfs
[[email protected] ~]# cd /westos/linux/nfs ##重新挂载
[[email protected] nfs]# touch file2
[[email protected] ~]# useradd westos
[[email protected] ~]# id westos
uid=1001(westos) gid=1001(westos) groups=1001(westos)
/westos/nfs *(sync,rw,anonuid=1001,anongid=1001)
/westos/nfs 172.25.254.218(sync,rw,no_root_squash) 172.25.254.[1-10](sync,rw,anonuid=1001,anongid=1001)
/westos/nfs *(sync,rw,no_root_squash) ##所有用户超户动作
[[email protected] ~]# chmod 777 /westos/nfs/
[[email protected] ~]# exportfs -rv ##刷新
[[email protected] ~]# vim /etc/auto.nfs
nfs -rw 172.25.254.118:/westos/nfs
[[email protected] ~]# cd /westos/linux/nfs ##重新挂载
[[email protected] nfs]# touch file2
[[email protected] ~]# useradd westos
[[email protected] ~]# id westos
uid=1001(westos) gid=1001(westos) groups=1001(westos)
/westos/nfs *(sync,rw,anonuid=1001,anongid=1001)
/westos/nfs 172.25.254.218(sync,rw,no_root_squash) 172.25.254.[1-10](sync,rw,anonuid=1001,anongid=1001)
【示例】所有用户执行超户动作



【示例二】对某台主机执行超户动作,某些为某用户动作



【示例二】对某台主机执行超户动作,某些为某用户动作