AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 286204
Accepted
Amit P
Amit P
Asked: 2021-03-01 23:22:28 +0800 CST2021-03-01 23:22:28 +0800 CST 2021-03-01 23:22:28 +0800 CST

如何使用 MaxScale 限制不良应用程序对 MariaDB Galera 集群的影响?

  • 772

我有一个具有三个 MariaDB 节点的 Galera Replication 集群,其中前面的 Maxscale Active-Passive 集群为 tis 客户端提供单节点映像。

我有一个行为不端的客户端,它打开连接而不关闭它们。在数据库限制达到之前,连接数一直在增加。为了限制我在两个参数下配置的连接数

max_connections=
max_user_connections=

我的情况是这样,当我只配置了 max_connections 时,只要达到限制,Galera 节点就会停止接受更多连接,并出现“连接太多”错误。当 Maxscale 看到此连接拒绝 n 次时,它会将服务器置于维护模式。我可以理解这种行为,这是意料之中的。当我配置 max_user_connections 时,由于应用程序表现不佳并尝试不断建立新连接,当用户特定限制达到进一步的连接尝试时,后端的 mariadb 节点会失败。Maxscale 观察到这些故障,并再次将服务器置于维护模式。我相信在这段时间内它只会看到来自坏客户端的连接尝试,没有其他应用程序尝试连接。

通过这种方式,MaxScale 会随着时间的推移将所有三个节点都置于维护模式,这使得完整的数据库服务不可用。

对于作为管理员的我来说,情况变得相同,设置用户特定的限制并不能实现任何目标。这里想问两点

Q1。如何防止只有一个用户连接失败将后端 mariadb 节点投入维护?

Q2。关于 MaxScale 如何以及何时决定将服务器置于维护模式的任何文档或教程、文章参考?

以下是有关环境的详细信息

Galera - 25.3.23,MariaDB - 10.3.12,MaxScale - 2.4.11,操作系统 - RHEL 7.4 (Maipo)

这是我的配置

MariaDB Galera 配置

[server]

# this is only for the mysqld standalone daemon
[mysqld]
#user statistics
userstat=1
performance_schema
#wait_timeout=600
max_allowed_packet=1024M
#
lower_case_table_names=1
#
max_connections=1500
max_user_connections=200
#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=300M; pc.ignore_sb=false; pc.ignore_quorum=false"
#wsrep_cluster_address defines members of the cluster
wsrep_cluster_address=gcomm://x.x.x.1,x.x.x.2,x.x.x.3
wsrep_cluster_name="mariadb-cluster"
wsrep_node_address=x.x.x.1
wsrep_node_incoming_address=x.x.x.1
wsrep_debug=OFF
#
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
query_cache_size=0
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=5G
#
bind-address=x.x.x.1
#
[mariadb]
#performance
wait_timeout=31536000
#
#query logging
log_output=FILE
#slow queries
slow_query_log
slow_query_log_file=/var/log/mariadb/mariadb-slow.log
long_query_time=10.0
log_queries_not_using_indexes=ON
min_examined_row_limit=1000
log_slow_rate_limit=1
log_slow_verbosity=query_plan,explain
#
#error logs
log_error=/var/log/mariadb/mariadb-error.log
log_warnings=2

同样配置所有三个 Galera 节点。

MaxScale 配置

[maxscale]
threads=auto

# Server definitions
[mariadb1]
type=server
address=x.x.x.1
port=3306
protocol=MariaDBBackend
#priority=0

[mariadb2]
type=server
address=x.x.x.2
port=3306
protocol=MariaDBBackend
#priority=1

[mariadb3]
type=server
address=x.x.x.3
port=3306
protocol=MariaDBBackend
#priority=1

# Monitor for the servers
#

[Galera-Monitor]
type=monitor
module=galeramon
servers=mariadb1, mariadb2, mariadb3
user=xxx
password=xxx
#disable_master_role_setting=true
monitor_interval=1000
#use_priority=true
#
disable_master_failback=true
available_when_donor=true

# Service definitions

[Galera-Service]
type=service
router=readwritesplit
master_accept_reads=true
connection_keepalive=300s
master_reconnection=true
master_failure_mode=error_on_write
connection_timeout=3600s
servers=mariadb1, mariadb2, mariadb3
user=xxx
password=xxx
#filters=Query-Log-Filter

