三度网教程:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

ProxySQL读写分离从设置到运用

时间:2023-4-19作者:未知来源:三度网教程人气:


SQL是Structured Query Language(结构化查询语言)的缩写。SQL是专为数据库而建立的操作命令集,是一种功能齐全的数据库语言。在使用它时,只需要发出“做什么”的命令,“怎么做”是不用使用者考虑的。SQL功能强大、简单易学、使用方便,已经成为了数据库操作的基础,并且现在几乎所有的数据库均支持SQL。
在美团点评DBProxy读写分离使用说明文章中已经说明了使用目的,本文介绍ProxySQL的使用方法以及和DBProxy的性能差异。具体的介绍可以看官网的相关说明,并且这个中间件也是percona推的一款中间件。其特性和其他读写分离的中间件差距不大,具体的会在文中介绍。本文大致简单的介绍在使用过程中的一些说明,也可以看官方的wiki获得使用帮助。

环境:

Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04Codename: trusty

下载

percona站点:

https://www.percona.com/downloads/proxysql/

github/官网:

https://github.com/sysown/proxysql/releases



我们首先看一下自己的环境:

MHA已经搭建:
master:172.16.16.35:3306slave:172.16.16.35:3307slave:172.16.16.34:3307

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=123456ping_interval=1remote_workdir=/tmp repl_password=123456repl_user=root report_script=/usr/local/bin/send_report shutdown_script=""ssh_user=root user=root [server1] hostname=172.16.16.35port=3306[server2] candidate_master=1check_repl_delay=0hostname=172.16.16.34port=3306[server3] hostname=172.16.16.35port=3307

下面我们基于这样一套MHA环境搭建读写分离。
1:安装ProxySQL软件,这个我们部署到172.16.16.34上
[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 0:1.3.7-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

发现确实已经将ProxySQL安装成功了
2:启动配置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="6032" # PXC admin credentials for connecting to pxc-cluster-node. export CLUSTER_USERNAME="admin"export CLUSTER_PASSWORD="admin"export CLUSTER_HOSTNAME="localhost"export CLUSTER_PORT="3306" # 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="10"export READ_HOSTGROUP_ID="11" # 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

现在来说ProxySQL 的路由已经启动,提示我们要启动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.1 -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 1Server version: 5.7.14 (ProxySQL Admin Module) Copyright (c) 2000, 2016, 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>

可以看到我们已经登录成功了,这里要说明的是 proxysql的默认配置文件是在:
[root@localhost bin]# find / -name proxysql.cnf/etc/proxysql.cnf

接下来我们开始配置ProxySQL:
[root@localhost bin]# mysql -uadmin -padmin -h127.0.0.1 -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 2Server version: 5.7.14 (ProxySQL Admin Module) Copyright (c) 2000, 2016, 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;+-----+---------+-------------------------------+

关键词:  ProxySQL读写分离从设置到运用





Copyright © 2012-2018 三度网教程(http://www.3du8.cn) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版