ProxySQL

发布时间 2023-04-18 16:11:51作者: igoodful

#################

ProxySQL是一款高性能、高可用性的SQL代理服务器,可以作为数据库中间件,在MySQL集群中提供负载均衡、故障转移、读写分离等功能。ProxySQL的配置包含多个方面,下面是一个简单的ProxySQL配置示例,介绍了一些基本配置项:

 

# 启用ProxySQL的日志功能
log_level = debug

# 监听的本地IP地址和端口
admin_variables =
{
    admin_credentials = 'admin:admin'
    mysql_ifaces = '0.0.0.0:6032'
}

# 集群节点的配置
mysql_servers =
{
    # 读写分离的主节点
    {   
        hostgroup_id = 10
        hostname = 'master.example.com'
        port = 3306
        weight = 100
        max_connections = 1000
    },
    # 读写分离的从节点
    {
        hostgroup_id = 20
        hostname = 'slave.example.com'
        port = 3306
        weight = 100
        max_connections = 1000
    },
    # 只读节点
    {
        hostgroup_id = 30
        hostname = 'readonly.example.com'
        port = 3306
        weight = 100
        max_connections = 1000
    }
}

# 配置SQL查询规则
mysql_query_rules =
(
    # 根据查询类型和表名选择不同的节点
    {
        rule_id = 10
        active = 1
        match_pattern = '^SELECT .* FROM table1'
        destination_hostgroup = IFNULL(nullif(substring_index(user(),'@',-1),''),10)
        apply = 1
    },
    {
        rule_id = 20
        active = 1
        match_pattern = '^SELECT .* FROM table2'
        destination_hostgroup = IFNULL(nullif(substring_index(user(),'@',-1),''),20)
        apply = 1
    },
    # 根据客户端IP地址选择不同的节点
    {
        rule_id = 30
        active = 1
        match_pattern = '.*'
        destination_hostgroup = IF(client_ip IN ('192.168.1.1','192.168.1.2'), 30, 10)
        apply = 1
    }
)

 

这个配置文件包含了ProxySQL的一些基本配置项:

  1. log_level:指定ProxySQL的日志级别,可以是debug、info、notice、warning、error、critical或alert。

  2. admin_variables:指定ProxySQL监听的IP地址和端口,用于管理ProxySQL。这里监听了所有网卡的6032端口,并使用了默认的管理账号admin/admin。

  3. mysql_servers:指定ProxySQL管理的MySQL节点,包括主节点、从节点和只读节点,每个节点需要指定hostgroup_id、hostname、port、weight和max_connections等参数。

  4. mysql_query_rules:指定ProxySQL的SQL查询规则,可以根据查询类型、表名、客户端IP地址等条件选择不同的MySQL节点,包括rule_id、active、match_pattern、destination_hostgroup和apply等参数。

这只是一个简单的ProxySQL配置

 

 

 

 

 

 

 

 

 

 

 

 

 

 

#################################