MariaDB
 sql >> Base de Dados >  >> RDS >> MariaDB

Gerenciamento Básico do MaxScale usando MaxCtrl para MariaDB Cluster

Na postagem anterior do blog, abordamos algumas introduções à instalação, atualização e implantação do MaxScale usando o cliente de linha de comando MaxCtrl. Nesta postagem do blog, abordaremos os aspectos de gerenciamento do MaxScale para nosso cluster MariaDB.

Existem vários componentes MaxScale que podemos gerenciar com MaxCtrl, a saber:

  1. Gerenciamento de servidores
  2. Gerenciamento de serviços
  3. Gerenciamento de monitores
  4. Gerenciamento de ouvintes
  5. Gerenciamento de filtros
  6. Gerenciamento MaxScale
  7. Gerenciamento de registros

Nesta postagem do blog, abordaremos os primeiros 4 componentes que são comumente usados ​​no MariaDB Cluster. Todos os comandos nesta postagem do blog são baseados no MaxScale 2.4.11.

Gerenciamento de Servidor

Lista/Mostrar Servidores


Liste um resumo de todos os servidores no MaxScale:
  maxctrl: list servers
┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬─────────────┐
│ Server         │ Address        │ Port │ Connections │ State                   │ GTID        │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera3 │ 192.168.10.203 │ 3306 │ 0           │ Master, Synced, Running │ 100-100-203 │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘

Para o MariaDB Cluster, a lista de servidores resume o estado do nó e do cluster, com seu MariaDB GTID, somente se o cluster estiver configurado para replicar de outro cluster por meio da Replicação MariaDB padrão. O estado é usado pelo MaxScale para controlar o comportamento do algoritmo de roteamento:

  • Master - Para um cluster, isso é considerado o Write-Master.
  • Escravo - Se todos os escravos estiverem inativos, mas o mestre ainda estiver disponível, o roteador usará o mestre.
  • Sincronizado - um nó de cluster que está em um estado sincronizado com o cluster.
  • Em execução - Um servidor que está em execução. Todos os servidores aos quais o MariaDB MaxScale pode se conectar são rotulados como em execução.

Embora o MariaDB Cluster seja capaz de lidar com replicação multimestre, o MaxScale sempre escolherá um nó para manter a função Mestre que receberá todas as gravações para roteamento readwritesplit. Por padrão, o Galera Monitor escolherá o nó com o menor valor wsrep_local_index como o principal. Isso significa que dois MaxScales executados em servidores diferentes escolherão o mesmo servidor como mestre.

Mostrar todos os servidores com mais detalhes:
maxctrl: show servers

Criar servidores


Geralmente, essa é a primeira coisa que você precisa fazer ao configurar o MaxScale como um balanceador de carga. É comum adicionar todos os nós do MariaDB Cluster ao MaxScale e rotulá-lo com um nome de objeto. Neste exemplo, rotulamos os nós Galera como no formato "mariadbgalera#":
maxctrl: create server mariadbgalera1 192.168.0.221 3306
maxctrl: create server mariadbgalera2 192.168.0.222 3306
maxctrl: create server mariadbgalera3 192.168.0.222 3306

O estado do servidor só será informado corretamente após ativarmos o módulo de monitoramento, conforme mostrado na seção Gerenciamento do Monitor mais abaixo.

Excluir um servidor


Para excluir um servidor, é preciso desvincular o servidor de quaisquer serviços ou monitores previamente. Como exemplo, na lista de servidores a seguir, gostaríamos de excluir mariadbgalera3 de MaxScale:
  maxctrl: list servers
┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬─────────────┐
│ Server         │ Address        │ Port │ Connections │ State                   │ GTID        │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera3 │ 192.168.10.203 │ 3306 │ 0           │ Master, Synced, Running │ 100-100-203 │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘

Liste todos os monitores e veja se o servidor faz parte de algum módulo de monitor:


 maxctrl: list monitors
 ┌─────────────────┬─────────┬────────────────────────────────────────────────┐
 │ Monitor         │ State   │ Servers                                        │
 ├─────────────────┼─────────┼────────────────────────────────────────────────┤
 │ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
 └─────────────────┴─────────┴────────────────────────────────────────────────┘

