Linux Centos7 --- nfs共享存储空间
admin
2023-03-31 06:02:09
0

Linux  Centos7 --- nfs共享存储空间

本章目的:使用NFS共享存储空间,并搭建HTTPD服务去使用这个空间

本章环境:VM虚拟机,一台服务器Centos7作为服务端提供NFS服务,一台服务器Centos7 -1作为客户端

1.给服务端加一块硬盘(重启服务端磁盘才有效)

Linux  Centos7 --- nfs共享存储空间

2.查看磁盘是否生效

[root@localhost ~]# ls /dev/
agpgart          lp0                 sda5      tty22  tty48    usbmon0
autofs           lp1                 sdb  //这个是我们新加的     tty23  tty49    usbmon1
block            lp2                 sg0       tty24  tty5     usbmon2
bsg              lp3                 sg1       tty25  tty50    vcs
btrfs-control    mapper              sg2       tty26  tty51    vcs1
bus              mcelog              shm       tty27  tty52    vcs2
cdrom            mem                 snapshot  tty28  tty53    vcs3
char             mqueue              snd       tty29  tty54    vcs4
console          net                 sr0       tty3   tty55    vcs5
core             network_latency     stderr    tty30  tty56    vcs6
cpu              network_throughput  stdin     tty31  tty57    vcsa
cpu_dma_latency  null                stdout    tty32  tty58    vcsa1

3.配置磁盘,格式化

