zoukankan      html  css  js  c++  java
  • proxysql 系列 ~ 读写分离核心功能

    零 安装 

       1 参考 https://github.com/sysown/proxysql 即可 现在最新版本为proxysql 2.X

    一 配置读写分离表
       1 mysql_user 列表配置 -》配置程序账号
           1 username && password 账号密码
           2 default_hostgroup 写hostgroup_id
           3 transaction_persistent 保证了同一个事务中所有的语句都会路由到同一组示例
        2 mysql_servers DB列表配置 
          该表的主键是hostgroup_id+hostname+port
         1 hostgroup_id
            1 不同功能不同hostgroup_id(写hostgroup_id,读hostgroup_id)
         2 status 集群健康情况
             ONLINE:当前后端实例状态正常。
             SHUNNED:临时被剔除,可能因为后端too many connection error,或者超过了max_replication_lag。
             OFFLINE_SOFT:软离线状态,不再接受新的连接,但已建立的连接会等待活跃事务完成。
             OFFLINE_HARD:硬离线状态,不再接受新的连接,已建立的连接或被强制中断,当后端实例宕机或网络不可达,会出现。
         3 max_replication_lag 设置延迟判断
         4 weight 权重比,默认为1,权重越大优先级越高
         5 max_connections 最大连接数(不要大于mysql的max_connections)
    3 mysql_query_rules列表配置
       1 active 是否启用(默认启用)
       2 match_pattern 具体的匹配规则
           1 ^SELECT ->只转发select 读hostgroup_id
           2 ^SELECT.*FOR UPDATE$ select for update是需要修改数据的,所以要定向到主库 写hostgroup_id
      3 apply 是否应用 (默认应用)
    二 创建相关账号
      1 监控账号权限需要 SUPER, REPLICATION CLIENT
         set mysql-monitor_username='proxysql';set mysql-monitor_password='proxysql';
        通过日志观测监控账号是否正常监控mysql复制进程
      2 程序账号权限需要 update,delete,insert,select,create
    三 常规配置加载操作
      //实时加载
       load mysql servers to runtime; 
       load mysql users to runtime; 
       load mysql variables to runtime; 
       load mysql query rules to runtime;
     //刷新到磁盘
       save mysql servers to disk;
       save mysql users to disk;
       save mysql variables to disk;
       save mysql query rules to disk;
    四 查看读写分离情况
      stats_mysql_query_digest表记载着读写分离的具体操作

      show tables  from  db  通过这种方式查询对应的表,用use-show tables方式没法看

      select * from runtime_global_variables   where variable_name=‘’  通过这种方式查询实时变量
    五 proxysql 权重与 读写
      在mysql_servers中新添加一条记录,标明主库配置读hostgroup_id,weight低于其他从库,这样做的目的就是当两个从库都出现问题时,主库提供读服务

    六 端口

         服务端口 6023 程序端口6033
    七 标准插入语句
      mysql_user
      insert into mysql_users(username,password,active,default_hostgroup,transaction_persistent)values('user','pwd',1,w-hostgrop-id,1);
      mysql_server
      insert into mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment) values(w-hostgroup-id,'MASTER-IP',PORT,1,MAX_CONNECTIONS,10,'test my proxysql');
      insert into mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment) values(r-hostgroup-id,'MASTER-IP',3306,weight,MAX_CONNECTIONS,10,'test my proxysql');
      insert into mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment)values(r-hostgroup-id,,'Slave-IP',3306,weight+1,MAX_CONNECTIONS,10,'test my proxysql');
      insert into mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment)values(r-hostgroup-id,,'Slave-IP',3306,weight+1,MAX_CONNECTIONS,10,'test my proxysql');
      mysql_query_rules
      INSERT INTO mysql_query_rules(active,match_pattern,destination_hostgroup,apply) VALUES(1,'^SELECT.*FOR UPDATE$',w-hostgroup-id,1);
      INSERT INTO mysql_query_rules(active,match_pattern,destination_hostgroup,apply)VALUES(2,'^SELECT',r-hostgroup-id,1);

      set mysql-monitor_username='proxysql';set mysql-monitor_password='proxysql';

    八 操作
      1 GRANT SUPER,REPLICATION CLIENT ON *.* TO 'proxysql' IDENTIFIED BY 'proxysql';
      2 mysql -uadmin -padmin -h127.0.0.1 -P6032 登录proxysql
      3 常规配置加载操作

  • 相关阅读:
    HDU 1058 Humble Numbers
    HDU 1160 FatMouse's Speed
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1003 Max Sum
    HDU 1297 Children’s Queue
    UVA1584环状序列 Circular Sequence
    UVA442 矩阵链乘 Matrix Chain Multiplication
    DjangoModels修改后出现You are trying to add a non-nullable field 'download' to book without a default; we can't do that (the database needs something to populate existing rows). Please select a fix:
    opencv做的简单播放器
    c++文件流输入输出
  • 原文地址:https://www.cnblogs.com/danhuangpai/p/11577884.html
Copyright © 2011-2022 走看看