Parece que mariadbgalera3 faz parte do MariaDB-Monitor, então temos que removê-lo primeiro usando o comando "unlink monitor":
 maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
 OK

Em seguida, liste todos os serviços para verificar se o servidor correspondente faz parte de algum serviço MaxScale:
  maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

Como você pode ver, mariadbgalera3 faz parte do Read-Write-Service e Round-Robin-Service. Remova o servidor desses serviços usando o comando "unlink service":
 maxctrl: unlink service Read-Write-Service mariadbgalera3
OK
 maxctrl: unlink service Round-Robin-Service mariadbgalera3
OK

Finalmente, podemos remover o servidor do MaxScale usando o comando "destroy server":

 maxctrl: destroy server mariadbgalera3
OK

Verifique usando a "lista de servidores" que removemos mariadbgalera3 do MaxScale.:

  maxctrl: list servers
┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬──────┐
│ Server         │ Address        │ Port │ Connections │ State                   │ GTID │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼──────┤
│ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Master, Synced, Running │      │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼──────┤
│ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │      │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴──────┘

Modificar o parâmetro do servidor


Para modificar o parâmetro de um servidor, pode-se usar o comando "alter server" que recebe apenas um parâmetro chave/valor de cada vez. Por exemplo:
  maxctrl: alter server mariadbgalera3 priority 10
 OK

Use o comando "show server" e examine a seção Parameters, para obter uma lista de parâmetros que podem ser alterados para o objeto "server":

maxctrl: show server mariadbgalera3
...

│ Parameters       │ {                                         │
│                  │     "address": "192.168.10.203",          │
│                  │     "protocol": "mariadbbackend",         │
│                  │     "port": 3306,                         │
│                  │     "extra_port": 0,                      │
│                  │     "authenticator": null,                │
│                  │     "monitoruser": null,                  │
│                  │     "monitorpw": null,                    │
│                  │     "persistpoolmax": 0,                  │
│                  │     "persistmaxtime": 0,                  │
│                  │     "proxy_protocol": false,              │
│                  │     "ssl": "false",                       │
│                  │     "ssl_cert": null,                     │
│                  │     "ssl_key": null,                      │
│                  │     "ssl_ca_cert": null,                  │
│                  │     "ssl_version": "MAX",                 │
│                  │     "ssl_cert_verify_depth": 9,           │
│                  │     "ssl_verify_peer_certificate": false, │
│                  │     "disk_space_threshold": null,         │
│                  │     "priority": "10"                      │
│                  │ }

Observe que o efeito do comando alter é imediato e o valor do parâmetro no tempo de execução será modificado, bem como o valor em seu arquivo de configuração individual MaxScale dentro de /var/lib/maxscale/maxscale.cnf.d/ para persistência durante a reinicialização.

Definir estado do servidor


MaxScale permite que os servidores backend Galera sejam temporariamente excluídos do conjunto de balanceamento de carga ativando o modo de manutenção. Podemos conseguir isso usando o comando "set server":
 maxctrl: set server mariadbgalera3 maintenance
OK

Ao olhar para o estado do servidor, devemos ver isto:

 maxctrl: show server mariadbgalera3
...
│ State            │ Maintenance, Running
...

Quando um servidor está em modo de manutenção, nenhuma conexão será criada para ele e as conexões existentes serão fechadas. Para limpar o estado de manutenção do host, use o comando "clear server":

 maxctrl: clear server mariadbgalera3 maintenance
OK

Verifique com "show server":

 maxctrl: show server mariadbgalera3
...
│ State            │ Slave, Synced, Running                    │
...

Gerenciamento de monitores

Criar um monitor


O módulo de monitor MaxScale para o MariaDB Cluster é chamado galeramon. Definir um módulo de monitoramento correto é necessário para que o MaxScale possa determinar o melhor roteamento para consultas dependendo do estado dos nós. Por exemplo, se um nó Galera estiver servindo como doador para um nó joiner, ele deve fazer parte dos nós íntegros? Em alguns casos, como quando o tamanho do banco de dados é tão pequeno, marcar um nó doador como íntegro (definindo o parâmetro available_when_donor=true em MaxScale) não é um plano ruim e às vezes melhora o desempenho do roteamento da consulta.

