免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1526 | 回复: 0
打印 上一主题 下一主题

SSH Tunnels speed up PG data transport in WAN [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:42 |只看该作者 |倒序浏览
SSH Tunnels Compression speed up PostgreSQL data transport in WAN environment 
STEP1. create ssh tunnels between remote db and local db

ssh -C -L 8888:127.0.0.1:5432 postgres@remote_ip

STEP2. open another shell window run as below:

postgres@bsmart-server1:~> date +%F%T;psql -h 127.0.0.1 -p 8888 -U postgres BMCV3_Archive -c "copy (select * from tblbmc_bat_activity_info_201105 limit 100000) to stdout" > /home/bsmart01/test1.dump;date +%F%T
2011-06-2720:20:31
2011-06-2720:24:19

cost : 0:03:48

not use the tunnels
postgres@bsmart-server1:~> date +%F%T;psql -h remote_ip -p 5432 -U postgres BMCV3_Archive -c "copy (select * from tblbmc_bat_activity_info_201105 limit 100000) to stdout" > /home/bsmart01/test2.dump;date +%F%T
2011-06-2720:36:51
2011-06-2720:47:30

cost : 0:10:39

If you try as above, you will found the tunnel running as foreground, if your terminal quit, the tunnel will close. 

another way, you can try tunnel server in background,


Step 1. useradd -m tunnel @ server C & server D

Step 2. create trust in servers 
Server C: 
su - tunnel
create ssh key : $  ssh-keygen 
cd ~/.ssh
put the id_rsa.pub into  Server D : ~/.ssh/authorized_keys

note: 
~ -- user "tunnel" home folder

Step 3. create tunnels
Server C:
ssh -CNf -p 22 -L *:9991:202.9.98.41:5432 tunnel@server_D_IP
ssh -CNf -p 22 -L *:9992:202.9.98.42:5432 tunnel@server_D_IP

simple way:  server_A --> server_41
ssh -CNf -p 22 -L *:6666:*:5432 tunnel@202.9.98.41

Now, you try it 
connect server_C_IP:9991  means connect to 202.9.98.41:5432
connect server_C_IP:9992  means connect to 202.9.98.42:5432


About OS & kernel setting:
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait=120
net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait=60
net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait=120
net.ipv4.tcp_keepalive_intvl=1
net.ipv4.tcp_keepalive_probes=6
net.ipv4.tcp_keepalive_time=1

Reference:
man ssh
man ssh_config


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP