![network block device(nbd) - 德哥@Digoal - PostgreSQL research](http://img1.ph.126.net/90cHiEn0OAKsBDHuNoGNhw==/6608721291376168174.png)
![network block device(nbd) - 德哥@Digoal - PostgreSQL research](http://img1.ph.126.net/MC0CHMG7MclCzDKkaXo9Fg==/781656010425750850.gif)
![network block device(nbd) - 德哥@Digoal - PostgreSQL research](http://img2.ph.126.net/RuR1_THAdGzjKhF0NMRdlQ==/3243999106690839287.gif)
Network block device
In Linux, a network block device is a device node whose content is provided by a remote machine. Typically, network block devices are used to access a storage device that does not physically reside in the local machine but on a remote one. As an example, the local machine can access a fixed disk that is attached to another computer.
Contents
[hide]Kernel client/userspace server[edit]
Technically, a network block device is realized by two components. In the client machine, where the device node is to work, a kernel module named nbd
controls the device. Whenever a program tries to access the device, this kernel module forwards the request to the server machine, where the data physically resides.
On the server machine, requests from the client are handled by a userspace program called nbd-server
. This program is not implemented as a kernel module because all it has to do is to serve network requests, which in turn just requires regular access to the server filesystem.
Example[edit]
If the file /tmp/xxx
on ComputerA has to be made accessible on ComputerB, one performs the following steps:
On ComputerA:
nbd-server 2000 /tmp/xxx
On ComputerB:
modprobe nbd nbd-client ComputerA 2000 /dev/nbd0
The file is now accessible on ComputerB as device /dev/nbd0
. If the original file was for example a disk image, it could be mounted for example via mount /dev/nbd0 /mnt/whatever
.
The command modprobe nbd
is not necessary if module loading is done automatically. Once the module is in the kernel, nbd-client
is used to send commands to it, such as associating a given remote file to a given local nb device. To finish using /dev/nbd0
, that is, to destroy its association with the file on other computer, one can run nbd-client -d /dev/nbd0
on ComputerB.
In this example, 2000 is the number of the server port through which the file is made accessible. Any available port could be used.
Availability[edit]
The network block device client module is available on Linux and GNU Hurd.
Since the server is a userspace program, it can potentially run on every Unix-like platform. It was ported to Solaris.[1]
[root@150 postgresql-9.3.5]# yum install -y nbd
Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
Loading mirror speeds from cached hostfile
epel/metalink | 5.4 kB 00:00
* base: mirrors.skyshe.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.163.com
* updates: centos.mirror.cdnetworks.com
base | 3.7 kB 00:00
extras | 3.3 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 5.3 MB 00:21
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nbd.x86_64 0:2.9.20-7.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================
Installing:
nbd x86_64 2.9.20-7.el6 epel 43 k
Transaction Summary
====================================================================================================================================
Install 1 Package(s)
Total download size: 43 k
Installed size: 83 k
Downloading Packages:
nbd-2.9.20-7.el6.x86_64.rpm | 43 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : nbd-2.9.20-7.el6.x86_64 1/1
Verifying : nbd-2.9.20-7.el6.x86_64 1/1
Installed:
nbd.x86_64 0:2.9.20-7.el6
Complete!
包含的内容 :
[root@150 postgresql-9.3.5]# rpm -ql nbd
/usr/bin/nbd-server
/usr/sbin/nbd-client
/usr/share/doc/nbd-2.9.20
/usr/share/doc/nbd-2.9.20/README
/usr/share/doc/nbd-2.9.20/cliserv.h
/usr/share/doc/nbd-2.9.20/nbd-tester-client.c
/usr/share/doc/nbd-2.9.20/simple_test
/usr/share/man/man1/nbd-server.1.gz
/usr/share/man/man5/nbd-server.5.gz
/usr/share/man/man8/nbd-client.8.gz
[参考]