centos7 mariadb主从复制配置搭建详解步骤

2019-10-12 16:08:36刘景俊

运行命令:rm -rf master.info,rm -rf *relay*

重启服务:[root@localhost mysql]# systemctl restart mariadb.service

进入mariadb:

[root@localhost mysql]# mysql -u root -padmin

MariaDB [(none)]> flush logs;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> reset slave;
Query OK, 0 rows affected (0.00 sec)

重新设置主从复制关系:

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='10.69.5.200',MASTER_USER='root', MASTER_PASSWORD='admin', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS= 694;
Query OK, 0 rows affected (0.02 sec)

这次成功了。

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.01 sec)

查看从库状态:

MariaDB [(none)]> show slave statusG
*************************** 1. row ***************************
        Slave_IO_State: Connecting to master
         Master_Host: 10.69.5.200
         Master_User: root
         Master_Port: 3306
        Connect_Retry: 60
       Master_Log_File: master-bin.000001
     Read_Master_Log_Pos: 694
        Relay_Log_File: relay-bin.000001
        Relay_Log_Pos: 4
    Relay_Master_Log_File: master-bin.000001
      Slave_IO_Running: Connecting
      Slave_SQL_Running: Yes
  ···
  ···
  ···
 Replicate_Ignore_Server_Ids: 
       Master_Server_Id: 0
1 row in set (0.00 sec)

发现问题2.Slave_IO_Running: Connecting

问题2.Slave_IO_Running: Connecting

查看错误日志

[root@localhost ~]# cat /var/log/mariadb/mariadb.log
···
160915 13:17:56 [Note] Slave SQL thread initialized, starting replication in log 'master-bin.000001' at position 694, relay log '/var/lib/mysql/relay-bin.000001' position: 4
160915 13:17:56 [ERROR] Slave I/O: error connecting to master 'root@10.69.5.200:3306' - retry-time: 60 retries: 86400 message: Can't connect to MySQL server on '10.69.5.200' (113), Error_code: 2003

这时运行telnet命令

[root@localhost ~]# telnet 10.69.5.200 3306

-bash: telnet: 未找到命令

安装telnet

[root@localhost ~]# yum -y install telnet-server.x86_64

安装成功后重启telnet服务

[root@localhost ~]# systemctl start telnet.socket
[root@localhost ~]# systemctl enable telnet.socket
[root@localhost ~]# telnet 10.69.5.200 3306

-bash: telnet: 未找到命令

还是不行

这回我reboot重启虚拟机,运行命令

注意:这回不是"yum -y install telnet-server.x86_64"了,这回没有telnet-server了

[root@localhost ~]# yum install telnet.x86_64

运行成功了

接着

[root@localhost ~]# systemctl enable telnet.socket
[root@localhost ~]# systemctl start telnet.socket
[root@localhost ~]# firewall-cmd --add-service=telnet --permanent 
success
[root@localhost ~]# telnet
telnet>