部署myaql主从异步复制

准备三台主机

192.168.200.10

192.168.200.11

192.168.200.12

所有机器上的操作

Systemctl stop firewalld

Setenforce 0

Iptables -F

在Mysql master 上配置NTP时间同步服务器

三台主机都安装 mariadb   mariadb-server ntp

yum -y install mariadb

yum -y install mariadb-server

yum -y install ntp

[root@localhost ~]# ntpdate 192.168.200.10

在第一台主机上

vim /etc/ntp.conf 添加两行

server 127.127.1.0

fudge 127.127.1.0 straturn 8

[root@localhost ~]# systemctl start ntpdate

Job for ntpdate.service failed. See 'systemctl status ntpdate.service' and 'journalctl -xn' for details.

[root@localhost ~]# systemctl enable ntp

Failed to issue method call: No such file or directory

[root@localhost ~]# systemctl start ntp

Failed to issue method call: Unit ntp.service failed to load: No such file or directory.

[root@localhost ~]# vim /etc/my.cnf

[mysqld]

server-id=1

log-bin=mysql-binlog

log-slave-updates=true

[root@localhost ~]# systemctl restart mariadb

[root@localhost ~]# netstat -lnpt | grep :3306

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      38391/mysqld    

[root@localhost ~]# mysql

MariaDB [(none)]> grant replication slave on *.* to 'myslave'@'192.168.200.1_' identified by '123456';

Query OK, 0 rows affected (0.16 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show master status;

+---------------------+----------+--------------+------------------+

| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+---------------------+----------+--------------+------------------+

| mysql-binlog.000001 |      478 |              |                  |

+---------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.38 sec)

启动NTP服务

[root@localhost ~]# systemctl enable ntp

Failed to issue method call: No such file or directory

[root@localhost ~]# systemctl start ntp

Failed to issue method call: Unit ntp.service failed to load: No such file or directory.

 

另外两台主机192.168.200.11

             192.168.200.12

从库连接主库进行测试,如果连接成功说明主库配置成功

[root@localhost ~]# mysql -u myslave -p123456 -h192.168.200.10

修改MYSQL配置文件(192.168.200.11)

[root@localhost ~]# vim /etc/my.cnf

[mysqld]

server-id=2

log-bin=mysql-binlog

log-slave-updates=true

修改MYSQL配置文件(192.168.200.12)

[root@localhost ~]# vim /etc/my.cnf

[mysqld]

server-id=3

log-bin=mysql-binlog

log-slave-updates=true

修改完成后重启数据库

[root@localhost ~]# systemctl restart mariadb

在slave服务器授权,启动从库,进行主从数据同步

[root@localhost ~]# mysql

MariaDB [(none)]> stop slave;

Query OK, 0 rows affected, 1 warning (0.00 sec)

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='192.168.200.10', MASTER_USER='myslave', MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-binlog.000001', MASTER_LOG_POS=478;

Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> start slave;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show slave statusG

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.200.10

                  Master_User: myslave

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-binlog.000001

          Read_Master_Log_Pos: 478

               Relay_Log_File: relay-log-bin.000002

                Relay_Log_Pos: 532

        Relay_Master_Log_File: mysql-binlog.000001

             Slave_IO_Running: Yes

            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: 478

              Relay_Log_Space: 824

              Until_Condition: None

               Until_Log_File:

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File:

           Master_SSL_CA_Path:

              Master_SSL_Cert:

            Master_SSL_Cipher:

               Master_SSL_Key:

        Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_SQL_Errno: 0

               Last_SQL_Error:

  Replicate_Ignore_Server_Ids:

             Master_Server_Id: 1

1 row in set (0.10 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.38 sec)

原文地址:https://www.cnblogs.com/liyurui/p/11740552.html