V předchozím příspěvku na blogu jsme probrali některé úvody k instalaci, upgradu a nasazení MaxScale pomocí klienta příkazového řádku MaxCtrl. V tomto příspěvku na blogu se budeme zabývat aspekty správy MaxScale pro náš cluster MariaDB.
Existuje řada komponent MaxScale, které můžeme spravovat pomocí MaxCtrl, jmenovitě:
- Správa serveru
- Správa služeb
- Sledování správy
- Správa posluchačů
- Správa filtrů
- Správa MaxScale
- Správa protokolování
V tomto blogovém příspěvku se budeme zabývat prvními 4 komponentami, které se běžně používají v MariaDB Cluster. Všechny příkazy v tomto příspěvku na blogu jsou založeny na MaxScale 2.4.11.
Správa serveru
Seznam/zobrazení serverů
Seznam všech serverů v 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 │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘ U MariaDB Cluster seznam serverů shrnuje stav uzlu a clusteru s jeho MariaDB GTID, pouze pokud je cluster nastaven na replikaci z jiného clusteru prostřednictvím standardní replikace MariaDB. Stav používá MaxScale k řízení chování směrovacího algoritmu:
- Master – U klastru je to považováno za Master Write-Master.
- Slave – Pokud jsou všechny podřízené jednotky mimo provoz, ale master je stále dostupný, router použije master.
- Synchronizováno – uzel clusteru, který je ve stavu synchronizace s clusterem.
- Běží – Server, který je v provozu. Všechny servery, ke kterým se MariaDB MaxScale může připojit, jsou označeny jako spuštěné.
Přestože je MariaDB Cluster schopen zpracovat replikaci s více hlavními servery, MaxScale vždy vybere jeden uzel, který bude mít roli Master, který bude přijímat všechny zápisy pro směrování typu readwritesplit. Ve výchozím nastavení vybere Galera Monitor jako hlavní uzel s nejnižší hodnotou wsrep_local_index. To znamená, že dva MaxScales běžící na různých serverech vyberou stejný server jako hlavní server.
Zobrazit všechny servery podrobněji:
maxctrl: show servers Vytvořit servery
Toto je obvykle první věc, kterou musíte udělat, když nastavujete MaxScale jako nástroj pro vyrovnávání zatížení. Je běžné přidat všechny uzly MariaDB Cluster do MaxScale a označit je názvem objektu. V tomto příkladu označujeme uzly Galera jako ve formátu "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 Stav serveru bude správně hlášen až poté, co aktivujeme modul monitorování, jak je uvedeno níže v části Správa monitorování.
Odstranit server
Chcete-li odstranit server, musíte nejprve odpojit server od všech služeb nebo monitorů. Jako příklad v následujícím seznamu serverů bychom chtěli odstranit mariadbgalera3 z 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 │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘ Vypište seznam všech monitorů a zjistěte, zda je server součástí nějakého monitorového modulu:
maxctrl: list monitors
┌─────────────────┬─────────┬────────────────────────────────────────────────┐
│ Monitor │ State │ Servers │
├─────────────────┼─────────┼────────────────────────────────────────────────┤
│ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
└─────────────────┴─────────┴────────────────────────────────────────────────┘ Vypadá to, že mariadbgalera3 je součástí MariaDB-Monitor, takže ji musíme nejprve odstranit pomocí příkazu „unlink monitor“:
maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
OK Dále vypište seznam všech služeb, abyste zkontrolovali, zda je příslušný server součástí nějaké služby 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 │ │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘ Jak můžete vidět, mariadbgalera3 je součástí služby Read-Write-Service a Round-Robin-Service. Odeberte server z těchto služeb pomocí příkazu "unlink service":
maxctrl: unlink service Read-Write-Service mariadbgalera3
OK
maxctrl: unlink service Round-Robin-Service mariadbgalera3
OK Nakonec můžeme server odebrat z MaxScale pomocí příkazu "destroy server":
maxctrl: destroy server mariadbgalera3
OK Ověřte pomocí "seznamu serverů", že jsme z MaxScale odstranili mariadbgalera3.:
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 │ │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴──────┘ Upravit parametr serveru
Chcete-li upravit parametr serveru, můžete použít příkaz "alter server", který přebírá pouze jeden parametr klíč/hodnota najednou. Například:
maxctrl: alter server mariadbgalera3 priority 10
OK Použijte příkaz "show server" a podívejte se do sekce Parametry, kde najdete seznam parametrů, které lze změnit pro objekt "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" │
│ │ } Všimněte si, že efekt změny příkazu je okamžitý a hodnota parametru za běhu bude upravena, stejně jako hodnota v jeho jednotlivém konfiguračním souboru MaxScale uvnitř /var/lib/maxscale/maxscale.cnf.d/ pro přetrvávání po restartu.
Nastavit stav serveru
MaxScale umožňuje, aby byly backendové servery Galera dočasně vyloučeny z nastavení vyrovnávání zátěže aktivací režimu údržby. Toho můžeme dosáhnout pomocí příkazu "set server":
maxctrl: set server mariadbgalera3 maintenance
OK Při pohledu na stav serveru bychom měli vidět toto:
maxctrl: show server mariadbgalera3
...
│ State │ Maintenance, Running
... Když je server v režimu údržby, nebudou k němu vytvořena žádná připojení a existující připojení budou uzavřena. Chcete-li vymazat stav údržby z hostitele, použijte příkaz "clear server":
maxctrl: clear server mariadbgalera3 maintenance
OK Ověřte pomocí "zobrazit server":
maxctrl: show server mariadbgalera3
...
│ State │ Slave, Synced, Running │
... Správa monitorování
Vytvořit monitor
Monitorovací modul MaxScale pro MariaDB Cluster se nazývá galeramon. Definování správného monitorovacího modulu je nezbytné, aby MaxScale mohl určit nejlepší směrování pro dotazy v závislosti na stavu uzlů. Pokud například uzel Galera slouží jako dárce pro spojovací uzel, měl by být součástí zdravých uzlů? V některých případech, například když je velikost databáze tak malá, není označení dárcovského uzlu jako zdravého (nastavením parametru available_when_donor=true v MaxScale) špatný plán a někdy zlepšuje výkon směrování dotazů.
Chcete-li vytvořit službu (router), musíte vytvořit monitorovacího uživatele na backendu serverů MariaDB. Obvykle by se používal stejný monitorovací uživatel, kterého jsme definovali pro modul monitoru. Pro Galera Cluster, pokud monitorovací uživatel neexistuje, stačí jej vytvořit na jednom z uzlů s následujícími oprávněními:
MariaDB> CREATE USER example@sqldat.com'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'; Použijte příkaz "create monitor" a zadejte název s galeramonem jako modulem monitoru:
maxctrl: create monitor MariaDB-Monitor galeramon servers=mariadbgalera1,mariadbgalera2,mariadbgalera3 user=maxscale_monitor password=MaXSc4LeP4ss
OK Všimněte si, že jsme nenakonfigurovali tajemství MaxScale, což znamená, že ukládáme uživatelské heslo ve formátu prostého textu. Chcete-li povolit šifrování, podívejte se na příklad v tomto příspěvku na blogu Úvod do správy MaxScale pomocí maxctrl pro MariaDB Cluster v části Přidání monitorování do sekce MaxScale.
Seznam/Zobrazit monitory
Seznam všech monitorů:
maxctrl: list monitors
┌─────────────────┬─────────┬────────────────────────────────────────────────┐
│ Monitor │ State │ Servers │
├─────────────────┼─────────┼────────────────────────────────────────────────┤
│ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
└─────────────────┴─────────┴────────────────────────────────────────────────┘ Chcete-li získat podrobnější pohled na monitor, použijte příkaz "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 │
│ │ } │
└─────────────────────┴───────────────────────────────────────────┘ Zastavit/Spustit monitor
Zastavení monitoru pozastaví monitorování serverů. To se běžně používá ve spojení s příkazem "set server" pro ruční ovládání stavů serveru. Chcete-li zastavit službu monitorování, použijte příkaz "stop monitor":
maxctrl: stop monitor MariaDB-Monitor
OK Ověřte stav pomocí "show monitor":
maxctrl: show monitors MariaDB-Monitor
┌─────────────────────┬───────────────────────────────────────────┐
│ Monitor │ MariaDB-Monitor │
├─────────────────────┼───────────────────────────────────────────┤
│ State │ Stopped │
... Chcete-li jej znovu spustit, použijte "start monitor":
maxctrl: start monitor MariaDB-Monitor
OK Upravit parametr monitoru
Chcete-li změnit parametr pro tento monitor, použijte příkaz "alter monitor" a zadejte klíč/hodnotu parametru, jak je uvedeno níže:
maxctrl: alter monitor MariaDB-Monitor available_when_donor true
OK Použijte příkaz "show monitor" a podívejte se do sekce Parametry, kde najdete seznam parametrů, které lze pro modul galeramon změnit:
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 │
│ │ } │
Smazat monitor
Chcete-li odstranit monitor, musíte nejprve odstranit všechny servery spojené s monitorem. Zvažte například následující monitor v MaxScale:
maxctrl: list monitors
┌─────────────────┬─────────┬────────────────────────────────────────────────┐
│ Monitor │ State │ Servers │
├─────────────────┼─────────┼────────────────────────────────────────────────┤
│ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
└─────────────────┴─────────┴────────────────────────────────────────────────┘ Odeberte všechny servery z této konkrétní služby:
maxctrl: unlink monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3
OK Náš monitor nyní vypadá takto:
maxctrl: list monitors
┌─────────────────┬─────────┬─────────┐
│ Monitor │ State │ Servers │
├─────────────────┼─────────┼─────────┤
│ MariaDB-Monitor │ Running │ │
└─────────────────┴─────────┴─────────┘ Pouze poté můžeme monitor smazat:
maxctrl: destroy monitor MariaDB-Monitor
OK Přidat/odebrat servery do Monitoru
Po vytvoření monitoru můžeme použít příkaz "link monitor" k přidání serverů Galera do monitoru. Použijte název serveru vytvořený v části Create Servers:
maxctrl: link monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3
OK Podobně pro odebrání serveru ze služby stačí použít příkaz "unlink monitor":
maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
OK Ověřte pomocí příkazu „list monitors“ nebo „show monitors“.
Správa služeb
Vytvořte službu
Chcete-li vytvořit službu (router), musíte vytvořit monitorovacího uživatele na backendu serverů MariaDB. Obvykle by se používal stejný monitorovací uživatel, kterého jsme definovali pro modul monitoru. Pro Galera Cluster, pokud monitorovací uživatel neexistuje, stačí jej vytvořit na jednom z uzlů s následujícími oprávněními:
MariaDB> CREATE USER example@sqldat.com'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'; Kde 192.168.0.220 je IP adresa hostitele MaxScale.
Poté zadejte název služby, typ směrování spolu s monitorovacím uživatelem, aby se MaxScale připojil k backendovým serverům:
maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=******
OK Při vytváření služby můžete také zadat další parametry. V tomto příkladu bychom chtěli, aby byl „hlavní“ uzel zahrnut do sady kruhového vyvažování pro náš cluster MariaDB Galera:
maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=****** router_options=master,slave
OK Pro zobrazení podporovaných parametrů použijte příkaz "show service". V případě routeru typu round-robin je seznam následující:
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 U routeru rozděleného na čtení a zápis jsou podporované parametry:
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.