MySQL 复制通过 SSH 隧道

编程入门 行业动态 更新时间:2024-10-27 14:24:22
本文介绍了MySQL 复制通过 SSH 隧道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尽管花了很多时间阅读官方文档、文章和 SO 问题,但我还是无法通过 SSH 隧道设置复制.

I am having trouble setting up the replication via SSH tunnel despite many hours spent throught the official docs, articles and SO questions.

我的主人是192.168.0.105,奴隶是192.168.0.104.我已经通过以下方式设置了 SSH 隧道:

My master is 192.168.0.105 and the Slave is 192.168.0.104. I have already set up the SSH tunnel via:

ssh -L 3305:127.0.0.1:3306 tunneluser@192.168.0.105 -f -N

其中 tunneluser 是我的 ma​​ster 上的本地用户.

where tunneluser is a local user on my master.

我在从站上得到以下输出(省略了不相关的行):

I get the following output on a slave (omitted the irrelevant lines):

mysql> SHOW SLAVE STATUS \G *************************** 1. row *************************** Slave_IO_State: Connecting to master Master_Host: 127.0.0.1 Master_User: slave_user Master_Port: 3305 ... Slave_IO_Running: Connecting Slave_SQL_Running: Yes ... Last_IO_Errno: 2003 Last_IO_Error: error connecting to master 'slave_user@127.0.0.1:3305' - retry-time: 10 retries: 1 ... 1 row in set (0.00 sec)

让我困惑的部分是,如果我尝试:

The part that puzzles me is that if I try:

mysql -h 127.0.0.1 -P 3305 -u slave_user -p

它登录没有任何问题.我开始认为这与权限有关,但我找不到任何提示来证实我的理论.

It logs-in without any issues. I am beginning to think this has something to do with permissions, but I cannot find any hint to confirm my theory.

我尝试以 mysql 用户身份设置隧道,但是,效果不佳.没想到,但我不得不试一试.

I tried to setup the tunnel as mysql user, however, that did not work as well. Didn't really expect but I had to give it a shot.

有人对如何调试这个有任何建议吗?

如果我直接通过端口 3306,它可以正常工作.

If I go directly through port 3306, it works without any issue.

推荐答案

好几天后,我在ServerFault上发现了一个类似的问题:

Well after several days, I found a similar question on ServerFault:

MySQL 复制通过 SSH - Last_IO_Errno: 2003 - 连接到 master 时出错

结果 SELinux 不得不用这个来做所有的事情!正如 @Tek Jau 所解释的,您可以通过 semanage 添加这个自定义端口来解决这个问题:

It turned out SELinux had to do everything with this! As @Tek Jau explained, you can tackle this by adding this custom port via semanage:

sudo /usr/sbin/semanage port -a -t mysqld_port_t -p tcp 3305

希望这可以帮助任何偶然发现类似问题的人.

Hope this helps anyone who stumbles upon similar issue.

更多推荐

MySQL 复制通过 SSH 隧道

本文发布于:2023-10-07 12:37:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:隧道   MySQL   SSH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!