Para criar um serviço (roteador), deve-se criar um usuário de monitoramento no backend dos servidores MariaDB. Comumente, seria usado o mesmo usuário de monitoramento que definimos para o módulo monitor. Para Galera Cluster, caso o usuário de monitoramento não exista, basta criá-lo em um dos nós com os seguintes privilégios:
MariaDB> CREATE USER [email protected]'192.168.0.220' IDENTIFIED BY 'MaXSc4LeP4ss';
MariaDB> GRANT SELECT ON mysql.* TO 'maxscale_monitor'@'192.168.0.220';
MariaDB> GRANT SHOW DATABASES ON *.* TO 'maxscale_monitor'@'192.168.0.220';

Use o comando "create monitor" e especifique um nome com galeramon como o módulo do monitor:

  maxctrl: create monitor MariaDB-Monitor galeramon servers=mariadbgalera1,mariadbgalera2,mariadbgalera3 user=maxscale_monitor password=MaXSc4LeP4ss
OK

Observe que não configuramos o segredo MaxScale, o que significa que armazenamos a senha do usuário em formato de texto simples. Para habilitar a criptografia, consulte o exemplo nesta postagem de blog, Introdução à administração do MaxScale usando maxctrl para MariaDB Cluster na seção Adicionar monitoramento ao MaxScale.

Lista/Mostrar Monitores


Para listar todos os monitores:
 maxctrl: list monitors
┌─────────────────┬─────────┬────────────────────────────────────────────────┐
│ Monitor         │ State   │ Servers                                        │
├─────────────────┼─────────┼────────────────────────────────────────────────┤
│ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
└─────────────────┴─────────┴────────────────────────────────────────────────┘

Para obter uma visão mais detalhada do monitor, use o comando "show monitor":

 maxctrl: show monitor MariaDB-Monitor

┌─────────────────────┬───────────────────────────────────────────┐
│ Monitor             │ MariaDB-Monitor                           │
├─────────────────────┼───────────────────────────────────────────┤
│ State               │ Running                                   │
├─────────────────────┼───────────────────────────────────────────┤
│ Servers             │ mariadbgalera1                            │
│                     │ mariadbgalera2                            │
│                     │ mariadbgalera3                            │
├─────────────────────┼───────────────────────────────────────────┤
│ Parameters          │ {                                         │
│                     │     "user": "maxscale_monitor",           │
│                     │     "password": "*****",                  │
│                     │     "passwd": null,                       │
│                     │     "monitor_interval": 2000,             │
│                     │     "backend_connect_timeout": 3,         │
│                     │     "backend_read_timeout": 1,            │
│                     │     "backend_write_timeout": 2,           │
│                     │     "backend_connect_attempts": 1,        │
│                     │     "journal_max_age": 28800,             │
│                     │     "disk_space_threshold": null,         │
│                     │     "disk_space_check_interval": 0,       │
│                     │     "script": null,                       │
│                     │     "script_timeout": 90,                 │
│                     │     "events": "all",                      │
│                     │     "disable_master_failback": false,     │
│                     │     "available_when_donor": true,         │
│                     │     "disable_master_role_setting": false, │
│                     │     "root_node_as_master": false,         │
│                     │     "use_priority": false,                │
│                     │     "set_donor_nodes": false              │
│                     │ }                                         │
├─────────────────────┼───────────────────────────────────────────┤
│ Monitor Diagnostics │ {                                         │
│                     │     "disable_master_failback": false,     │
│                     │     "disable_master_role_setting": false, │
│                     │     "root_node_as_master": false,         │
│                     │     "use_priority": false,                │
│                     │     "set_donor_nodes": false              │
│                     │ }                                         │
└─────────────────────┴───────────────────────────────────────────┘

Parar/Iniciar Monitor


Parar um monitor pausará o monitoramento dos servidores. Isso geralmente é usado em conjunto com o comando "set server" para controlar manualmente os estados do servidor. Para interromper o serviço de monitoramento, use o comando "stop monitor":
 maxctrl: stop monitor MariaDB-Monitor
OK

Verifique o estado com "show monitor":

 maxctrl: show monitors MariaDB-Monitor
┌─────────────────────┬───────────────────────────────────────────┐
│ Monitor             │ MariaDB-Monitor                           │
├─────────────────────┼───────────────────────────────────────────┤
│ State               │ Stopped                                   │
...