#Listener

[Galera-Listener]
type=listener
service=Galera-Service
protocol=MariaDBClient
port=4306

mariadb galera
  • 2 2 个回答
  • 454 Views

2 个回答

  • Voted
  1. dbdemon
    2021-03-22T10:39:46+08:002021-03-22T10:39:46+08:00

    我不认为 MaxScale 是您要用来解决此问题的组件。可以在 MariaDB 服务器本身中执行此操作。我遇到了完全相同的问题,并通过使用该max_user_connections设置对数据库用户施加限制来解决它。

    wait_timeout=31536000

    为什么这个值这么大?您的应用程序是否保持连接打开而不是创建新连接?虽然这听起来像是个好主意,但这意味着连接意外保持打开/空闲状态直到很久以后才会关闭。

    对于作为管理员的我来说,情况变得相同,设置用户特定的限制并不能实现任何目标。

    我不认为这是正确的。

    Q1。如何防止只有一个用户连接失败将后端 mariadb 节点投入维护?

    如果您限制数据库用户,使得max_user_connection所有用户的总和 <max_connections每个节点的总和,那么用户将无法达到max_connections限制。

    Q2。关于 MaxScale 如何以及何时决定将服务器置于维护模式的任何文档或教程、文章参考?

    我认为没有一个单独的文档,而是分散在 MaxScale 文档中。我认为维护模式最初是作为管理员安排计划停机时间的一种方式,但后来也被用于其他事情,请参阅如maintenance_on_low_disk_space

    • 0
  2. Best Answer
    Amit P
    2021-10-28T22:50:00+08:002021-10-28T22:50:00+08:00

    我connection_timeout, max_connections, max_user_connections在数据库服务器节点上尝试过配置,但没有帮助。当错误的应用程序进行连接尝试并且达到阈值时,数据库服务器会断开与"Too many connections". Maxscale 观察了一段时间,并将后端服务器置于Maintenance. 设置max_users_connections某个值说:200,导致后端服务器在单个用户达到限制时拒绝连接。现在,当Too many connections由于“max_users_connectionslimit threshold breach due to bad application, Maxscale again marks the server in维护”状态而出现多次故障时。它不区分尝试来自单个用户或多个用户的集体。它只看到来自服务器的“连接过多”故障。

    为了解决这种情况,我在 Maxscale 下为max_connections设置了限制的不良行为应用程序创建了一个单独的服务。在服务的不同端口号上创建了一个单独的侦听器。

    由于单独的服务,只要max_connections达到 MAxscale 的阈值,其他客户端不受影响。此外,请注意max_connections后端 MariadB 服务器的限制大于 Maxscale 上配置的值,因此 Maxscale 上的阈值更早达到,并且它永远不会将后端服务器放入Maintenance mode. Maxscale 的新配置块如下 -

    [Galera-Service]
    type=service
    router=readwritesplit
    master_accept_reads=true
    connection_keepalive=300s
    master_reconnection=true
    master_failure_mode=error_on_write
    connection_timeout=300s
    max_connections=2500
    servers=mariadb1, mariadb2, mariadb3
    user=user
    password=password
    
    
    [Galera-Service-Bad-App]
    type=service
    router=readwritesplit
    master_accept_reads=true
    connection_keepalive=300s
    master_reconnection=true
    master_failure_mode=error_on_write
    connection_timeout=300s
    max_connections=250
    servers=mariadb1, mariadb2, mariadb3
    user=user
    password=password
    #
    
    [Galera-Listener]
    type=listener
    service=Galera-Service
    protocol=MariaDBClient
    port=4306
    
    [Galera-Listener-astro]
    type=listener
    service=Galera-Service-Badd-App
    protocol=MariaDBClient
    port=4307
    
    
    
    • 0

相关问题

  • MariaDB 标头错误

  • 错误 1046 Mariadb:未选择数据库

  • 你还在使用 MyISAM 还是更喜欢 Aria 存储引擎?

  • 从星期四或一周中的任何其他日子开始,如何通过每周结果改进我的 SQL 语句?

  • 什么时候是使用 MariaDB 而不是 MySQL 的合适时机,为什么?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve