美文网首页
ProxySQL手册_01安装使用

ProxySQL手册_01安装使用

作者: 这货不是王马勺 | 来源:发表于2021-10-11 11:29 被阅读0次

转载来自 骏马金龙 https://www.junmajinlong.com

适用于ProxySQL 1.4.4及之后版本

快速开始

安装

下载ProxySQL安装包: https://github.com/sysown/proxysql/releases
下载之后,使用操作系统的包管理器来安装它:

wget https://github.com/sysown/proxysql/releases/download/v1.4.9/proxysql_1.4.9-ubuntu16_amd64.deb
dpkg -i proxysql_1.4.9-ubuntu16_amd64.deb

也可以使用仓库来安装:
Ubuntu / Debian:
添加仓库:

apt-get install -y lsb-release
wget -O - 'http://repo.proxysql.com/ProxySQL/repo_pub_key' | apt-key add -
echo deb http://repo.proxysql.com/ProxySQL/proxysql-1.4.x/$(lsb_release -sc)/ ./ \
| tee /etc/apt/sources.list.d/proxysql.list

安装:

apt-get update
apt-get install proxysql OR apt-get install proxysql=version

Red Hat / CentOS:
添加仓库:

cat <<EOF | tee /etc/yum.repos.d/proxysql.repo
[proxysql_repo]
name= ProxySQL YUM repository
baseurl=http://repo.proxysql.com/ProxySQL/proxysql-1.4.x/centos/\$releasever
gpgcheck=1
gpgkey=http://repo.proxysql.com/ProxySQL/repo_pub_key
EOF

安装:

yum install proxysql OR yum install proxysql-version

ProxySQL服务管理

ProxySQL安装好后,可以使用 service 来启动和停止它:
启动 ProxySQL:

service proxysql start

停止 ProxySQL:

service proxysql stop

ProxySQL升级

只需安装新的ProxySQL版本然后重启即可:

wget https://github.com/sysown/proxysql/releases/download/v1.4.9/proxysql_1.4.9-ubuntu16_amd64.deb
dpkg -i proxysql_1.4.9-ubuntu16_amd64.deb
service proxysql restart

查看ProxySQL的版本

$ proxysql --version

在版本号中有 _DEBUG 字符串的表示它是调试版本。 调试版本比非调试版本要慢,但是在出现故障时更容易调试。
如:
Main init phase0 completed in 0.000146 secs.
ProxySQL version v1.4.9-1.1_DEBUG, codename Truls

通过admin interface配置ProxySQL

首先,请记住,配置ProxySQL的最佳方式是通过它的管理接口(admin interface)。这样可以通过SQL查询它的管理数据库实现在线配置(无需重启ProxySQL)。这种配置方式非常有效。
第二种配置方式是使用配置文件。

通过管理接口配置ProxySQL
可以使用mysql客户端来连接管理接口,以下是使用admin凭据连接到本地6032端口的管理接口:

$ mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
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 4
Server version: 5.5.30 (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.

Admin>

注意:如果你的MySQL客户端版本为8.04或更高版本,需要在上面连接到管理接口的命令行上加上--default-auth=mysql_native_password

连接到管理界面后,可以列出你允许使用SQL语言进行查询的数据库和表的列表:

Admin> SHOW DATABASES;
+-----+---------+-------------------------------+
| seq | name    | file                          |
+-----+---------+-------------------------------+
| 0   | main    |                               |
| 2   | disk    | /var/lib/proxysql/proxysql.db |
| 3   | stats   |                               |
| 4   | monitor |                               |
+-----+---------+-------------------------------+
4 rows in set (0.00 sec)

这些是你能控制的后端服务器节点,一些请求以及设置(如缓存、访问控制列表等)会路由到这些节点上。当在内存中修改了这些数据结构,必须为运行时环境加载新的配置,或者将设置持久化到磁盘(这样即使重启ProxySQL,这些配置也都还在)。关于管理接口配置ProxySQL更详细的内容,参见:https://github.com/malongshuai/proxysql/wiki/ProxySQL-Configuration

通过配置文件配置ProxySQL
尽管通过配置文件配置ProxySQL只是一种辅助方式,我们也无法忽略它的价值,因为引导新安装的ProxySQL的启动,需要它。
让我们快速浏览一下配置文件的主要部分(这个概述是对ProxySQL配置的一个非常高级的概述)。
顶级sections:

  • admin_variables:包含控制管理接口功能的全局变量。
  • mysql_variables:包含控制"处理MySQL流入流量功能"的全局变量。
  • mysql_servers:包含管理接口中mysql_servers表的行。它们定义了MySQL流量要路由到的后端服务器。行按照.cfg文件格式进行编写,例如:
 mysql_servers =
 (
    {
        address="127.0.0.1"
        port=3306
        hostgroup=0
        max_connections=200
    }
 )
  • mysql_users:包含管理接口中mysql_users表的行。它们定义了谁可以连接到ProxySQL,以及ProxySQL用哪个用户连接后端服务器。行按照.cfg文件格式进行编写,例如:
 mysql_users:
 (
    {
        username = "root"
        password = "root"
        default_hostgroup = 0
        max_connections=1000
        default_schema="information_schema"
        active = 1
    }
 )
  • mysql_query_rules:包含管理接口中mysql_query_rules表的行。它们根据各种标准(pattern匹配,执行查询的用户身份,等等)定义了对MySQL流量的分类和路由规则。行按照.cfg文件格式进行编写,例如(注意:这个示例是一个非常通用的查询路由规则,强烈建议创建专门的查询规则替代这个通用规则):
 mysql_query_rules:
 (
    {
        rule_id=1
        active=1
        match_pattern="^SELECT .* FOR UPDATE$"
        destination_hostgroup=0
        apply=1
    },
    {
        rule_id=2
        active=1
        match_pattern="^SELECT"
        destination_hostgroup=1
        apply=1
    }
 )
  • datadir:指定数据目录的路径。

相关文章

网友评论

      本文标题:ProxySQL手册_01安装使用

      本文链接:https://www.haomeiwen.com/subject/ebdloltx.html