Para iniciá-lo novamente, use o "iniciar monitor":

 maxctrl: start monitor MariaDB-Monitor
OK

Modificar parâmetro do monitor


Para alterar um parâmetro para este monitor, use o comando "alter monitor" e especifique a chave/valor do parâmetro conforme abaixo:
 maxctrl: alter monitor MariaDB-Monitor available_when_donor true
OK

Use o comando "show monitor" e consulte a seção Parâmetros, para obter uma lista de parâmetros que podem ser alterados para o módulo galeramon:

maxctrl: show server mariadbgalera3
...
│ Parameters          │ {                                         │
│                     │     "user": "maxscale_monitor",           │
│                     │     "password": "*****",                  │
│                     │     "monitor_interval": 2000,             │
│                     │     "backend_connect_timeout": 3,         │
│                     │     "backend_read_timeout": 1,            │
│                     │     "backend_write_timeout": 2,           │
│                     │     "backend_connect_attempts": 1,        │
│                     │     "journal_max_age": 28800,             │
│                     │     "disk_space_threshold": null,         │
│                     │     "disk_space_check_interval": 0,       │
│                     │     "script": null,                       │
│                     │     "script_timeout": 90,                 │
│                     │     "events": "all",                      │
│                     │     "disable_master_failback": false,     │
│                     │     "available_when_donor": true,         │
│                     │     "disable_master_role_setting": false, │
│                     │     "root_node_as_master": false,         │
│                     │     "use_priority": false,                │
│                     │     "set_donor_nodes": false              │
│                     │ }                                         │

Excluir um monitor


Para excluir um monitor, é necessário remover primeiro todos os servidores vinculados ao monitor. Por exemplo, considere o seguinte monitor em MaxScale:
 maxctrl: list monitors
┌─────────────────┬─────────┬────────────────────────────────────────────────┐
│ Monitor         │ State   │ Servers                                        │
├─────────────────┼─────────┼────────────────────────────────────────────────┤
│ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
└─────────────────┴─────────┴────────────────────────────────────────────────┘

Remova todos os servidores desse serviço específico:

 maxctrl: unlink monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3

OK

Nosso monitor agora está assim:
 maxctrl: list monitors
┌─────────────────┬─────────┬─────────┐
│ Monitor         │ State   │ Servers │
├─────────────────┼─────────┼─────────┤
│ MariaDB-Monitor │ Running │         │
└─────────────────┴─────────┴─────────┘

Só então podemos excluir o monitor:

 maxctrl: destroy monitor MariaDB-Monitor
OK

Adicionar/Remover Servidores no Monitor


Após criar um monitor, podemos usar o comando "link monitor" para adicionar os servidores Galera ao monitor. Use o nome do servidor conforme criado na seção Criar Servidores:
 maxctrl: link monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3
OK

Da mesma forma, para remover um servidor do serviço, basta usar o comando "unlink monitor":

 maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
OK

Verifique com o comando "list monitors" ou "show monitors".

Gerenciamento de Serviços

Criar um serviço


Para criar um serviço (roteador), deve-se criar um usuário de monitoramento no backend dos servidores MariaDB. Comumente, seria usado o mesmo usuário de monitoramento que definimos para o módulo monitor. Para Galera Cluster, caso o usuário de monitoramento não exista, basta criá-lo em um dos nós com os seguintes privilégios:
MariaDB> CREATE USER [email protected]'192.168.0.220' IDENTIFIED BY 'MaXSc4LeP4ss';
MariaDB> GRANT SELECT ON mysql.* TO 'maxscale_monitor'@'192.168.0.220';
MariaDB> GRANT SHOW DATABASES ON *.* TO 'maxscale_monitor'@'192.168.0.220';

Onde 192.168.0.220 é o endereço IP do host MaxScale.

Em seguida, especifique o nome do serviço, o tipo de roteamento junto com um usuário de monitoramento para que MaxScale se conecte aos servidores backend:
 maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=******
OK

Além disso, você pode especificar parâmetros adicionais ao criar o serviço. Neste exemplo, gostaríamos que o nó "master" fosse incluído no conjunto de balanceamento round-robin para nosso MariaDB Galera Cluster:
 maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=****** router_options=master,slave
