ProxySQL读写分离
- master:172.16.16.35:
- slave:172.16.16.35:
- slave:172.16.16.34:
MHA manager在172.16.16.34,配置文件如下:
- [root@localhost bin]# cat /etc/masterha/app1.cnf
- [server default]
- manager_log=/var/log/mha/app1/manager.log
- manager_workdir=/var/log/mha/app1.log
- master_binlog_dir=/home/mysql/db3306/log/
- master_ip_failover_script=/usr/local/bin/master_ip_failover
- master_ip_online_change_script=/usr/local/bin/master_ip_online_change
- password=
- ping_interval=
- remote_workdir=/tmp
- repl_password=
- repl_user=root
- report_script=/usr/local/bin/send_report
- shutdown_script=""
- ssh_user=root
- user=root
- [server1]
- hostname=172.16.16.35
- port=
- [server2]
- candidate_master=
- check_repl_delay=
- hostname=172.16.16.34
- port=
- [server3]
- hostname=172.16.16.35
- port=
- [root@localhost bin]# sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
- [root@localhost bin]# yum install proxysql
- Installed:
- proxysql.x86_64 :1.3.-1.1.el6
- Complete!
- [root@localhost bin]# find / -name proxysql
- /var/lib/proxysql
- /var/run/proxysql
- /etc/rc.d/init.d/proxysql
- /usr/bin/proxysql
- [root@localhost bin]# cat /etc/proxysql-admin.cnf
- # proxysql admin interface credentials.
- export PROXYSQL_USERNAME="admin"
- export PROXYSQL_PASSWORD="admin"
- export PROXYSQL_HOSTNAME="localhost"
- export PROXYSQL_PORT=""
- # PXC admin credentials for connecting to pxc-cluster-node.
- export CLUSTER_USERNAME="admin"
- export CLUSTER_PASSWORD="admin"
- export CLUSTER_HOSTNAME="localhost"
- export CLUSTER_PORT=""
- # proxysql monitoring user. proxysql admin script will create this user in pxc to monitor pxc-nodes.
- export MONITOR_USERNAME="monitor"
- export MONITOR_PASSWORD="monit0r"
- # Application user to connect to pxc-node through proxysql
- export CLUSTER_APP_USERNAME="proxysql_user"
- export CLUSTER_APP_PASSWORD="passw0rd"
- # ProxySQL read/write hostgroup
- export WRITE_HOSTGROUP_ID=""
- export READ_HOSTGROUP_ID=""
- # ProxySQL read/write configuration mode.
- export MODE="singlewrite"
- [root@localhost bin]# proxysql-admin --config-file=/etc/proxysql-admin.cnf --enable
- This script will assist with configuring ProxySQL (currently only Percona XtraDB cluster in combination with ProxySQL is supported)
- ProxySQL read/write configuration mode is singlewrite
- ProxySQL is not running; please start the proxysql service
- [root@localhost bin]# service proxy
- proxy proxysql proxysql-admin proxysql_galera_checker proxysql_node_monitor
- [root@localhost bin]# service proxysql start
- Starting ProxySQL: DONE!
- [root@localhost bin]# mysql -uadmin -padmin -h127.0.0. -P6032
- mysql: [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
- Server version: 5.7. (ProxySQL Admin Module)
- Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql>
- [root@localhost bin]# find / -name proxysql.cnf
- /etc/proxysql.cnf
- [root@localhost bin]# mysql -uadmin -padmin -h127.0.0. -P6032
- mysql: [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
- Server version: 5.7. (ProxySQL Admin Module)
- Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> show databases;
- +-----+---------+-------------------------------+
- | seq | name | file |
- +-----+---------+-------------------------------+
- | | main | |
- | | disk | /var/lib/proxysql/proxysql.db |
- | | stats | |
- | | monitor | |
- +-----+---------+-------------------------------+
- rows in set (0.00 sec)
- mysql> use admin
- Database changed
- mysql> show tables;
- +--------------------------------------+
- | tables |
- +--------------------------------------+
- | global_variables |
- | mysql_collations |
- | mysql_query_rules |
- | mysql_replication_hostgroups |
- | mysql_servers |
- | mysql_users |
- | runtime_global_variables |
- | runtime_mysql_query_rules |
- | runtime_mysql_replication_hostgroups |
- | runtime_mysql_servers |
- | runtime_mysql_users |
- | runtime_scheduler |
- | scheduler |
- +--------------------------------------+
- rows in set (0.00 sec)
- mysql> insert into mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment) values(,'172.16.16.35',,,,,'test');
- Query OK, row affected (0.00 sec)
- mysql> insert into mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment) values(,'172.16.16.34',,,,,'test');
- Query OK, row affected (0.00 sec)
- mysql> insert into mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment) values(,'172.16.16.35',,,,,'test');
- Query OK, row affected (0.00 sec)
- mysql> select * from mysql_servers;
- +--------------+--------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
- | hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
- +--------------+--------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
- | | 172.16.16.35 | | ONLINE | | | | | | | test |
- | | 172.16.16.34 | | ONLINE | | | | | | | test |
- | | 172.16.16.35 | | ONLINE | | | | | | | test |
- +--------------+--------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
- rows in set (0.00 sec)
- mysql> insert into mysql_replication_hostgroups values(,,'masterha') ;
- Query OK, row affected (0.00 sec)
- mysql> select * from mysql_replication_hostgroups;
- +------------------+------------------+----------+
- | writer_hostgroup | reader_hostgroup | comment |
- +------------------+------------------+----------+
- | | | masterha |
- +------------------+------------------+----------+
- row in set (0.00 sec)
- mysql> GRANT SUPER, REPLICATION CLIENT ON *.* TO 'proxysql'@'172.16.16.%' IDENTIFIED BY 'proxysql';
- Query OK, rows affected, warning (0.09 sec)
- mysql> flush privileges;
- Query OK, rows affected (0.10 sec)
- mysql> set mysql-monitor_username='proxysql';
- Query OK, row affected (0.00 sec)
- mysql> set mysql-monitor_password='proxysql';
- Query OK, row affected (0.00 sec)
- mysql> load mysql variables to runtime;
- Query OK, rows affected (0.00 sec)
- mysql> save mysql variables to disk;
- Query OK, rows affected (0.02 sec)
- mysql> insert into mysql_users(username,password,active,default_hostgroup,transaction_persistent) values('root','',,,);
- Query OK, row affected (0.00 sec)
- mysql> select * from mysql_users;
- +----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
- | username | password | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections |
- +----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
- | root | | | | | NULL | | | | | | |
- +----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
- row in set (0.00 sec)
- mysql> load mysql servers to runtime;
- Query OK, rows affected (0.01 sec)
- mysql> save mysql servers to disk;
- Query OK, rows affected (0.08 sec)
- mysql> load mysql users to runtime;
- Query OK, rows affected (0.00 sec)
- mysql> save mysql users to disk;
- Query OK, rows affected (0.03 sec)
- mysql> INSERT INTO mysql_query_rules(active,match_pattern,destination_hostgroup,apply) VALUES(,'^SELECT.*FOR UPDATE$',,);
- Query OK, row affected (0.01 sec)
- mysql> INSERT INTO mysql_query_rules(active,match_pattern,destination_hostgroup,apply) VALUES(,'^SELECT',,);
- Query OK, row affected (0.00 sec)
- mysql> LOAD MYSQL QUERY RULES TO RUNTIME;
- Query OK, rows affected (0.00 sec)
- mysql> SAVE MYSQL QUERY RULES TO DISK;
- Query OK, rows affected (0.04 sec)
- [root@localhost ~]# mysql -uroot -p123456 -h172.16.16. -P6033
- mysql: [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
- Server version: 5.7. (ProxySQL)
- Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> select * from maxiangqian.test;
- +-----+------+
- | id | name |
- +-----+------+
- | | qq |
- | | qq |
- | | aa |
- | | a |
- | | a |
- +-----+------+
- rows in set (0.04 sec)
- mysql> select * from stats_mysql_query_digest;
- mysql> select @@server_id;
- +-------------+
- | @@server_id |
- +-------------+
- | |
- +-------------+
- row in set (0.01 sec)
- mysql> select * from maxiangqian.test for update;
- +-----+------+
- | id | name |
- +-----+------+
- | | qq |
- | | qq |
- | | aa |
- | | a |
- | | a |
- +-----+------+
- rows in set (0.00 sec)
- mysql> select * from stats_mysql_query_digest;
ProxySQL读写分离的更多相关文章
- MySQL ProxySQL读写分离实践
目的 在上一篇文章MySQL ProxySQL读写分离使用初探里初步介绍了ProxySQL的使用,本文继续介绍它的一些特点和DBProxy的性能差异.深入一些去了解ProxySQL,通过测试来说明Pr ...
- mysqlfailover高可用与proxysql读写分离配置
proxysql官方推荐两种高可用方案: 1.MHA+proxysql 2.mysqlrpladmin+proxysql MySQLfailover工具包含在mysqlrpladmin工具中,所以两者 ...
- MHA+ProxySQL 读写分离高可用
文档结构如下: 1.ProxySQL说明 ProxySQL是mysql的一款中间件的产品,是灵活的mysql代理层,可以实现读写分离,支持query路由器的功能,支持动态指定sql进行缓存,支持动态加 ...
- MySQL ProxySQL读写分离使用初探
目的 在美团点评DBProxy读写分离使用说明文章中已经说明了使用目的,本文介绍ProxySQL的使用方法以及和DBProxy的性能差异.具体的介绍可以看官网的相关说明,并且这个中间件也是percon ...
- ProxySQL 读写分离实践
前言 ProxySQL是一个高性能的MySQL中间件,拥有强大的规则引擎.具有以下特性: 连接池,而且是 multiplexing 主机和用户的最大连接数限制 自动下线后端DB 延迟超过阀值 ping ...
- Proxysql读写分离配置
ProxySQL是Percona主推的读写分离中间件,下载地址为: https://www.percona.com/downloads/proxysql/ 一.安装 1:下载 wget https:/ ...
- ProxySQL读写分离代理
实现ProxySQL反向代理Mysql读写分离 简介 ProxySQL相当于小型的数据库,在磁盘上有存放数据库的目录:ProxySQL用法和mysql相似 启动ProxySQL后会有两个监听端口: 6 ...
- ProxySQL 读写分离方法
转载自:https://www.jianshu.com/p/597b840bf70c (使用正则表达式实现基本的读/写分离) 在这一部分,我将通过一个示例来演示如何通过正则表达式来实现读/写分离. 首 ...
- ProxySQL读写分离测试(续)
Preface I've implemented ProxySQL on PXC yesterday but got some errors when configured query ...
随机推荐
- C# 文件操作系列一
在.Net环境中,所有关于文件操作的类都在System.IO命名空间下,注:在修改文件时,安全性显得格外重要,但是本随笔不过多讲述安全性,这里假设我们有足够的权限. 1.管理文件系统 先通过一幅图来了 ...
- 第一个hibernate程序HelloWorldHibernate
HelloWorldHibernate步骤: HelloWorld 1,新建java项目hibernate_0100_HelloWorld 2,学习User-library-hibernate,并加入 ...
- java面试题汇总(一)
1.MySQL之binlog底层原理分析:https://www.jianshu.com/p/e19d9312d1b5 2.redis持久化的几种方式https://www.cnblogs.com/A ...
- 《Algorithms算法》笔记:元素排序(4)——凸包问题
<Algorithms算法>笔记:元素排序(4)——凸包问题 Algorithms算法笔记元素排序4凸包问题 凸包问题 凸包问题的应用 凸包的几何性质 Graham 扫描算法 代码 凸包问 ...
- android Application类的详细介绍(转)
在代码中经常看到application这个类,一直不知道这个是干什么用的,今天刚好有点时间,所以进行了详细的学习. 一.先对它的整体概念解释: 在android源码中对他的描述是; * Base cl ...
- 各种数据库maven的pom文件编写与ibernate链接配置
各种数据库Hibernate链接配置 Derby db driver maven dependency <dependency> <groupId>org.ap ...
- %notfound的理解——oracle存储过程 .
文档中的解释:It returns TRUE if an INSERT, UPDATE, or DELETE statement affected no rows, or a SELECT INTO ...
- 非科班双非本科投的337家Java后台(励志)
考试结束,班级平均分只拿到了年级第二,班主任于是问道:大家都知道世界第一高峰珠穆朗玛峰,有人知道世界第二高峰是什么吗?正当班主任要继续发话,只听到角落默默想起来一个声音:”乔戈里峰” 前言 文章出自h ...
- Charles 抓取 iphone https的设置方式
1. Charles: help > SSL Proxying > Install Charles Root Certificate, 2. 将会打开 钥匙串访问 的功能,查找 Char ...
- webstorm 连接svn
先下个Slik-Subversion,安装好,在webstorm中setting中搜索Subversion,把上边安装的地址加上\svn.exe配置在Use command line client,然 ...