背景:

前面的2篇文章MySQL ProxySQL读写分离使用初探MySQL ProxySQL读写分离实践大致介绍了ProxySQL的使用说明,从文章的测试的例子中看到ProxySQL使用SQLITE来进行配置的持久化,以及ProxySQL是一个CPU密集型的中间价,如果CPU比较空闲,可以像MySQL一样安装多个实例的ProxySQL,充分利用资源。下面介绍下如何备份持久化的ProxySQL配置和多实例ProxySQL的创建。

多实例建立:

假设默认的实例已经装好了(6032、6033),现在需要新增一个新实例(ProxySQL2):7032,7033

1,添加配置文件:

cp /etc/proxysql.cnf /etc/proxysql2.cnf

2,修改配置文件:修改3行

datadir="/var/lib/proxysql2"
...
...
mysql_ifaces="127.0.0.1:7032;/tmp/proxysql_admin2.sock"
...
...
interfaces="0.0.0.0:7033;/tmp/proxysql2.sock"
...

3,添加启动文件:

cp /etc/init.d/proxysql /etc/init.d/proxysql2

4,修改启动文件:

OLDDATADIR="/var/run/proxysql2"
DATADIR="/var/lib/proxysql2"
OPTS="-c /etc/proxysql2.cnf -D $DATADIR" 修改成新的启动
sudo -u proxysql /usr/bin/proxysql2 $OPTS 修改2行:
for i in `pgrep proxysql` ; do
替换为:
for i in `pidof proxysql2` ; do
最后修改一些输出:
把echo输出的proxysql改成proxysql2

5,复制执行文件(懒的修改脚本了,直接复制新起一个执行文件...):

cp /usr/bin/proxysql /usr/bin/proxysql2

这里需要注意的是:需要修改默认实例的启动文件(/etc/init.d/proxysql)

修改2行:
for i in `pgrep proxysql` ; do
替换为:
for i in `pidof proxysql` ; do

即把pgrep改成pidof,这是因为通过pgrep找到了所有的proxysql实例的进程号,会引起误操作,单实例ProxySQL可以不需要考虑。

6,修改权限:

chown -R proxysql.proxysql proxysql2.cnf
chown -R proxysql.proxysql proxysql2/

7,开启实例:

root@dbproxy:/var/lib# /etc/init.d/proxysql2 start
Starting ProxySQL2: DONE!
root@dbproxy:/var/lib# ps -ef| grep proxy
proxysql May27 ? :: /usr/bin/proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql
proxysql May27 ? :: /usr/bin/proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql
proxysql : ? :: /usr/bin/proxysql2 -c /etc/proxysql2.cnf -D /var/lib/proxysql2
proxysql : ? :: /usr/bin/proxysql2 -c /etc/proxysql2.cnf -D /var/lib/proxysql2

查看端口信息:

root@dbproxy2:/var/lib# netstat -nltp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 127.0.0.1: 0.0.0.0:* LISTEN /proxysql
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql
tcp 0.0.0.0: 0.0.0.0:* LISTEN /sshd
tcp 127.0.0.1: 0.0.0.0:* LISTEN /proxysql2
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql2
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql2
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql2
tcp 0.0.0.0: 0.0.0.0:* LISTEN /proxysql2
tcp6 ::: :::* LISTEN /sshd

8:完成

root@dbproxy:/var/lib/proxysql2# /etc/init.d/proxysql2 stop
Shutting down ProxySQL2: DONE!
root@dbproxy:/var/lib/proxysql2# /etc/init.d/proxysql2 start
Starting ProxySQL2: DONE!
root@dbproxy:/var/lib/proxysql2# /etc/init.d/proxysql2 status
ProxySQL2 is running ().
root@dbproxy2:/var/lib/proxysql2# mysql -uadmin -padmin -h127.0.0. -P7032
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.5. (ProxySQL Admin Module) Copyright (c) - Percona LLC and/or its affiliates
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. admin@127.0.0.1 : (none) ::>select * from mysql_servers;
Empty set (0.00 sec) admin@127.0.0.1 : (none) ::>

到此,多实例已经建立成功,接着说明下如何对持久化的配置进行备份。

持久化配置备份

上面已经提到,ProxySQL的持久化是通过SQLITE实现的,对于备份就是对SQLITE的备份,关于如何使用SQLITE可以查看官方文档SQLite教程。这里大致的说明下sqlite以 SQL 文本格式转储数据。

