【发布时间】:2018-06-21 08:04:05
【问题描述】:
我在这里尝试做的是将端口 3306 上机器一上的所有连接转发到端口 3306 上本地主机上的机器二。因此,如果您连接到机器一上的 mysql,它就像您正在连接在第二台机器上。
我认为 ssh 隧道应该转发特定端口上的流量,而不是像将我登录到另一台机器一样。 (就像它在这里做的那样)我试过在“@machine-two-hostname.com”之前没有“admin”,并且做同样的事情。正如标题所说,在后台运行它不会让我在“localhost”上连接,当我尝试在“绑定地址已在使用”的相同端口上设置另一个 ssh 隧道时,它确实给了我一条新消息。怀疑我在下面运行的命令也不起作用,但它只是将我登录到另一台机器而不连接端口。
admin@machine-one:~$ ssh -L 3306:localhost:3306 admin@machine-two-hostname.com
Linux machine-two 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/\*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Jun 20 11:16:07 2018 from 172.31.93.22
admin@machine-two:~$ mysql -uroot -proot-pass
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> \q
Bye
admin@machine-two:~$ exit
logout
Connection to machine-two-hostname.com closed.
admin@machine-one:~$ ssh -fN -L 3306:localhost:3306 admin@machine-two-hostname.com
admin@machine-one:~$ mysql -uroot -proot-pass
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
在后台运行:
admin@machine-one:~$ ssh -fN -L 3306:localhost:3306 machine-two-hostname.com
admin@machine-one:~$ mysql -uroot -proot-pass -hlocalhost
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
在后台运行时更新,当我使用 127.0.0.1 而不是 localhost 时,mysql 连接有效,为什么?
admin@machine-one:~$ mysql -uroot -proot-pass -hlocalhost
ERROR 2002 (HY000): Cant connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
admin@machine-one:~$ mysql -uroot -proot-pass -h127.0.0.1
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
【问题讨论】:
标签: mysql ssh ssh-tunnel