<p>横向扩展解决方案 - 在多个从站之间分配负载以提高性能。在此环境中,所有写入和更新都必须在主服务器上进行。但是,读取可以在一个或多个从设备上进行。该模型可以提高写入性能(因为主设备专用于更新),同时显着提高了越来越多的从设备的读取速度。</p>
讯享网
数据安全性 - 因为数据被复制到从站,并且从站可以暂停复制过程,所以可以在从站上运行备份服务而不会破坏相应的主数据。
分析 - 可以在主服务器上创建实时数据,而信息分析可以在从服务器上进行,而不会影响主服务器的性能。
备份 - 可以使用从服务器数据进行备份,减轻主服务器的压力。
清理环境
讯享网 rpm -qa | egrep “mysql|mariadb” yum -y erase `rpm -qa | egrep “mysql|mariadb”` && rm -f /etc.my* && rm -rf /var/lib/mysql && rm -f /var/log/mysqld.log [ ! -f /etc/my.cnf ] && [ ! -d /var/lib/mysql ] && [! -f /var/log/mysqld.log ] && echo “数据库清理完成” || echo “数据库文件存在”
配置主从
防火墙 selinux 主机名解析
主库
讯享网 #开启binlog、 [root@master ~]# vim /etc/my.cnf server_id=201 log_bin=/var/lib/mysql/binlog [root@master ~]# systemctl restart mysqld mysql> grant replication slave on . to ‘slave’@‘192.168.100.%’ identified by “Qianfeng@321”; mysql> flush privileges; mysql> show master status; +—————+———-+————–+——————+——————-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +—————+———-+————–+——————+——————-+ | binlog.000001 | 602 | | | | +—————+———-+————–+——————+——————-+
从库
mysql> CHANGE MASTER TO MASTER_HOST=‘master’, MASTER_USER=‘slave’, MASTER_PASSWORD=‘Qianfeng@321’, MASTER_PORT=3306, MASTER_LOG_FILE=‘binlog.000001’, MASTER_LOG_POS=602, MASTER_CONNECT_RETRY=10; mysql> start slave;
查看主从状态
讯享网 mysql> show slave statusG * 1. row * Slave_IO_State: Waiting for master to send event Master_Host: master Master_User: slave Master_Port: 3306 Connect_Retry: 10 Master_Log_File: binlog.000002 Read_Master_Log_Pos: 154 Relay_Log_File: slave-relay-bin.000002 Relay_Log_Pos: 317 Relay_Master_Log_File: binlog.000002 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: 154 Relay_Log_Space: 524 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: 201 Master_UUID: a3c4a11e-9278-11ef-9035-000c298a6e96 Master_Info_File: /var/lib/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: #重点关注第13 14行,两个Yes #重点关注第21 22行 #重点关注第35行 查看主从复制是否有延迟
重新配置主从【从库】
mysql> stop slave; mysql> reset slave; mysql> CHANGE MASTER TO MASTER_HOST=‘master’, MASTER_USER=‘slave’, MASTER_PASSWORD=‘Qianfeng@321’, MASTER_PORT=3306, MASTER_LOG_FILE=‘binlog.000001’, MASTER_LOG_POS=602, MASTER_CONNECT_RETRY=10; mysql> start slave; mysql> show slave statusG

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/174041.html