[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0xe5bb6879 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5242624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

4.自动挂载并且查看挂载状态

[root@client html]# vim /etc/fstab

/etc/fstab
 Created by anaconda on Sat Aug 10 00:09:52 2019

 Accessible filesystems, by reference, are maintained under '/dev/disk'
 See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

UUID=6885a615-3022-4e62-8685-1dc9aaa0b657 /                       xfs     defaults        0 0
UUID=91d30663-7fe2-4989-9ad9-9f9c7086a493 /boot                   xfs     defaults        0 0
UUID=121c8f14-d41e-4da5-a3eb-f973cde89040 /home                   xfs     defaults        0 0
UUID=89bc11a2-b2cc-4816-9638-8f061beae396 swap                    swap    defaults        0 0
/dev/sdb1       /mnt    xfs     defaults        0 0
设备目录         挂载点    文件类型   
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
~                                                                                                 
:wq  //保存退出
[root@localhost ~]# mount -a
[root@localhost ~]# df -hT
文件系统       类型      容量  已用  可用 已用% 挂载点
/dev/sda2      xfs        10G  3.9G  6.2G   39% /
devtmpfs       devtmpfs  898M     0  898M    0% /dev
tmpfs          tmpfs     912M     0  912M    0% /dev/shm
tmpfs          tmpfs     912M  9.0M  903M    1% /run
tmpfs          tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda5      xfs        10G   37M   10G    1% /home
/dev/sda1      xfs       6.0G  174M  5.9G    3% /boot
tmpfs          tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs          tmpfs     183M   16K  183M    1% /run/user/0
/dev/sdb1      xfs        20G   33M   20G    1% /mnt

5.装NFS共享和远程调用工具包

[root@localhost ~]# yum install nfs-utils rpcbind -y   //NFS共享和远程调用工具包
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: centos.ustc.edu.cn
 * updates: mirrors.163.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 nfs-utils.x86_64.1.1.3.0-0.48.el7 将被 升级
---> 软件包 nfs-utils.x86_64.1.1.3.0-0.61.el7 将被 更新
---> 软件包 rpcbind.x86_64.0.0.2.0-42.el7 将被 升级
---> 软件包 rpcbind.x86_64.0.0.2.0-47.el7 将被 更新

6.编辑共享配置文件

[root@localhost ~]# vim /etc/exports  //到共享配置文件中开始配置

/mnt    192.168.17.0/24(rw,sync,no_root_squash)   //可读可写,同步,不降级处理
你共享出去的挂载点目录                                                      

7.开启所有功能关闭防火墙,查看有没有被共享出去

[root@localhost ~]# systemctl start nfs  //开启共享功能
[root@localhost ~]# systemctl start rpcbind  //开启远程调用
[root@localhost ~]# netstat -ntap | grep rpc   查看TCP端口
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      3035/rpc.mountd     
tcp        0      0 0.0.0.0:45274           0.0.0.0:*               LISTEN      3033/rpc.statd      
tcp6       0      0 :::38508                :::*                    LISTEN      3033/rpc.statd      
tcp6       0      0 :::20048                :::*                    LISTEN      3035/rpc.mountd     
[root@localhost ~]# systemctl stop firewalld.service //关闭防火墙
[root@localhost ~]# setenforce 0  //关闭增强功能
[root@localhost ~]# showmount -e  //查看我们有没有共享出去
Export list for localhost.localdomain:
/mnt 192.168.17.0/24

8.到客户段中,关闭所有功能,安装HTTPD服务

[root@client ~]# systemctl stop firewalld.service 
[root@client ~]# setenforce 0
[root@client ~]# yum insatll httpd -y
已加载插件:fastestmirror, langpacks

9.把服务器的挂载点,挂载到我们HTTPD的站点下

[root@client ~]# mount 192.168.17.128:/mnt /var/www/html/  //站点
[root@client ~]# df -hT
文件系统            类型      容量  已用  可用 已用% 挂载点
/dev/sda2           xfs        20G  4.5G   16G   23% /
devtmpfs            devtmpfs  898M     0  898M    0% /dev
tmpfs               tmpfs     912M     0  912M    0% /dev/shm
tmpfs               tmpfs     912M  9.0M  903M    1% /run
tmpfs               tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda3           xfs       9.4G   37M  9.3G    1% /home
/dev/sda1           xfs       5.6G  174M  5.5G    4% /boot
tmpfs               tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs               tmpfs     183M   24K  183M    1% /run/user/0
/dev/sr0            iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
192.168.17.128:/mnt nfs4       20G   32M   20G    1% /var/www/html

10.使用另一种方法:自动挂载,配置

[root@client ~]# umount /var/www/html/   //先把之前的解挂
[root@client ~]# df -hT
文件系统       类型      容量  已用  可用 已用% 挂载点
/dev/sda2      xfs        20G  4.5G   16G   23% /
devtmpfs       devtmpfs  898M     0  898M    0% /dev
tmpfs          tmpfs     912M     0  912M    0% /dev/shm
tmpfs          tmpfs     912M  9.0M  903M    1% /run
tmpfs          tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda3      xfs       9.4G   37M  9.3G    1% /home
/dev/sda1      xfs       5.6G  174M  5.5G    4% /boot
tmpfs          tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs          tmpfs     183M   24K  183M    1% /run/user/0
/dev/sr0       iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64

[root@client ~]# vim /etc/fstab
 /etc/fstab
Created by anaconda on Fri Aug  9 19:16:53 2019

 Accessible filesystems, by reference, are maintained under '/dev/disk'
 See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

UUID=0857ae22-72c1-4ad4-bd8d-333df1d5c1a4 /                       xfs     defaults        0 0
UUID=2d335fb0-e4af-4a90-8777-1ce16ac58065 /boot                   xfs     defaults        0 0
UUID=d28abede-d7a4-439a-b830-64f95069ec17 /home                   xfs     defaults        0 0
UUID=1bc36e2d-3ba8-4980-9bf8-7b56280bb434 swap                    swap    defaults        0 0
192.168.17.128:/mnt     /var/www/html   nfs     defaults,_netdev        0 0     
[root@client ~]# mount -a
[root@client ~]# df -hT
文件系统            类型      容量  已用  可用 已用% 挂载点
/dev/sda2           xfs        20G  4.5G   16G   23% /
devtmpfs            devtmpfs  898M     0  898M    0% /dev
tmpfs               tmpfs     912M     0  912M    0% /dev/shm
tmpfs               tmpfs     912M  9.0M  903M    1% /run
tmpfs               tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda3           xfs       9.4G   37M  9.3G    1% /home
/dev/sda1           xfs       5.6G  174M  5.5G    4% /boot
tmpfs               tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs               tmpfs     183M   24K  183M    1% /run/user/0
/dev/sr0            iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
192.168.17.128:/mnt nfs4       20G   32M   20G    1% /var/www/html

11.在站点中写一个网页,并开启HTTPD服务

[root@client ~]# cd /var/www/html/
[root@client html]# ls
[root@client html]# vim index.html
h2>this is nfs
~                                                                                      
~                          
[root@client html]# cat index.html 

this is nfs

[root@client html]# systemctl start httpd

12.我们登录网站试一下(客户端的IP地址)

Linux  Centos7 --- nfs共享存储空间

以上就是我们NFS共享存储的所有内容了

相关内容

热门资讯

伊朗外交部发言人:解冻被冻结资... △伊朗外交部发言人巴加埃(资料图)当地时间5月11日,伊朗外交部发言人巴加埃在回应有关伊美谈判主要分...
男子驾驶摩托车国道上逆行致1死... 早前报道 摩托车国道上逆行致1死1伤,骑手出事前曾做手势打招呼来源:大风新闻(2026年05月11日...
外交部:中方决定不同意台湾地区... 5月11日,外交部发言人郭嘉昆主持例行记者会。有记者问:据了解,第七十九届世界卫生大会将于5月18日...
糖果制品中检出伟哥 4月22日,上海市市场监督管理局发布2026年第13期省级食品安全抽检信息,检出3批次不合格食品,不...
伊朗副议长:我国已成为世界第四... 美伊谈判陷入僵局,伊朗拒绝了美国提出的结束战争的方案。以此同时,伊朗副议长巴巴伊5月10日强调,伊朗...
河南760亿省级财政资金定存招... 【大河财立方消息】5月11日消息,河南省财政厅公布2026年度第1期河南省省级财政专户资金定期存款代...
无忧传媒宣布与“孕妇泰国坠崖案... 据北京商报消息,5月11日,记者从无忧传媒方面获悉,目前公司与签约达人王暖暖经友好协商已确定解约。5...
米哈游:编造“皮套论”谣言构成... 【大河财立方消息】 5月11日,据米哈游法务部,近日米哈游诉网络博主许某鹏(网名“自由人米八”)、罗...
外交部介绍特朗普访华具体安排和... 5月11日,外交部发言人郭嘉昆主持例行记者会。总台央视记者提问:中方已经发布美国总统特朗普来华进行国...
61家!郑州市科技类校外培训机... 根据《河南省科技类校外培训机构设置标准和管理指南(试行)》有关规定,为落实“双减”政策要求,经科技类...