文件共享NFS

nfs:mysql


Network File Systemweb

RPC:Remote Procedure Callsql

NFS: sun, 协议;服务器

NFSv1app

NFSv2, NFSv3, 异步

NIS:Network Information Serviceasync

nfsd:2049/tcp tcp

辅助类的服务:rpc (portmap)ide

rpc.mountd:认证;对挂载的主机进行认证wordpress

rpc.lockd:加锁:防止多进程同时访问同一个文件使文件发生错乱

rpc.statd:状态

nfs server:

安装:内核模块nfsd

用户空间的工具程序:nfs-utils

Unit File:/usr/lib/systemd/system/nfs.service

配置文件:/etc/exports, /etc/exports.d/*

管理共享的nfs文件系统:配置文件每一行定义一个共享文件系统

Each line contains an export point and a whitespace-separated list of clients allowed to mount the file system at that point.

 

/PATH/TO/SOME_DIR   CLIENTS_1(export_options,...)  CLIENTS_2(export_options,...) 

CLIENTS:

single host: IPv4, IPv6, FQDN

IP networks:network/netmask,支持两种格式的掩码;

wildcards:在主机名字符串中使用通,*.magedu.com,

anonymous:*,表示全部的客户端主机;

General Options

ro:只读;

rw:读写;

sync:同步

async:异步

User ID Mapping:

远程客户端和服务端的用户映射是根据uid进行映射的,为了不root权限过大的问题,默认限制了root用户的权限即默认就有root_squash

root_squash:压缩root用户的权限,默认行为;nfsnobody

no_root_squash:不压缩root用户的权限;

all_squash:压缩全部用户的权限; //默认是不压缩,以uid号进行映射

anonuid=uid,anongid=gid:将压缩的用户映射为此处指定的用户

NFS Client:

mount -t nfs NFS_SERVER:/PATH/TO/EXPORTED_DIR  /MOUNT_POINT  [-rvVwfnsh] [-o OPTIONS]

showmount - show mount information for an NFS server

-e or --exports

Show the NFS server's export list.

-d or --directories

List only the directories mounted by some client.

exportfs - maintain table of exported NFS file systems

-a     Export or unexport all directories.

-r Reexport  all  directories, synchronizing /var/lib/nfs/etab with /etc/exports and files under /etc/exports.d.

-u     Unexport one or more directories.

 

开机自动挂载:/etc/fstab文件中,若是nfs服务器没开启,这样会使客户机出现阻塞。解决方法是在挂载的时候mount命令加上timeout ;

练习:

(1) 建立一个共享mydata,路径为/mysql/data,客户端1挂载至/mydata;然后客户端1主机安装mysql或mariadb,将数据目录设定为/mydata,要确保mysql服务能正常 运行,但数据目录位于samba server上;

(2) 客户端2主机使用相似客户端1主机的方式挂载mydata共享至本地的/mydata目录,然后,直接安装mysql或mariadb server,设定其数据目录为/mydata;测试

(a) 客户端1 mysql服务运行时,客户端2的mysql服务可否启动?

1启动2不能启动,

(b) 客户端1 mysql服务中止时,客户端2的mysql服务可否启动?

1停2能启动

练习:(1) nfs sever共享/data/application/web,在目录中提供wordpress;

  (2) 部署两台amp服务器,均挂载此共享做为某主机的文档映射路径;

  (3) 验正两台主机上的wordpress是否可被同时访问;

(a) 发一个文件,验正图片上传等功能;

(b) 在任一客户端上访问此应用,屡次刷新,确认下全部资源访问是否正常 ;