mysql搭建及主从同步+读写分离

从库生成两个线程,一个I/O线程,一个SQL线程;i/o线程去请求主库 的binlog,并将得到的binlog日志写到relay log(中继日志) 文件中;
主库会生成一个 log dump 线程,用来给从库 i/o线程传binlog;
SQL 线程,会读取relay log文件中的日志,并解析成具体操作,来实现主从的操作一致,而最终数据一致;
规划 MySQL01
192.168.226.127
mysql02
192.168.226.128
mysql03
192.168.226.129
mysql04
【mysql搭建及主从同步+读写分离】192.168.226.130
centos7.6
mysql-5.7.17.tar
mysql-proxy-0.8.5-linux-debian6.0-x86-64bit.tar.gz
mysql01 主 mysql02从 mysql03 读写分离 mysql04测试机
mysql搭建1.解压[root@mysql01 ~]# lsanaconda-ks.cfgmysql-5.7.17.tar[root@mysql01 ~]# tar -xvf mysql-5.7.17.tar ./mysql-community-client-5.7.17-1.el7.x86_64.rpm./mysql-community-common-5.7.17-1.el7.x86_64.rpm./mysql-community-devel-5.7.17-1.el7.x86_64.rpm./mysql-community-embedded-5.7.17-1.el7.x86_64.rpm./mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm./mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm./mysql-community-libs-5.7.17-1.el7.x86_64.rpm./mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm./mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm./mysql-community-server-5.7.17-1.el7.x86_64.rpm./mysql-community-test-5.7.17-1.el7.x86_64.rpm2.安装[root@mysql01 ~]# lsanaconda-ks.cfgmysql-5.7.17.tarmysql-community-client-5.7.17-1.el7.x86_64.rpm#安装mysql-community-common-5.7.17-1.el7.x86_64.rpm#安装mysql-community-devel-5.7.17-1.el7.x86_64.rpmmysql-community-embedded-5.7.17-1.el7.x86_64.rpmmysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpmmysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpmmysql-community-libs-5.7.17-1.el7.x86_64.rpm#安装mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm#安装mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpmmysql-community-server-5.7.17-1.el7.x86_64.rpm#安装mysql-community-test-5.7.17-1.el7.x86_64.rpm[root@mysql01 ~]#yum install -y mysql-community-client-5.7.17-1.el7.x86_64.rpm mysql-community-common-5.7.17-1.el7.x86_64.rpm mysql-community-libs-5.7.17-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm mysql-community-server-5.7.17-1.el7.x86_64.rpm3.启动mysql服务[root@mysql01 ~]# systemctl start mysqld[root@mysql01 ~]# cat /var/log/mysqld.log | grep password2022-03-11T13:48:31.592028Z 1 [Note] A temporary password is generated for root@localhost: +i2yM_qvqtxj4 修改密码,否则不能正常使用[root@mysql01 ~]# mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: 初始密码The existing password for the user account root has expired. Please set a new password.New password:新密码Re-enter new password: 再次输入新密码Re-enter new password: The 'validate_password' plugin is installed on the server.The subsequent steps will run with the existing configurationof the plugin.Using existing password for root.Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) :... skipping.By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : ySuccess.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : ySuccess.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database...Success. - Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : ySuccess.All done!5 登录mysql[root@mysql01 ~]# mysql -uroot -p123qqq...Amysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.Commands end with ; or g.Your MySQL connection id is 6Server version: 5.7.17 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.mysql>主从搭建mysql01和mysql02完成以上数据库部署


推荐阅读