Network File System
RPC:Remote Procedure Call
NFS: sun, 协议;
NFSv1
NFSv2, NFSv3,
NIS:Network Information Service
nfsd:2049/tcp
辅助类的服务:rpc (portmap)
rpc.mountd:认证;
rpc.lockd:加锁
rpc.statd:状态
nfs server:
安装:内核模块nfsd
yum install -y nfs-utils
用户空间的工具程序: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:
root_squash:压缩root用户的权限,默认行为;nfsnobody
no_root_squash:不压缩root用户的权限;
all_squash:压缩所有用户的权限; 只可以往外复制文件
anonuid and anongid:将压缩的用户映射为此处指定的用户
NFS Client:
mount -t nfs NFS_SERVER:/PATH/TO/EXPORTED_DIR /MOUNT_POINT [-rvVwfnsh] [-o OPTIONS]
showmount - show mount information for an NFS server
showmount [options] 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.
-rReexport all directories, synchronizing /var/lib/nfs/etab with /etc/exports and files under /etc/exports.d.
-u Unexport one or more directories.
-au:重新装载,不用重启服务即可把新增的装载到服务上
开机自动挂载:/etc/fstab文件中
练习:
(1) 创建一个共享mydata,路径为/mysql/data,客户端1挂载至/mydata;而后客户端1主机安装mysql或mariadb,将数据目录设定为/mydata,要确保mysql服务能正常 运行,但数据目录位于nfs server上;而后,直接安装mysql或mariadb server,设定其数据目录为/mydata;测试
(a) 客户端1 mysql服务运行时,客户端2的mysql服务能否启动?
不能,只能启动一台
(b) 客户端1 mysql服务停止时,客户端2的mysql服务能否启动?
可以启动
先安装nfs服务包
yum install -y nfs-utils
两台电脑配置一样,其中一台配置如下
yum install mariadb-server nfs-utils -y
编辑MariaDB数据库配置文件
vim /etc/my.cnf
另外一台配置一致
然后启动其中一台客户端的MariaDB服务
(2) nfs sever共享/data/application/web,在目录中提供wordpress;
(a) 部署两台amp服务器,均挂载此共享作为某主机的文档映射路径;
(b) 验正两台主机上的wordpress是否可被同时访问;
(c) 发一个文件,验正图片上传等功能;
(d) 在任一客户端上访问此应用,多次刷新,确认下所有资源访问是否正常 ;
nfs服务配置
将WordPress解压到web目录
unzip wordpress-4.4.2-zh_CN.zip
cp -a wordpress /data/application/web/
重读配置文件,尽量不要重启nfs服务
客户端操作
启动httpd服务,然后用浏览器访问
通过另外一台httpd服务器的ip访问该网页