mysql+mycat 实现读写分离

    xiaoxiao2021-12-14  18

    Prepare: 二台linux(CentOS7)服务器(IP:192.168.82.252,192.168.82.86) mycat安装包 mysql-community-release-el7-5

    Begin: 安装mysql,二台服务器做相同的操作

    ## 下载 $ > wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm $ > rpm -ivh mysql-community-release-el7-5.noarch.rpm ## 安装 $ > yum install mysql-community-server ## 启动mysql $ > systemctl start mysqld.service ## 修改密码 $ > mysqladmin -u root password 1q2w3e4r ## 关闭防火墙 $ > systemctl stop firewalld.service; ##连接mycql $ > mysql -u root -p ##授权远程连接 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1q2w3e4r' WITH GRANT OPTION; FLUSH PRIVILEGES;

    修改master(252) mysql配置(my.cnf)

    $ > vi /etc/my.cnf ## 在[mysqld]下添加一下内容 log-bin=mysql-bin server-id=252 innodb_flush_log_at_trx_commit=1

    修改slave(86) mysql配置(my.cnf)

    $ > vi /etc/my.cnf ## 在[mysqld]下添加一下内容 log-bin=mysql-bin server-id=86

    修改完成后重启

    $ > systemctl restart mysqld.service

    在master上建立账号并授权slave

    $ > mysql -u root -p mysql > create user 'toslave'@'192.168.82.252' identified by '1q2w3e4r'; mysql > GRANT REPLICATION SLAVE ON *.* to 'toslave'@'192.168.82.252' identified by '1q2w3e4r'; mysql > flush privileges;

    查看master状态

    mysql > show master status;

    slave(86)下执行命令

    ## 暂停slave mysql > stop slave; ## 充值slave mysql > reset slave; ## 设置连接master mysql > change master to master_host='192.168.82.252',master_user='toslave',master_password='1q2w3e4r', master_log_file='mysql-bin.000003',master_log_pos=536699534; ## 启动slave mysql > start slave; ## 查看slave状态 mysql > show slave status\G;

    连接成功,环境搭建完成。

    测试 在master上创建数据库

    mysql > create database id not exists t_cat default charset utf8 collate utf8_general_ci; mysql > show databases;

    slave查询

    测试master上建表插入数据操作,salve 均能同步到操作;

    搭建mycat

    下载mycat(地址:http://download.csdn.net/detail/once520/9699574) 解压

    $ > tar zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

    mycat配置

    ## 到conf目录下 $ > cd mycat/conf

    简化的schema.xml配置如下:

    $ > bin/mycat start

    启动过程中出现问题可以查看日志

    待续。。。。。。

    转载请注明原文地址: https://ju.6miu.com/read-962203.html

    最新回复(0)