如果我们要 navicat 连接线上的数据库,一般不允许在本地直接连线上的数据库地址。一般配置 navicat 的 ssh 隧道实现先登上跳板机,再链接数据库。

可以 navicat 的 ssh 隧道只支持一级,如果是两层怎么办呢?这时候我们可以使用 ssh 端口转发。
1. ssh 端口转发
1.1 ssh config
例如我要去test服务器,去连接数据库,涉及到二级跳转。
1 2 3 4 5 6 7 8 9 10 11 12
| Host test HostName 172.31.58.22 Port 22 User web IdentityFile ~/.ssh/web.pem ProxyCommand ssh -q -x -W %h:%p jump
Host jump HostName 13.52.21.111 Port 22 IdentityFile ~/.ssh/fhyx User ubuntu
|
1.2 本地开启转发
1 2 3 4 5 6 7
| nohup ssh -fvNL localhost:3308:myk0c8.us-west-1.rds.com:3306 ubuntu@test &
nohup ssh -fvNL localhost:27018:localhost:27017 ubuntu@test &
|
1.3 navicat配置
只需要连接本地的3308端口就行,自动转发到 test 服务器的 myk0c8.us-west-1.rds.amazonaws.com:3306

2. 参考资料