nfs autos

简介: nfs autos

NFS AutoFS

两台机器

image.png

一、NFS服务端配置

1.配置本地 hosts 解析

[root@nfs-server ~]# echo "192.168.195.145 "nfs-server" >> /etc/hosts
[root@nfs-server ~]# echo "192.168.195.146 "client" >> /etc/hosts
[root@nfs-server ~]# tail -n2 /etc/hosts
192.168.195.145 nfs-server
192.168.195.146 client

2.安装 nfs 以及 rpc 所需要的包

[root@nfs-server ~]# yum -y install nfs-utils rpcbind

3.启动 rpc nfs 服务并设置为开机自启动

[root@nfs-server ~]# systemctl start rpcbind //先启动 rpc 服务再启动 nfs 服务。
[root@nfs-server ~]# systemctl start nfs
[root@nfs-server ~]# systemctl enable rpcbind
[root@nfs-server ~]# systemctl enable nfs

4.配置挂载目录

[root@nfs-server ~]# vi /etc/exports
/mnt 192.168.195.0/24(rw,async)
/opt *(rw,async)

5.关闭防火墙和selinux

[root@nfs-server ~]# systemctl stop firewalld
[root@nfs-server ~]# systemctl disable firewalld
[root@nfs-server ~]# setenforce 0
[root@nfs-server ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are
protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

6.验证NFS

[root@nfs-server ~]# systemctl restart rpcbind nfs-server
[root@nfs-server ~]# showmount -e 127.0.0.1
Export list for 192.168.195.145:
/opt *
/mnt 192.168.195.0/24

二、NFS客户端挂载

1.安装NFS

[root@nfs-client ~]# yum -y install rpcbind nfs-utils

2.配置本地 hosts 解析

[root@nfs-client users]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.195.145 nfs-server
192.168.195.146 nfs-client

3.验证NFS

[root@nfs-client ~]# showmount -e 192.168.195.145
Export list for 192.168.195.145:
/opt *
/mnt 192.168.195.0/24

4.挂载NFS

[root@nfs-client ~]# mount -t nfs 192.168.195.145:/mnt /mnt
[root@nfs-client ~]# mount -t nfs 192.168.195.145:/opt /opt
[root@nfs-client ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
192.168.195.145:/mnt nfs4 17G 1.5G 16G 9% /mnt
192.168.195.145:/opt nfs4 17G 1.5G 16G 9% /opt

三、使用autofs配置自动挂载

1.配置本地 hosts 解析

[root@client users]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.195.145 nfs-server
192.168.195.147 client

2.创建挂载目录并挂载

[root@client ~]# mkdir /nfsdir
[root@client ~]# mount -t nfs 192.168.195.145:/mnt /nfsdir
[root@client ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
192.168.195.145:/mnt nfs4 17G 1.5G 16G 9% /mnt
192.168.195.145:/opt nfs4 17G 1.5G 16G 9% /opt
192.168.195.145:/mnt nfs4 17G 1.5G 16G 9% /nfsdir

3.编辑 “/etc/auto.master” 主配置文件

[root@client ~]# echo "/nfsdir /etc/auto.user" >> /etc/auto.master

4.编辑 “/etc/auto.user” 子配置文件

[root@client ~]# echo "users -fstype=nfs,rw,sync,no_root_squash nfs-server:/home"
>> /etc/auto.user

5.启动 autofs 服务并设置为开机自启动

#服务端
[root@server ~]# mkdir /mnt/users
#客户端
[root@client ~]# cd /nfsdir/
[root@client nfsdir]# ls -lh
总用量 0
[root@client nfsdir]# cd users
[root@client users]# pwd
/nfsdir/users
[root@client users]# ls -lh /nfsdir/
total 0
drwxr-xr-x 2 root root 6 Mar 16 03:26 users

6.测试autofs自动挂载

#服务端
[root@server ~]# mkdir /mnt/users
#客户端
[root@client ~]# cd /nfsdir/
[root@client nfsdir]# ls -lh
总用量 0
[root@client nfsdir]# cd users
[root@client users]# pwd
/nfsdir/users
[root@client users]# ls -lh /nfsdir/
total 0
drwxr-xr-x 2 root root 6 Mar 16 03:26 users


相关文章
|
3月前
|
Unix
|
12月前
|
网络协议 网络安全
|
域名解析 网络协议 Unix
NFS服务器详解
NFS服务器详解
1245 0
|
存储 网络协议 Linux
NFS服务配置
NFS会经常用到,用于在网络上共享存储。这样讲,你对NFS可能不太了解,举一个例子来说明一下NFS是用来做什么的。假如有三台机器A, B, C,它们需要访问同一个目录,目录中都是图片,传统的做法是把这些图片分别放到A, B, C. 但是使用NFS只需要放到A上,然后A共享给B和C即可。访问的时候,B和C是通过网络的方式去访问A上的那个目录的。
363 0
NFS服务配置
|
测试技术
|
Oracle 关系型数据库 网络安全
|
开发工具
nfs
1026 0