我正在尝试通过 ssh 隧道进行 mariadb 复制。这是我的配置。首先,我创建了一个从复制服务器 (R1) 到主服务器 (M1) 的 ssh 隧道。
ssh -L 13306:localhost:3306 -p 22111 admin@M1 -f -N
两个服务器上的 mariadb 实例都已运行。并且我已经在 M1 mariadb 实例上创建了一个复制用户。
CREATE USER 'replication'@'127.0.0.1' identified by 'xxxx';
GRANT REPLICATION SLAVE on *.* to 'replication'@'127.0.0.1' REQUIRE SSL;
从 R1 我检查是否可以连接到 M1 mariadb 实例。
mysql -u replication -pxxxx -h 127.0.0.1 --protocol=TCP -P 13306
上述操作成功。但是现在,当我指示复制实例 R1变更主控和启动从站, 它失败。
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='replication', MASTER_PASSWORD='xxxx', MASTER_PORT=13306, MASTER_LOG_FILE='mysql-bin.000022', MASTER_LOG_POS=9164599, MASTER_SSL=1, MASTER_SSL_CA='/etc/tls/ca-cert.pem', MASTER_SSL_CERT='/etc/tls/client-cert.pem', MASTER_SSL_KEY='/etc/tls/client-key.pem', MASTER_CONNECT_RETRY=10;
START SLAVE;
SHOW SLAVE STATUS \G
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 127.0.0.1
Master_User: replication
Master_Port: 13306
Connect_Retry: 10
Master_Log_File: mysql-bin.000022
Read_Master_Log_Pos: 9164599
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000022
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 9164599
Relay_Log_Space: 249
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: Yes
Master_SSL_CA_File: /etc/tls/ca-cert.pem
Master_SSL_CA_Path:
Master_SSL_Cert: /etc/tls/client-cert.pem
Master_SSL_Cipher:
Master_SSL_Key: /etc/tls/client-key.pem
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 2003
Last_IO_Error: error connecting to master '[email protected]:13306' - retry-time: 10 retries: 86400 message: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_SSL_Crl: /etc/tls/ca-cert.pem
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
1 row in set (0.00 sec)
非常欢迎任何指出错误配置的帮助。
问候,
阿舒托什·辛格
答案1
在使用 SELinux 的非标准端口时遇到了同样的问题。
需要确保您有检查 SELinux 管理工具的工具:
yum install -y setroubleshoot-server selinux-policy-devel
您可以通过运行以下命令检查 mysql 服务的允许端口:
semanage port -l | grep mysqld_port_t
然后您可以通过运行以下命令将端口添加到 mysql 服务:
semanage port -a -t mysqld_port_t -p tcp 13306
然后重新启动你的从机并且它应该连接。