NFS--基础--02--实践

NFS–基础–02–实践


1、常用命令

1.1、nfs


# 启动
systemctl start nfs   
# 停止
systemctl stop nfs
# 重启
systemctl restart nfs
# 状态
systemctl status nfs
# 开机自启动
systemctl enable nfs

1.2、rpcbind

# 启动
systemctl start rpcbind.service       
# 停止
systemctl stop rpcbind.service  
# 重启
systemctl restart rpcbind.service  
# 状态
systemctl status rpcbind.service  
# 开机自启动
systemctl enable rpcbind.service   

1.3、httpd

# 启动
systemctl start httpd
# 停止
systemctl stop httpd
# 重启
systemctl restart httpd
# 状态
systemctl status httpd
# 开机自启动
systemctl enable httpd

2、服务端

2.1、安装软件包

# 查看是否安装了 nfs-utils和rpcbind 软件包
rpm -q rpcbind nfs-utils                  

# 没有则用yum安装
yum install -y rpcbind nfs-utils  		

2.2、设置共享目录

2.2.1、创建共享目录

# 创建目录
mkdir /nfs/share -p

# 给与权限
chmod 777 /nfs/share
 

2.2.2、编辑配置文件

# vim /etc/exports	
/nfs/share 192.168.187.0/24(rw,sync,no_root_squash)
说明
  1. /nfs/share 允许192.168.187.0/24的客户端访问。
  2. rw:表示允许读写,ro表示为只读;
  3. sync:表示同步写入到内存与硬盘中;
  4. no_root_squash:表示当客户机以root身份访问时赋予本地root权限

2.3、启动NFS服务程序

# 启动
systemctl start nfs
systemctl start rpcbind.service


# 开机自启动
systemctl enable rpcbind.service
# 开机自启动
systemctl enable nfs

2.3.1、查看rpcbind是否开启

rpcbind服务默认使用111端口

netstat -anpt | grep rpcbind   

在这里插入图片描述

2.3.2、查看本机发布的NFS共享目录

showmount -e 

在这里插入图片描述

3、客户端

3.1、安装软件包

# 查看是否安装rpcbind,nfs-utils 
rpm -q rpcbind nfs-utils  
# 未安装可以使用yum进行安装                  
yum install -y rpcbind nfs-utils 
 			
 

3.2、启动客户端

 
# 开启 rpcbind服务            
systemctl start rpcbind			
# 设置开机自启			
systemctl enable rpcbind					
		

3.3、查看服务器端共享的目录,然后进行挂载

3.3.1、查看共享目录

# 服务端IP地址为 192.168.187.181
showmount -e 192.168.187.181

在这里插入图片描述

3.3.2、手动挂载并查看是否成功

# 创建目录
mkdir  /nfs-client-share
# 手动挂载
mount 192.168.187.181:/nfs/share /nfs-client-share
# 查看是否成功
df -Th

在这里插入图片描述

3.3.3、设置自动挂载

# vim /etc/fstab
192.168.187.181:/nfs/share /nfs-client-share  nfs  defaults,_netdev 0 0
 

在这里插入图片描述

4、测试–验证共享存储功能

在服务端创建文件,在客户端查看

在这里插入图片描述

5、测试–网页共享功能

5.1、服务端操作

5.1.1、安装httpd,并设置前端页面内容

# 安装httpd
yum install httpd -y 
# 启动
systemctl start httpd
# 设置前端页面内容
echo "NFS 服务端 192.168.187.154"  > /var/www/html/index.html

在这里插入图片描述

5.1.2、编辑nfs配置文件

# vim /etc/exports		
# 共享目录
/var/www/html 192.168.187.0/24(ro)

在这里插入图片描述

5.1.3、宣告并查看共享目录

# 宣告共享目录
exportfs -rv
# 查看共享目录
showmount -e 

在这里插入图片描述

5.1.4、重启服务

# 注意执行顺序,先rpcbind,后nfs
systemctl restart rpcbind.service
systemctl restart nfs


5.2、客户端操作

5.2.1、安装httpd,并设置前端页面内容

# 安装httpd
yum install httpd -y 
# 启动
systemctl start httpd
 

5.2.2、重启服务

# 注意执行顺序,先rpcbind,后nfs
systemctl restart rpcbind.service
systemctl restart nfs



5.2.2、查看服务器端共享的目录,然后进行挂载

# 服务端IP地址为 192.168.187.181
showmount -e 192.168.187.181


# 手动挂载
mount 192.168.187.181:/var/www/html /var/www/html
# 查看是否成功
df -Th

在这里插入图片描述

5.2.3、打开客户端浏览器输入服务端IP查看

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值