zoukankan      html  css  js  c++  java
  • 基于Atlas实现读写分离

    mysql-proxy是官方提供的mysql中间件产品可以实现负载平衡,读写分离,等,但其不支持大数据量的分库分表且性能较差。下面介绍几款能代替其的mysql开源中间件产品:Atlas,tddl,Mycat。 

    环境准备:

    关闭所有防火墙

    192.168.200.111       master

    192.168.200.112      slave1

    192.168.200.113      slave2

    192.168.200.114      Atlas

    192.168.200.115     客户端

    先实现MySQL数据库的主从复制

    mysql主机允许Atlas远程连接

    mysql> grant all on *.* to 'admin'@'192.168.200.%' identified by '123123';

    mysql> flush privileges;

    Atlas主机:

    rpm -vih https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm
    #注意操作系统的版本,安装相应版本的Atlas。

    cd /usr/local/mysql-proxy/bin/

    ./encrypt 123123

    ++gAN07C/Q0=

    cd /usr/local/mysql-proxy/ # Atlas的安装目录

    vim conf/test.cnf

    [mysql-proxy]
    admin-username = user
    admin-password = pwd
    proxy-backend-addresses = 192.168.200.111:3306        #主服务器IP地址
    proxy-read-only-backend-addresses = 192.168.200.112:3306,192.168.200.113:3306          ##从服务器
    pwds = admin:++gAN07C/Q0=                    ##对应上面加密的密码,跟主服务器设置一致
    daemon = true
    keepalive = true
    event-threads = 8
    log-level = message
    log-path = /usr/local/mysql-proxy/log
    sql-log = REALTIME
    proxy-address = 0.0.0.0:1234
    admin-address = 0.0.0.0:2345

    用户名与其对应的加密过的MySQL密码,密码使用安装路径 /bin目录下的加密程序encrypt加密,用户名与密码之间用冒号分隔。主从数据库上需要先创建该用户并设置密码(用户名和密码在主从数据库上要一致)。

    3、运行Atlas

      进入/usr/local/mysql-proxy/bin目录,执行下面的命令启动、重启或停止Atlas。

    ./mysql-proxyd test start #启动Atlas。
    OK: MySQL-Proxy of test is started

    ./mysql-proxyd test restart #重启Atlas。

    ./mysql-proxyd test stop #停止Atlas。

    测试:

    此时的三台MySQL服务器是主从备份

    在mysql-master 创建db_test 库及该库下的test表

    MariaDB [(none)]> create database db_test;

    MariaDB [db_test]> create table test(id int(10),name varchar(20));

    可以在112和113上查看该库

    show  databases;

    在112和113 服务器上停止主从备份

    MariaDB [(none)]> stop slave;

    在111上添加表内容

    MariaDB [db_test]> insert into test values('1','master');

    此前在服务器上同步了表,所以在从服务器上可以直接手动插入其他内容

    在slave1 上:

    MariaDB [(none)]> insert into db_test.test values('2','slave1');

    在slave2上:

    MariaDB [(none)]> insert into db_test.test values('3','slave2');

    在115上测试

    [root@localhost ~]# yum -y install mariadb 或者mysql

    mysql -uadmin -p123123 -h 192.168.200.114 -P1234

    (1) 读测试

    2)写测试:

    MySQL [(none)]> insert into db_test.test values('4','clieent');

    在master服务器上查看是否写入:

     

     -------------------------------------------------

    详情请看

    https://blog.csdn.net/fgf00/article/details/50599814

  • 相关阅读:
    BZOJ 3626: [LNOI2014]LCA(树链剖分+离线处理)
    python备用
    STL的使用。。备忘
    DP专题
    任务
    hdu 网络流题集
    hdu KM匹配题集
    hdu 差分约束题集
    hdu 2sat题集
    Codeforces Round #261 (Div. 2)
  • 原文地址:https://www.cnblogs.com/maoyanqing/p/11686516.html
Copyright © 2011-2022 走看看