- 论坛徽章:
- 3
|
qpipe是我写的一个在Unix机器上通过管道可靠传数据的工具。此工具开发的初衷是为了在生产中心和容灾中心传ZFS文件系统快照来使用了。我开始使用ssh来做管道来传ZFS快照,但当网络不好时容易hang,同时发现ssh带宽在千兆网上只能到达50MBbytes/s,就再不高不上去了,同时还很占用CPU。我写的这个工具有以下几个功能:
1. 当网络不稳定,TCP连接断了后,可以重连。
2. 相比ssh,占用CPU低。
3.有压缩功能,为了提高压缩速度,可以使用多线程压缩,线程数可以由参数指定。
在Solaris平台上已使用了很长一段时间,运行一直稳定。
下面介绍使用方法:
此工具分服务端和客户端,而程序只有这一个,当指定不同的参数时,程序会以服务端运行或以客户端模式运行。
在服务器端,运行qpipe服务:
nohup ./qpipe -p 4000 -n 192.168.1.0/24 -n 192.168.2.0 >qpipe.log 2>&1 &
-n 参数指定允许访问的客户端IP的网络范围,可以设置多个。
在客户端上:
如果想把文件t.dat传送到服务端机器的/tmp目录下,客户端的命令如下:
cat t.dat | ./qpipe -s 192.168.1.1 -p 4000 -c "cat >/tmp/t.dat"
osdba@odlt:~/tmp/osdba-qpipe-24a0aea$ cat t.dat | ./qpipe -s 192.168.1.1 -p 4000 -c "cat >/tmp/t.dat"
2012-03-15 21:01:29 : INFO : Client id : 1
====Total read bytes : 10485760, send bytes : 45793, rate of compression : 0%, time : 0.24 s
其中 -s指定了服务器的IP地址,-p指定了端口。-c 指定了在服务端接收数据的程序。上面的命令就如同在本机上执行:
cat t.dat |cat >/tmp/t.dat命令,只不过通过qpipe完成了跨机器的功能。
下面演示如何传送ZFS快照:
[root@host01/]#zfs list
NAME USED AVAIL REFER MOUNTPOINT
storagepool 804G 422G 730G /storagepool
storagepool/tangtest 60.6G 422G 59.6G /storagepool/tangtest
我们要把/storagepool/tangtest文件系统传送到host02上去。传送zfs快照需要先建一个快照:
[root@host01 /]#zfs snapshot storagepool/tangtest@snap01
[root@host01 /]#zfs list
NAME USED AVAIL REFER MOUNTPOINT
storagepool 803G 423G 730G /storagepool
storagepool/tangtest 59.6G 423G 59.6G /storagepool/tangtest
storagepool/tangtest@snap01 0 - 59.6G -
这时可以看到快照storagepool/tangtest@snap01建好了,我们把这个快照传到host02上。
先把host02上把启动qpipe服务器:
[root@host02 ]#nohup ./qpipe -n 192.168.128..0/24 -n 192.168.129.0/24 -p 5000 >qpipe.log 2>&1 &
[1] 35
然后在host01上运行如下命令:
[root@host01]#zfs send storagepool/tangtest@snap01 |./qpipe -s 192.168.129.2 -p 5000 -c "zfs recv storagepool/tangtest"
2012-03-15 21:10:55 : INFO : Client id : 1
----read speed: 187016797/s, send speed: 755235/s, rate of compression : 0%
----read speed: 146371897/s, send speed: 653566/s, rate of compression : 0%
....
....
等命令执行完后,到host02上可以看到文件系统storagepool/tangtest传过来了:
[root@inc-dba-gp-129-148 /storagepool/qpipe]#zfs list
NAME USED AVAIL REFER MOUNTPOINT
storagepool 30.2G 1.17T 2.68G /storagepool
storagepool/tangtest 59.6G 423G 59.6G /storagepool/tangtest
storagepool/tangtest@snap01 0 - 59.6G -
默认命令中是开启压缩的,使用zlib压缩级别2,可以通过-z参数指定压缩率,如果-z 0则关闭压缩。
默认是使用4个线程做压缩的,可以通过-t 参数指定压缩线程数。
qpipe的其它参数见帮助:
[host01]#./qpipe -h
Usage: qpipe [OPTION]
read data from stdin, and send to a command in remove server.
-s <server_ip>
in client mode, specify the server IP
-p <port>
in client mode, specify the server ip port,
in server mode, specify the server listen port
-c <cmd>
only can be used in client mode, specify the command run in server
-z <0-9>
specified compression level, between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all
-t <1-nn>
specified number of concurrent compress threads, default is 4
-b <blocksize>
specified block size, default is 4M
-l <loglevel>
loglevel, default loglevel is 3, 3 is 1(ERR_LOG)+2(INFO_LOG)
ERR_LOG: 1, INFO_LOG: 2, STAT_LOG: 4, DEBUG0_LOG: 8, DEBUG1_LOG: 16
-w <wait_seconds>
specified time of server wait client reconnect, default is 300 seconds
when beyond it ,then server close this session
-n <allow_ip_or_network>
only can be used in server mode, specify the specified client ipaddress or network can connect to server
-k <socket_buffer_size>
specified size of socket buffer,default is 1M
-h
help
Example:
qpipe -p 5000 -n 172.16.196.0/24
This command start server in 5000 port.
If you only specify a port option, program run in server mode, and listen on this port.
cat t.dat |qpipe -s 192.168.1.200 -p 5000 -c "cat >t2.dat"
This command send file t.dat to 192.168.1.200
|
|