1:先到指定的数据db目录

root@dbproxy:/var/lib/proxysql# ls -lh
-rw------- proxysql proxysql 33K May : proxysql.db
-rw------- proxysql proxysql 142K May : proxysql.log
-rw-r--r-- proxysql proxysql May : proxysql.pid

2:备份,执行.dump

root@dbproxy:/var/lib/proxysql# sqlite3 proxysql.db .dump > /home/dxy/proxysql.sql 

3,还原,若还原到另一个ProxySQL(上面安装的实例proxysql2)中,先保证目标proxysql.db文件不存在(需要关闭ProxySQL,删除数据目录里的所有文件)再执行:

root@dbproxy:~# /etc/init.d/proxysql2 stop
Shutting down ProxySQL2: DONE! root@dbproxy:/var/lib/proxysql2# ls -lh
total

在目标实例目录中执行:

root@dbproxy:/var/lib/proxysql2# sqlite3 proxysql.db < /home/dxy/proxysql.sql
root@dbproxy:/var/lib/proxysql2# ls -lh
total 32K
-rw-r--r-- root root 32K May : proxysql.db

开启实例:

root@dbproxy:/var/lib/proxysql2# /etc/init.d/proxysql2 start
Starting ProxySQL: DONE!
root@dbproxy:/var/lib/proxysql2# ls -lh
total 60K
-rw-r--r-- root root 32K May : proxysql.db
-rw------- proxysql proxysql 21K May : proxysql.log
-rw-r--r-- proxysql proxysql May : proxysql.pid #修改权限
root@dbproxy:/var/lib/proxysql2# chown -R proxysql.proxysql proxysql.db

说明:如果备份的实例和还原的实例使用的端口全部一致,则直接开启ProxySQL就可以用了。但本文的测试备份的实例的端口是6032和6033,还原的目标实例端口是7032和7033,即使还原了也不能使用,所以需要修改db文件,用sqlite连接修改:

#连接
root@dbproxy:/var/lib/proxysql2# sqlite3 proxysql.db #修改显示
sqlite> .header on
sqlite> .mode column #查看需要更新的变量
sqlite> select * from global_variables;
...
admin-mysql_ifaces 127.0.0.1:
...
mysql-interfaces 0.0.0.0:;/ #更新
sqlite> update global_variables set variable_value='127.0.0.1:7032' where variable_name = 'admin-mysql_ifaces';
sqlite> update global_variables set variable_value='0.0.0.0:7033;/' where variable_name = 'mysql-interfaces';

上面操作完成之后,再开启ProxySQL验证:

root@dbproxy:/var/lib/proxysql2# /etc/init.d/proxysql2 start
Starting ProxySQL2: DONE! oot@dbproxy2:/var/lib/proxysql2# mysql -uadmin -padmin -h127.0.0. -P7032
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.5. (ProxySQL Admin Module) Copyright (c) - Percona LLC and/or its affiliates
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. admin@127.0.0.1 : (none) ::>select * from mysql_users;
+-----------+-------------------------------------------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
| username | password | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections |
+-----------+-------------------------------------------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
| abc | *1AF30A6370D8959926FC3BD6158C9C551D0DBA28 | | | | | | | | | | |
| bcd | *F8258EA2FA1D7FE2B55DA522BFCC87B93CC63ADF | | | | | | | | | | |
+-----------+-------------------------------------------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
rows in set (0.00 sec) admin@127.0.0.1 : (none) ::>select * from mysql_servers;
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+-----------+
| hostgroup_id | hostname | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+-----------+
| | 192.168.20.123 | | ONLINE | | | | | | | ReadWrite |
| | 192.168.20.12 | | ONLINE | | | | | | | ReadOnly |
| | 192.168.20.123 | | ONLINE | | | | | | | ReadWrite |
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+-----------+
rows in set (0.00 sec)

从上面的结果看到,持久化备份和还原成功。注意:因为sqlite不支持远程备份,需要在本地备份好之后,再传到备份中心进行保存。

总结:

到此,关于ProxySQL的介绍告已段落,ProxySQL作者的更新还是比较勤快的,若后续有新功能和特性等,再进行补充说明,关于ProxySQL的文档请见:https://github.com/sysown/ProxySQL