OK

Use o comando "show service" para ver os parâmetros suportados. Para roteador round-robin, a lista da seguinte forma:

  maxctrl: show service Round-Robin-Service
...
│ Parameters          │ {                                          │
│                     │     "router_options": null,                │
│                     │     "user": "maxscale_monitor",            │
│                     │     "password": "*****",                   │
│                     │     "passwd": null,                        │
│                     │     "enable_root_user": false,             │
│                     │     "max_retry_interval": 3600,            │
│                     │     "max_connections": 0,                  │
│                     │     "connection_timeout": 0,               │
│                     │     "auth_all_servers": false,             │
│                     │     "strip_db_esc": true,                  │
│                     │     "localhost_match_wildcard_host": true, │
│                     │     "version_string": null,                │
│                     │     "weightby": null,                      │
│                     │     "log_auth_warnings": true,             │
│                     │     "retry_on_failure": true,              │
│                     │     "session_track_trx_state": false,      │
│                     │     "retain_last_statements": -1,          │
│                     │     "session_trace": 0

Para o roteador dividido de leitura e gravação, os parâmetros suportados são:

  maxctrl: show service Read-Write-Service
...
│ Parameters          │ {                                                           │
│                     │     "router_options": null,                                 │
│                     │     "user": "maxscale_monitor",                             │
│                     │     "password": "*****",                                    │
│                     │     "passwd": null,                                         │
│                     │     "enable_root_user": false,                              │
│                     │     "max_retry_interval": 3600,                             │
│                     │     "max_connections": 0,                                   │
│                     │     "connection_timeout": 0,                                │
│                     │     "auth_all_servers": false,                              │
│                     │     "strip_db_esc": true,                                   │
│                     │     "localhost_match_wildcard_host": true,                  │
│                     │     "version_string": null,                                 │
│                     │     "weightby": null,                                       │
│                     │     "log_auth_warnings": true,                              │
│                     │     "retry_on_failure": true,                               │
│                     │     "session_track_trx_state": false,                       │
│                     │     "retain_last_statements": -1,                           │
│                     │     "session_trace": 0,                                     │
│                     │     "use_sql_variables_in": "all",                          │
│                     │     "slave_selection_criteria": "LEAST_CURRENT_OPERATIONS", │
│                     │     "master_failure_mode": "fail_instantly",                │
│                     │     "max_slave_replication_lag": -1,                        │
│                     │     "max_slave_connections": "255",                         │
│                     │     "retry_failed_reads": true,                             │
│                     │     "prune_sescmd_history": false,                          │
│                     │     "disable_sescmd_history": false,                        │
│                     │     "max_sescmd_history": 50,                               │
│                     │     "strict_multi_stmt": false,                             │
│                     │     "strict_sp_calls": false,                               │
│                     │     "master_accept_reads": false,                           │
│                     │     "connection_keepalive": 300,                            │
│                     │     "causal_reads": false,                                  │
│                     │     "causal_reads_timeout": "10",                           │
│                     │     "master_reconnection": false,                           │
│                     │     "delayed_retry": false,                                 │
│                     │     "delayed_retry_timeout": 10,                            │
│                     │     "transaction_replay": false,                            │
│                     │     "transaction_replay_max_size": "1Mi",                   │
│                     │     "optimistic_trx": false                                 │
│                     │ }

List/Show Services
 

To list out all created services (routers), use the "list services" command:

 maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Binlog-Repl-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

In the above examples, we have created 3 services, with 3 different routers. However, the Binlog-Repl-Service for our binlog server is not linked with any servers yet.

To show all services in details:

 maxctrl: show services

Or if you want to show a particular service:
 maxctrl: show service Round-Robin-Service

Stop/Start Services


Stopping a service will prevent all the listeners for that service from accepting new connections. Existing connections will still be handled normally until they are closed. To stop and start all services, use the "stop services":
 maxctrl: stop services
 maxctrl: show services
 maxctrl: start services
 maxctrl: show services

Or we can use the "stop service" to stop only one particular service:

 maxctrl: stop services Round-Robin-Service

Delete a Service


In order to delete a service, one has to remove all servers and destroy the listeners associated with the service first. For example, consider the following services in MaxScale:
 maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

Let's remove Round-Robin-Service from the setup. Remove all servers from this particular service:

 maxctrl: unlink service Round-Robin-Service mariadbgalera1 mariadbgalera2 mariadbgalera3
OK

Our services are now looking like this:
 maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │                                                │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

If the service is tied with a listener, we have to remove it as well. Use "list listeners" and specify the service name to look for it:

 maxctrl: list listeners Round-Robin-Service
┌──────────────────────┬──────┬─────────┬─────────┐
│ Name                 │ Port │ Host    │ State   │
├──────────────────────┼──────┼─────────┼─────────┤
│ Round-Robin-Listener │ 3307 │ 0.0.0.0 │ Running │
└──────────────────────┴──────┴─────────┴─────────┘

And then remove the listener:
 maxctrl: destroy listener Round-Robin-Service Round-Robin-Listener
OK

Finally, we can remove the service:
 maxctrl: destroy service Round-Robin-Service
OK

Modify Service's Parameter


Similar to the other object, one can modify a service parameter by using the "alter service" command:
 maxctrl: alter service Read-Write-Service master_accept_reads true
OK

Some routers support runtime configuration changes to all parameters. Currently all readconnroute, readwritesplit and schemarouter parameters can be changed at runtime. In addition to module specific parameters, the following list of common service parameters can be altered at runtime:
  • user
  • passwd
  • enable_root_user
  • max_connections
  • connection_timeout
  • auth_all_servers
  • optimize_wildcard
  • strip_db_esc
  • localhost_match_wildcard_host
  • max_slave_connections
  • max_slave_replication_lag
  • retain_last_statements

Note that alter command effect is immediate and the parameter's value in the runtime will be modified as well as the value in its individual MaxScale configuration file inside /var/lib/maxscale/maxscale.cnf.d/ for persistence across restart.

Add/Remove Servers into Service


After creating a service, we can use the link command to add our servers into the service. Use the server's name as created under Create Servers section:
 maxctrl: link service Round-Robin-Service mariadbgalera1 mariadbgalera2 mariadbgalera3
OK

Similarly, to remove a server from the service, just use "unlink service" command:
 maxctrl: unlink service Round-Robin-Service mariadbgalera3
OK

We can only remove one server from a service at a time, so repeat it for other nodes to delete them. Verify with "list services" or "show services" command.

Listener Management

List Listeners


To list all listeners, we need to know the service name in advanced:
maxctrl: list services
┌──────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service              │ Router         │ Connections │ Total Connections │ Servers                                        │
├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service   │ readwritesplit │ 0           │ 0                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service  │ readconnroute  │ 0           │ 0                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤

In the above example, we have two services, Read-Write-Service and Round-Robin-Service. Then, we can list out the listener for that particular service. For Read-Write-Service:

 maxctrl: list listeners Read-Write-Service
┌─────────────────────┬──────┬─────────┬─────────┐
│ Name                │ Port │ Host    │ State   │
├─────────────────────┼──────┼─────────┼─────────┤
│ Read-Write-Listener │ 3306 │ 0.0.0.0 │ Running │
└─────────────────────┴──────┴─────────┴─────────┘

And for Round-Robin-Service:

 maxctrl: list listeners Round-Robin-Service
┌──────────────────────┬──────┬─────────┬─────────┐
│ Name                 │ Port │ Host    │ State   │
├──────────────────────┼──────┼─────────┼─────────┤
│ Round-Robin-Listener │ 3307 │ 0.0.0.0 │ Running │
└──────────────────────┴──────┴─────────┴─────────┘

Unlike other objects in MaxScale, the listener does not have a "show" and "alter" commands since it is a fairly simple object.

Create a Listener


Make sure a service has been created. In this example, taken from the Create Service section above, we will create a listener so MaxScale will listen on port 3307 to process the MariaDB connections in a round-robin fashion:
 maxctrl: create listener Round-Robin-Service Round-Robin-Listener 3307
OK

Delete a Listener


To delete a listener, use the "destroy listener" command with the respective service name and listener name:
 maxctrl: destroy listener Round-Robin-Service Round-Robin-Listener
OK

This concludes this episode of basic MaxScale management tasks for MariaDB Cluster. In the next series, we are going to cover the MaxScale advanced management tasks like service filters, MaxScale user management and so on.