将同一块硬盘挂载到两台机器上

本文介绍如何使用NFS(网络文件系统)在两台Linux机器上同时读写同一块磁盘。具体步骤包括在一台机器上挂载磁盘,并通过NFS将该磁盘导出给另一台机器。此方案确保了数据的一致性和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问:I want to mount the same disk to two linux machines and both machine must be able to read/write on the same disk at the same time.

答:You can do that through NFS. Mount the disk to a machine and share that drive through NFS to the other machine. 

Suppose the disk to be shared is /dev/sdb and the machines that you want to share the disk is machine1.example.com and machine2.example.com, then:

  1. Mount /dev/sdb in machine1 (You can skip this step if the said disk is already mounted and being used by machine1)

  2. Make the machine1 as the NFS server and export the directory on which /dev/sdb is mounted. Say, if /dev/sdb is mounted on /mnt/sharemount. The NFS export entries in /etc/exports should say:

    /mnt/sharemount machine2.example.com(rw,sync)

  3. Now that machine2 is allowed to use /mnt/sharemount from machine1 through NFS from step2, just mount /mnt/sharemount from machine1 on machine2

    mount machine1.example.com:/mnt/sharemount /mnt/sharemount

Data will not get corruped if these two machines start writing to the same location in /mnt/sharemount since the required locks will be applied and it will all happen transparent to you.

This answer is only an outline. If you are not familiar mounting a new disk to a server and with setting up NFS, please google how to configure nfs client and server linux. The search results will present you dozens of easy to follow tutorials and step-by-step guides. If you are comfortable using the command line(which I assume you are), you should be able to get the setup done with minimal time.

转载于:https://my.oschina.net/wuliong/blog/1573773

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值