MySQL ProxySQL相关维护说明的更多相关文章

  1. ProxySQL的相关维护说明

    背景: 前面的2篇文章MySQL ProxySQL读写分离使用初探和MySQL ProxySQL读写分离实践大致介绍了ProxySQL的使用说明,从文章的测试的例子中看到ProxySQL使用SQLIT ...

  2. Mysql优化相关总结

    Mysql优化相关总结 2016-05-31 数据库集中营 优化顺序: 选择适当的引擎和表结构和数据类型 建立索引,优化sql. 增加缓存,redis.memcache. 主从.主主,读写分离. my ...

  3. MySQL ProxySQL读写分离实践

    目的 在上一篇文章MySQL ProxySQL读写分离使用初探里初步介绍了ProxySQL的使用,本文继续介绍它的一些特点和DBProxy的性能差异.深入一些去了解ProxySQL,通过测试来说明Pr ...

  4. mysql数据库相关流程图/原理图

    mysql数据库相关流程图/原理图 1.mysql主从复制原理图 mysql主从复制原理是大厂后端的高频面试题,了解mysql主从复制原理非常有必要. 主从复制原理,简言之,就三步曲,如下: 主数据库 ...

  5. RDS MySQL 全文检索相关问题的处理

    RDS MySQL 全文检索相关问题 1. RDS MySQL 对全文检索的支持 2. RDS MySQL 全文检索相关参数 3. RDS MySQL 全文检索中文支持 3.1 MyISAM 引擎表 ...

  6. MySQL 权限相关

    # ============================= mysql 权限相关 =====================================================gran ...

  7. MySQL复制相关参数详解

    MySQL复制相关参数详解 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.复制相关系统变量 1>.server_id 是必须设置在master和每个slave上的唯一标 ...

  8. 自建YUM源以及相关维护

    yum相关概念我这里就不做详细的讲解了,就是一个软件包管理工具.在企业中,很多时候进行编译了自己的RPM包,在搭建YUM的时候,希望将自定义的RPM加入到YUM源中,从而出现了下列方法. 一.配置私有 ...

  9. MySQL库相关操作

    ========MySQL库相关操作====== 一.系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信 ...

随机推荐

  1. TCP协议中是如何保证报文可靠传输的

    1.什么是TCP的可靠传输 它向应用层提供的数据是无差错的.有序的.无丢失的,换言之就是:TCP最终递交给应用层的数据和发送者发送的数据是一模一样的. 2.TCP保证可靠传输的办法有哪些? TCP采用 ...

  2. SPA 单页面应用程序。

    看到这个问题,先说下自己的理解到的程度,再去参考做修正,争取这一次弄懂搞清楚 自己的理解: 单页面应用程序,解决浏览器获取数据刷新页面的尴尬,通过ajax请求获取数据达到异步更新视图的按钮,原理的实现 ...

  3. DP-01背包

    题目传送门 题目类似01背包,但存在一个选取先后不同价值会有损耗,所有对物品按易损耗的程度从大到小排个序来顺序选取. #include<bits/stdc++.h> using names ...

  4. c# 钩子类

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...

  5. 【RL-TCPnet网络教程】第29章 NTP网络时间协议基础知识

    第29章      NTP网络时间协议基础知识 本章节为大家讲解NTP (Network Time Protocol,网络时间协议)和SNTP(简单网络时间协议,Simple Network Time ...

  6. 阿里面试100%问到,JVM性能调优篇

    JVM 调优概述 性能定义 吞吐量 - 指不考虑 GC 引起的停顿时间或内存消耗,垃圾收集器能支撑应用达到的最高性能指标. 延迟 - 其度量标准是缩短由于垃圾啊收集引起的停顿时间或者完全消除因垃圾收集 ...

  7. 最小化JIT示例(仅限Intel x86+Windows)

    #include <Windows.h> #include <cstdint> #include <cstring> #define BACK_FILL (0) i ...

  8. [Swift]LeetCode470. 用 Rand7() 实现 Rand10() | Implement Rand10() Using Rand7()

    Given a function rand7 which generates a uniform random integer in the range 1 to 7, write a functio ...

  9. [Swift]LeetCode481. 神奇字符串 | Magical String

    A magical string S consists of only '1' and '2' and obeys the following rules: The string S is magic ...

  10. Spring设计模式_策略模式/其他

    策略模式特性 1.执行最终结果一样 2.执行过程和执行逻辑不一样 3.使用同一接口 达到目的就可以了 Git地址 https://github.com/wujiachengSH/WjcStrategy ...