- 論壇徽章:
- 3
|
qpipe是我寫的一個在Unix機器上通過管道可靠傳數據的工具。此工具開發(fā)的初衷是為了在生產中心和容災中心傳ZFS文件系統(tǒng)快照來使用了。我開始使用ssh來做管道來傳ZFS快照,但當網絡不好時容易hang,同時發(fā)現ssh帶寬在千兆網上只能到達50MBbytes/s,就再不高不上去了,同時還很占用CPU。我寫的這個工具有以下幾個功能:
1. 當網絡不穩(wěn)定,TCP連接斷了后,可以重連。
2. 相比ssh,占用CPU低。
3.有壓縮功能,為了提高壓縮速度,可以使用多線程壓縮,線程數可以由參數指定。
在Solaris平臺上已使用了很長一段時間,運行一直穩(wěn)定。
下面介紹使用方法:
此工具分服務端和客戶端,而程序只有這一個,當指定不同的參數時,程序會以服務端運行或以客戶端模式運行。
在服務器端,運行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 指定了在服務端接收數據的程序。上面的命令就如同在本機上執(zhí)行:
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文件系統(tǒng)傳送到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%
....
....
等命令執(zhí)行完后,到host02上可以看到文件系統(tǒng)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
|
|